View | Details | Raw Unified | Return to bug 256910 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/pde/internal/ui/editor/target/OverviewPage.java (-117 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.editor.target;
12
13
import org.eclipse.jface.action.IStatusLineManager;
14
import org.eclipse.pde.internal.ui.*;
15
import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
16
import org.eclipse.pde.internal.ui.editor.PDEFormPage;
17
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.SWTException;
19
import org.eclipse.swt.layout.GridData;
20
import org.eclipse.swt.widgets.Composite;
21
import org.eclipse.ui.PlatformUI;
22
import org.eclipse.ui.forms.IManagedForm;
23
import org.eclipse.ui.forms.editor.FormEditor;
24
import org.eclipse.ui.forms.events.HyperlinkEvent;
25
import org.eclipse.ui.forms.events.IHyperlinkListener;
26
import org.eclipse.ui.forms.widgets.*;
27
28
public class OverviewPage extends PDEFormPage implements IHyperlinkListener {
29
30
	public static final String PAGE_ID = "overview"; //$NON-NLS-1$
31
32
	public OverviewPage(FormEditor editor) {
33
		super(editor, PAGE_ID, PDEUIMessages.OverviewPage_title);
34
	}
35
36
	/* (non-Javadoc)
37
	 * @see org.eclipse.pde.internal.ui.editor.PDEFormPage#createFormContent(org.eclipse.ui.forms.IManagedForm)
38
	 */
39
	protected void createFormContent(IManagedForm managedForm) {
40
		super.createFormContent(managedForm);
41
		ScrolledForm form = managedForm.getForm();
42
		FormToolkit toolkit = managedForm.getToolkit();
43
		form.setText(PDEUIMessages.OverviewPage_title);
44
		form.setImage(PDEPlugin.getDefault().getLabelProvider().get(PDEPluginImages.DESC_TARGET_DEFINITION));
45
		fillBody(managedForm, toolkit);
46
		PlatformUI.getWorkbench().getHelpSystem().setHelp(form.getBody(), IHelpContextIds.TARGET_OVERVIEW_PAGE);
47
	}
48
49
	private void fillBody(IManagedForm managedForm, FormToolkit toolkit) {
50
		Composite body = managedForm.getForm().getBody();
51
		body.setLayout(FormLayoutFactory.createFormGridLayout(true, 2));
52
53
		managedForm.addPart(new TargetDefinitionSection(this, body));
54
		managedForm.addPart(new LocationsSection(this, body));
55
		createContentsSection(body, toolkit);
56
		createEnvironmentSection(body, toolkit);
57
	}
58
59
	private void createContentsSection(Composite parent, FormToolkit toolkit) {
60
		Section section = createSection(parent, toolkit, PDEUIMessages.OverviewPage_contentTitle);
61
		createText(section, PDEUIMessages.OverviewPage_contentDescription, toolkit);
62
	}
63
64
	private void createEnvironmentSection(Composite parent, FormToolkit toolkit) {
65
		Section section = createSection(parent, toolkit, PDEUIMessages.OverviewPage_environmentTitle);
66
		createText(section, PDEUIMessages.OverviewPage_environmentDescription, toolkit);
67
	}
68
69
	private Section createSection(Composite parent, FormToolkit toolkit, String title) {
70
		Section section = toolkit.createSection(parent, ExpandableComposite.TITLE_BAR);
71
		section.clientVerticalSpacing = FormLayoutFactory.SECTION_HEADER_VERTICAL_SPACING;
72
		section.setText(title);
73
		section.setLayout(FormLayoutFactory.createClearTableWrapLayout(false, 1));
74
		section.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));
75
		return section;
76
	}
77
78
	private FormText createText(Section section, String content, FormToolkit toolkit) {
79
		Composite container = toolkit.createComposite(section, SWT.NONE);
80
		container.setLayout(FormLayoutFactory.createSectionClientTableWrapLayout(false, 1));
81
		section.setClient(container);
82
		FormText text = toolkit.createFormText(container, true);
83
		try {
84
			text.setText(content, true, false);
85
		} catch (SWTException e) {
86
			text.setText(e.getMessage(), false, false);
87
		}
88
		TableWrapData data = new TableWrapData(TableWrapData.FILL_GRAB);
89
		data.maxWidth = 250;
90
		text.setLayoutData(data);
91
		text.addHyperlinkListener(this);
92
		return text;
93
	}
94
95
	public void linkActivated(HyperlinkEvent e) {
96
		String href = (String) e.getHref();
97
		if (href.equals("content")) //$NON-NLS-1$
98
			getEditor().setActivePage(ContentPage.PAGE_ID);
99
		else if (href.equals("environment")) //$NON-NLS-1$
100
			getEditor().setActivePage(EnvironmentPage.PAGE_ID);
101
	}
102
103
	public void linkEntered(HyperlinkEvent e) {
104
		IStatusLineManager mng = getEditor().getEditorSite().getActionBars().getStatusLineManager();
105
		mng.setMessage(e.getLabel());
106
	}
107
108
	public void linkExited(HyperlinkEvent e) {
109
		IStatusLineManager mng = getEditor().getEditorSite().getActionBars().getStatusLineManager();
110
		mng.setMessage(null);
111
	}
112
113
	protected String getHelpResource() {
114
		return "/org.eclipse.pde.doc.user/guide/tools/editors/target_definition_editor/overview.htm"; //$NON-NLS-1$
115
	}
116
117
}
(-)src/org/eclipse/pde/internal/ui/editor/target/TargetDefinitionSection.java (-268 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.editor.target;
12
13
import org.eclipse.debug.ui.StringVariableSelectionDialog;
14
import org.eclipse.jface.window.Window;
15
import org.eclipse.pde.core.IModelChangedEvent;
16
import org.eclipse.pde.internal.core.itarget.*;
17
import org.eclipse.pde.internal.ui.PDEPlugin;
18
import org.eclipse.pde.internal.ui.PDEUIMessages;
19
import org.eclipse.pde.internal.ui.editor.*;
20
import org.eclipse.pde.internal.ui.parts.FormEntry;
21
import org.eclipse.swt.SWT;
22
import org.eclipse.swt.dnd.Clipboard;
23
import org.eclipse.swt.events.SelectionAdapter;
24
import org.eclipse.swt.events.SelectionEvent;
25
import org.eclipse.swt.layout.GridData;
26
import org.eclipse.swt.widgets.*;
27
import org.eclipse.ui.IActionBars;
28
import org.eclipse.ui.forms.IFormColors;
29
import org.eclipse.ui.forms.widgets.*;
30
31
public class TargetDefinitionSection extends PDESection {
32
33
	private FormEntry fNameEntry;
34
	private FormEntry fPath;
35
	private Button fUseDefault;
36
	private Button fCustomPath;
37
	private Button fFileSystem;
38
	private Button fVariable;
39
	private static int NUM_COLUMNS = 5;
40
41
	public TargetDefinitionSection(PDEFormPage page, Composite parent) {
42
		super(page, parent, ExpandableComposite.TITLE_BAR);
43
		createClient(getSection(), page.getEditor().getToolkit());
44
	}
45
46
	/* (non-Javadoc)
47
	 * @see org.eclipse.pde.internal.ui.editor.PDESection#createClient(org.eclipse.ui.forms.widgets.Section, org.eclipse.ui.forms.widgets.FormToolkit)
48
	 */
49
	protected void createClient(Section section, FormToolkit toolkit) {
50
		section.setLayout(FormLayoutFactory.createClearTableWrapLayout(false, 1));
51
		Composite client = toolkit.createComposite(section);
52
		client.setLayout(FormLayoutFactory.createSectionClientGridLayout(false, NUM_COLUMNS));
53
54
		IActionBars actionBars = getPage().getPDEEditor().getEditorSite().getActionBars();
55
56
		createNameEntry(client, toolkit, actionBars);
57
58
		createLocation(client, toolkit, actionBars);
59
60
		toolkit.paintBordersFor(client);
61
		section.setClient(client);
62
		section.setText(PDEUIMessages.TargetDefinitionSection_title);
63
		GridData data = new GridData();
64
		data.horizontalSpan = 2;
65
		data.grabExcessHorizontalSpace = true;
66
		data.horizontalAlignment = SWT.FILL;
67
		section.setLayoutData(data);
68
		// Register to be notified when the model changes
69
		getModel().addModelChangedListener(this);
70
	}
71
72
	/* (non-Javadoc)
73
	 * @see org.eclipse.ui.forms.AbstractFormPart#dispose()
74
	 */
75
	public void dispose() {
76
		ITargetModel model = getModel();
77
		if (model != null) {
78
			model.removeModelChangedListener(this);
79
		}
80
		super.dispose();
81
	}
82
83
	/* (non-Javadoc)
84
	 * @see org.eclipse.pde.internal.ui.editor.PDESection#modelChanged(org.eclipse.pde.core.IModelChangedEvent)
85
	 */
86
	public void modelChanged(IModelChangedEvent e) {
87
		// No need to call super, handling world changed event here
88
		if (e.getChangeType() == IModelChangedEvent.WORLD_CHANGED) {
89
			handleModelEventWorldChanged(e);
90
		}
91
	}
92
93
	/**
94
	 * @param event
95
	 */
96
	private void handleModelEventWorldChanged(IModelChangedEvent event) {
97
		// Perform the refresh
98
		refresh();
99
		// Note:  A deferred selection event is fired from radio buttons when
100
		// their value is toggled, the user switches to another page, and the
101
		// user switches back to the same page containing the radio buttons
102
		// This appears to be a result of a SWT bug.
103
		// If the radio button is the last widget to have focus when leaving 
104
		// the page, an event will be fired when entering the page again.
105
		// An event is not fired if the radio button does not have focus.
106
		// The solution is to redirect focus to a stable widget.
107
		getPage().setLastFocusControl(fNameEntry.getText());
108
	}
109
110
	private void createNameEntry(Composite client, FormToolkit toolkit, IActionBars actionBars) {
111
		fNameEntry = new FormEntry(client, toolkit, PDEUIMessages.TargetDefinitionSection_name, null, false);
112
		fNameEntry.setFormEntryListener(new FormEntryAdapter(this, actionBars) {
113
			public void textValueChanged(FormEntry entry) {
114
				getTarget().setName(entry.getValue());
115
			}
116
		});
117
		GridData gd = (GridData) fNameEntry.getText().getLayoutData();
118
		gd.horizontalSpan = 4;
119
		fNameEntry.setEditable(isEditable());
120
	}
121
122
	private void createLocation(Composite client, FormToolkit toolkit, IActionBars actionBars) {
123
		Label label = toolkit.createLabel(client, PDEUIMessages.TargetDefinitionSection_targetLocation);
124
		label.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
125
126
		fUseDefault = toolkit.createButton(client, PDEUIMessages.TargetDefinitionSection_sameAsHost, SWT.RADIO);
127
		GridData gd = new GridData();
128
		gd.horizontalSpan = 5;
129
		gd.horizontalIndent = 15;
130
		fUseDefault.setLayoutData(gd);
131
		fUseDefault.addSelectionListener(new SelectionAdapter() {
132
			public void widgetSelected(SelectionEvent e) {
133
				if (fUseDefault.getSelection()) {
134
					fPath.getText().setEditable(false);
135
					fPath.setValue("", true); //$NON-NLS-1$
136
					fFileSystem.setEnabled(false);
137
					fVariable.setEnabled(false);
138
					getLocationInfo().setDefault(true);
139
				}
140
			}
141
		});
142
143
		fCustomPath = toolkit.createButton(client, PDEUIMessages.TargetDefinitionSection_location, SWT.RADIO);
144
		gd = new GridData();
145
		gd.horizontalIndent = 15;
146
		fCustomPath.setLayoutData(gd);
147
		fCustomPath.addSelectionListener(new SelectionAdapter() {
148
			public void widgetSelected(SelectionEvent e) {
149
				if (fCustomPath.getSelection()) {
150
					ILocationInfo info = getLocationInfo();
151
					fPath.getText().setEditable(true);
152
					fPath.setValue(info.getPath(), true);
153
					fFileSystem.setEnabled(true);
154
					fVariable.setEnabled(true);
155
					info.setDefault(false);
156
				}
157
			}
158
		});
159
160
		fPath = new FormEntry(client, toolkit, null, null, false);
161
		fPath.getText().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
162
		fPath.setFormEntryListener(new FormEntryAdapter(this, actionBars) {
163
			public void textValueChanged(FormEntry entry) {
164
				getLocationInfo().setPath(fPath.getValue());
165
			}
166
		});
167
168
		fFileSystem = toolkit.createButton(client, PDEUIMessages.TargetDefinitionSection_fileSystem, SWT.PUSH);
169
		fFileSystem.addSelectionListener(new SelectionAdapter() {
170
			public void widgetSelected(SelectionEvent e) {
171
				handleBrowseFileSystem();
172
			}
173
		});
174
175
		fVariable = toolkit.createButton(client, PDEUIMessages.TargetDefinitionSection_variables, SWT.PUSH);
176
		fVariable.addSelectionListener(new SelectionAdapter() {
177
			public void widgetSelected(SelectionEvent e) {
178
				handleInsertVariable();
179
			}
180
		});
181
	}
182
183
	/* (non-Javadoc)
184
	 * @see org.eclipse.ui.forms.AbstractFormPart#commit(boolean)
185
	 */
186
	public void commit(boolean onSave) {
187
		fNameEntry.commit();
188
		fPath.commit();
189
		super.commit(onSave);
190
	}
191
192
	/* (non-Javadoc)
193
	 * @see org.eclipse.pde.internal.ui.editor.PDESection#cancelEdit()
194
	 */
195
	public void cancelEdit() {
196
		fNameEntry.cancelEdit();
197
		fPath.cancelEdit();
198
		super.cancelEdit();
199
	}
200
201
	/* (non-Javadoc)
202
	 * @see org.eclipse.ui.forms.AbstractFormPart#refresh()
203
	 */
204
	public void refresh() {
205
		ITarget target = getTarget();
206
		fNameEntry.setValue(target.getName(), true);
207
		ILocationInfo info = getLocationInfo();
208
		fUseDefault.setSelection(info.useDefault());
209
		fCustomPath.setSelection(!info.useDefault());
210
		String path = (info.useDefault()) ? "" : info.getPath(); //$NON-NLS-1$
211
		fPath.setValue(path, true);
212
		fPath.getText().setEditable(!info.useDefault());
213
		fFileSystem.setEnabled(!info.useDefault());
214
		fVariable.setEnabled(!info.useDefault());
215
		super.refresh();
216
	}
217
218
	public boolean canPaste(Clipboard clipboard) {
219
		Display d = getSection().getDisplay();
220
		Control c = d.getFocusControl();
221
		if (c instanceof Text)
222
			return true;
223
		return false;
224
	}
225
226
	protected void handleBrowseFileSystem() {
227
		DirectoryDialog dialog = new DirectoryDialog(getSection().getShell());
228
		String text = fPath.getValue();
229
		if (text.length() == 0)
230
			text = TargetEditor.LAST_PATH;
231
		dialog.setFilterPath(text);
232
		dialog.setText(PDEUIMessages.BaseBlock_dirSelection);
233
		dialog.setMessage(PDEUIMessages.BaseBlock_dirChoose);
234
		String result = dialog.open();
235
		if (result != null) {
236
			fPath.setValue(result);
237
			getLocationInfo().setPath(result);
238
			TargetEditor.LAST_PATH = result;
239
		}
240
	}
241
242
	private void handleInsertVariable() {
243
		StringVariableSelectionDialog dialog = new StringVariableSelectionDialog(PDEPlugin.getActiveWorkbenchShell());
244
		if (dialog.open() == Window.OK) {
245
			fPath.getText().insert(dialog.getVariableExpression());
246
			// have to setValue to make sure getValue reflects the actual text in the Text object.
247
			fPath.setValue(fPath.getText().getText());
248
			getLocationInfo().setPath(fPath.getText().getText());
249
		}
250
	}
251
252
	private ILocationInfo getLocationInfo() {
253
		ILocationInfo info = getTarget().getLocationInfo();
254
		if (info == null) {
255
			info = getModel().getFactory().createLocation();
256
			getTarget().setLocationInfo(info);
257
		}
258
		return info;
259
	}
260
261
	private ITarget getTarget() {
262
		return getModel().getTarget();
263
	}
264
265
	private ITargetModel getModel() {
266
		return (ITargetModel) getPage().getPDEEditor().getAggregateModel();
267
	}
268
}
(-)src/org/eclipse/pde/internal/ui/editor/target/JRESection.java (-246 / +197 lines)
Lines 1-246 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2008 IBM Corporation and others.
2
 * Copyright (c) 2005, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.editor.target;
11
package org.eclipse.pde.internal.ui.editor.target;
12
12
13
import java.util.TreeSet;
13
import java.util.TreeSet;
14
import org.eclipse.jdt.launching.JavaRuntime;
14
import org.eclipse.jdt.launching.JavaRuntime;
15
import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
15
import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
16
import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager;
16
import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager;
17
import org.eclipse.pde.core.IModelChangedEvent;
17
import org.eclipse.pde.internal.core.target.provisional.ITargetDefinition;
18
import org.eclipse.pde.internal.core.itarget.*;
18
import org.eclipse.pde.internal.core.util.VMUtil;
19
import org.eclipse.pde.internal.core.util.VMUtil;
19
import org.eclipse.pde.internal.ui.PDEUIMessages;
20
import org.eclipse.pde.internal.ui.PDEUIMessages;
20
import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
21
import org.eclipse.pde.internal.ui.editor.*;
21
import org.eclipse.pde.internal.ui.parts.ComboPart;
22
import org.eclipse.pde.internal.ui.parts.ComboPart;
22
import org.eclipse.swt.SWT;
23
import org.eclipse.swt.SWT;
23
import org.eclipse.swt.events.*;
24
import org.eclipse.swt.events.*;
24
import org.eclipse.swt.layout.GridData;
25
import org.eclipse.swt.layout.GridData;
25
import org.eclipse.swt.widgets.Button;
26
import org.eclipse.swt.widgets.Button;
26
import org.eclipse.swt.widgets.Composite;
27
import org.eclipse.swt.widgets.Composite;
27
import org.eclipse.ui.dialogs.PreferencesUtil;
28
import org.eclipse.ui.dialogs.PreferencesUtil;
28
import org.eclipse.ui.forms.SectionPart;
29
import org.eclipse.ui.forms.widgets.FormToolkit;
29
import org.eclipse.ui.forms.editor.FormPage;
30
import org.eclipse.ui.forms.widgets.Section;
30
import org.eclipse.ui.forms.widgets.*;
31
31
32
public class JRESection extends PDESection {
32
public class JRESection extends SectionPart {
33
33
34
	private Button fDefaultJREButton;
34
	private Button fDefaultJREButton;
35
	private Button fNamedJREButton;
35
	private Button fNamedJREButton;
36
	private Button fExecEnvButton;
36
	private Button fExecEnvButton;
37
	private ComboPart fNamedJREsCombo;
37
	private ComboPart fNamedJREsCombo;
38
	private ComboPart fExecEnvsCombo;
38
	private ComboPart fExecEnvsCombo;
39
	private TreeSet fExecEnvChoices;
39
	private TreeSet fExecEnvChoices;
40
	private boolean fBlockChanges;
40
	private boolean fBlockChanges;
41
	private Button fConfigureJREButton;
41
	private Button fConfigureJREButton;
42
42
	private TargetEditor fEditor;
43
	private static String JRE_PREF_PAGE_ID = "org.eclipse.jdt.debug.ui.preferences.VMPreferencePage"; //$NON-NLS-1$
43
44
	private static String EE_PREF_PAGE_ID = "org.eclipse.jdt.debug.ui.jreProfiles"; //$NON-NLS-1$
44
	private static String JRE_PREF_PAGE_ID = "org.eclipse.jdt.debug.ui.preferences.VMPreferencePage"; //$NON-NLS-1$
45
45
	private static String EE_PREF_PAGE_ID = "org.eclipse.jdt.debug.ui.jreProfiles"; //$NON-NLS-1$
46
	public JRESection(PDEFormPage page, Composite parent) {
46
47
		super(page, parent, Section.DESCRIPTION);
47
	public JRESection(FormPage page, Composite parent) {
48
		createClient(getSection(), page.getEditor().getToolkit());
48
		super(parent, page.getManagedForm().getToolkit(), Section.DESCRIPTION | ExpandableComposite.TITLE_BAR);
49
	}
49
		fEditor = (TargetEditor) page.getEditor();
50
50
		createClient(getSection(), page.getEditor().getToolkit());
51
	protected void createClient(Section section, FormToolkit toolkit) {
51
	}
52
		section.setText(PDEUIMessages.JRESection_title);
52
53
		section.setDescription(PDEUIMessages.JRESection_description);
53
	private ITargetDefinition getTarget() {
54
		section.setLayout(FormLayoutFactory.createClearGridLayout(false, 1));
54
		return fEditor.getTarget();
55
		GridData data = new GridData(GridData.FILL_HORIZONTAL);
55
	}
56
		data.verticalAlignment = SWT.TOP;
56
57
		data.horizontalSpan = 2;
57
	protected void createClient(Section section, FormToolkit toolkit) {
58
		section.setLayoutData(data);
58
		section.setText(PDEUIMessages.JRESection_title);
59
59
		section.setDescription(PDEUIMessages.JRESection_description + "  Selecting a named JRE will change the workspace default JRE setting.");
60
		Composite client = toolkit.createComposite(section);
60
		section.setLayout(FormLayoutFactory.createClearGridLayout(false, 1));
61
		client.setLayout(FormLayoutFactory.createSectionClientGridLayout(false, 3));
61
		GridData data = new GridData(GridData.FILL_HORIZONTAL);
62
62
		data.verticalAlignment = SWT.TOP;
63
		initializeValues();
63
		data.horizontalSpan = 2;
64
64
		section.setLayoutData(data);
65
		fDefaultJREButton = toolkit.createButton(client, PDEUIMessages.JRESection_defaultJRE, SWT.RADIO);
65
66
		GridData gd = new GridData();
66
		Composite client = toolkit.createComposite(section);
67
		gd.horizontalSpan = 3;
67
		client.setLayout(FormLayoutFactory.createSectionClientGridLayout(false, 3));
68
		fDefaultJREButton.setLayoutData(gd);
68
69
		fDefaultJREButton.addSelectionListener(new SelectionAdapter() {
69
		initializeValues();
70
			public void widgetSelected(SelectionEvent e) {
70
71
				updateWidgets();
71
		fDefaultJREButton = toolkit.createButton(client, PDEUIMessages.JRESection_defaultJRE, SWT.RADIO);
72
				if (!fBlockChanges)
72
		GridData gd = new GridData();
73
					getRuntimeInfo().setDefaultJRE();
73
		gd.horizontalSpan = 3;
74
			}
74
		fDefaultJREButton.setLayoutData(gd);
75
		});
75
		fDefaultJREButton.addSelectionListener(new SelectionAdapter() {
76
76
			public void widgetSelected(SelectionEvent e) {
77
		fNamedJREButton = toolkit.createButton(client, PDEUIMessages.JRESection_JREName, SWT.RADIO);
77
				updateWidgets();
78
		fNamedJREButton.addSelectionListener(new SelectionAdapter() {
78
				if (!fBlockChanges) {
79
			public void widgetSelected(SelectionEvent e) {
79
//					 TODO getRuntimeInfo().setDefaultJRE();
80
				updateWidgets();
80
				}
81
				if (!fBlockChanges)
81
			}
82
					getRuntimeInfo().setNamedJRE(fNamedJREsCombo.getSelection());
82
		});
83
			}
83
84
		});
84
		fNamedJREButton = toolkit.createButton(client, PDEUIMessages.JRESection_JREName, SWT.RADIO);
85
85
		fNamedJREButton.addSelectionListener(new SelectionAdapter() {
86
		fNamedJREsCombo = new ComboPart();
86
			public void widgetSelected(SelectionEvent e) {
87
		fNamedJREsCombo.createControl(client, toolkit, SWT.SINGLE | SWT.BORDER);
87
				updateWidgets();
88
		fNamedJREsCombo.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
88
				if (!fBlockChanges) {
89
		String[] installs = VMUtil.getVMInstallNames();
89
//					TODO getRuntimeInfo().setNamedJRE(fNamedJREsCombo.getSelection());
90
		fNamedJREsCombo.setItems(installs);
90
				}
91
		fNamedJREsCombo.addModifyListener(new ModifyListener() {
91
			}
92
			public void modifyText(ModifyEvent e) {
92
		});
93
				if (!fBlockChanges)
93
94
					getRuntimeInfo().setNamedJRE(fNamedJREsCombo.getSelection());
94
		fNamedJREsCombo = new ComboPart();
95
			}
95
		fNamedJREsCombo.createControl(client, toolkit, SWT.SINGLE | SWT.BORDER);
96
		});
96
		fNamedJREsCombo.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
97
97
		String[] installs = VMUtil.getVMInstallNames();
98
		fConfigureJREButton = toolkit.createButton(client, PDEUIMessages.JRESection_jrePreference, SWT.PUSH);
98
		fNamedJREsCombo.setItems(installs);
99
		fConfigureJREButton.addSelectionListener(new SelectionAdapter() {
99
		fNamedJREsCombo.addModifyListener(new ModifyListener() {
100
			public void widgetSelected(SelectionEvent e) {
100
			public void modifyText(ModifyEvent e) {
101
				openPreferencePage(JRE_PREF_PAGE_ID);
101
//				if (!fBlockChanges)
102
			}
102
//		TODO			getRuntimeInfo().setNamedJRE(fNamedJREsCombo.getSelection());
103
		});
103
			}
104
104
		});
105
		fExecEnvButton = toolkit.createButton(client, PDEUIMessages.JRESection_ExecutionEnv, SWT.RADIO);
105
106
		fExecEnvButton.addSelectionListener(new SelectionAdapter() {
106
		fConfigureJREButton = toolkit.createButton(client, PDEUIMessages.JRESection_jrePreference, SWT.PUSH);
107
			public void widgetSelected(SelectionEvent e) {
107
		fConfigureJREButton.addSelectionListener(new SelectionAdapter() {
108
				updateWidgets();
108
			public void widgetSelected(SelectionEvent e) {
109
				if (!fBlockChanges)
109
				openPreferencePage(JRE_PREF_PAGE_ID);
110
					getRuntimeInfo().setExecutionEnvJRE(fExecEnvsCombo.getSelection());
110
			}
111
			}
111
		});
112
		});
112
113
113
		fExecEnvButton = toolkit.createButton(client, PDEUIMessages.JRESection_ExecutionEnv, SWT.RADIO);
114
		fExecEnvsCombo = new ComboPart();
114
		fExecEnvButton.addSelectionListener(new SelectionAdapter() {
115
		fExecEnvsCombo.createControl(client, toolkit, SWT.SINGLE | SWT.BORDER);
115
			public void widgetSelected(SelectionEvent e) {
116
		fExecEnvsCombo.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
116
				updateWidgets();
117
		fExecEnvsCombo.setItems((String[]) fExecEnvChoices.toArray(new String[fExecEnvChoices.size()]));
117
//				if (!fBlockChanges)
118
		fExecEnvsCombo.addModifyListener(new ModifyListener() {
118
//			TODO		getRuntimeInfo().setExecutionEnvJRE(fExecEnvsCombo.getSelection());
119
			public void modifyText(ModifyEvent e) {
119
			}
120
				if (!fBlockChanges)
120
		});
121
					getRuntimeInfo().setExecutionEnvJRE(fExecEnvsCombo.getSelection());
121
122
			}
122
		fExecEnvsCombo = new ComboPart();
123
		});
123
		fExecEnvsCombo.createControl(client, toolkit, SWT.SINGLE | SWT.BORDER);
124
124
		fExecEnvsCombo.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
125
		Button configureEEButton = toolkit.createButton(client, PDEUIMessages.JRESection_eePreference, SWT.PUSH);
125
		fExecEnvsCombo.setItems((String[]) fExecEnvChoices.toArray(new String[fExecEnvChoices.size()]));
126
		configureEEButton.addSelectionListener(new SelectionAdapter() {
126
		fExecEnvsCombo.addModifyListener(new ModifyListener() {
127
			public void widgetSelected(SelectionEvent e) {
127
			public void modifyText(ModifyEvent e) {
128
				openPreferencePage(EE_PREF_PAGE_ID);
128
//				if (!fBlockChanges)
129
			}
129
//		TODO			getRuntimeInfo().setExecutionEnvJRE(fExecEnvsCombo.getSelection());
130
		});
130
			}
131
		configureEEButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
131
		});
132
132
133
		section.setClient(client);
133
		Button configureEEButton = toolkit.createButton(client, PDEUIMessages.JRESection_eePreference, SWT.PUSH);
134
134
		configureEEButton.addSelectionListener(new SelectionAdapter() {
135
		// Register to be notified when the model changes
135
			public void widgetSelected(SelectionEvent e) {
136
		getModel().addModelChangedListener(this);
136
				openPreferencePage(EE_PREF_PAGE_ID);
137
	}
137
			}
138
138
		});
139
	/* (non-Javadoc)
139
		configureEEButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
140
	 * @see org.eclipse.pde.internal.ui.editor.PDESection#modelChanged(org.eclipse.pde.core.IModelChangedEvent)
140
141
	 */
141
		section.setClient(client);
142
	public void modelChanged(IModelChangedEvent e) {
142
143
		// No need to call super, handling world changed event here
143
	}
144
		if (e.getChangeType() == IModelChangedEvent.WORLD_CHANGED) {
144
145
			handleModelEventWorldChanged(e);
145
	protected void initializeValues() {
146
		}
146
		fExecEnvChoices = new TreeSet();
147
	}
147
		IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager();
148
148
		IExecutionEnvironment[] envs = manager.getExecutionEnvironments();
149
	/**
149
		for (int i = 0; i < envs.length; i++)
150
	 * @param event
150
			fExecEnvChoices.add(envs[i].getId());
151
	 */
151
	}
152
	private void handleModelEventWorldChanged(IModelChangedEvent event) {
152
153
		// Perform the refresh
153
	protected void updateWidgets() {
154
		refresh();
154
		fNamedJREsCombo.setEnabled(fNamedJREButton.getSelection());
155
		// Note:  A deferred selection event is fired from radio buttons when
155
		fExecEnvsCombo.setEnabled(fExecEnvButton.getSelection());
156
		// their value is toggled, the user switches to another page, and the
156
	}
157
		// user switches back to the same page containing the radio buttons
157
158
		// This appears to be a result of a SWT bug.
158
	public void refresh() {
159
		// If the radio button is the last widget to have focus when leaving 
159
//		fBlockChanges = true;
160
		// the page, an event will be fired when entering the page again.
160
//		ITargetJRE info = getRuntimeInfo();
161
		// An event is not fired if the radio button does not have focus.
161
//
162
		// The solution is to redirect focus to a stable widget.
162
//		int jreType = info.getJREType();
163
		getPage().setLastFocusControl(fConfigureJREButton);
163
//		fDefaultJREButton.setSelection(jreType == ITargetJRE.TYPE_DEFAULT);
164
	}
164
//		fNamedJREButton.setSelection(jreType == ITargetJRE.TYPE_NAMED);
165
165
//		fExecEnvButton.setSelection(jreType == ITargetJRE.TYPE_EXECUTION_ENV);
166
	/* (non-Javadoc)
166
//
167
	 * @see org.eclipse.ui.forms.AbstractFormPart#dispose()
167
//		String jreName = info.getJREName();
168
	 */
168
//		if (jreType == ITargetJRE.TYPE_NAMED) {
169
	public void dispose() {
169
//			if (fNamedJREsCombo.indexOf(jreName) < 0)
170
		ITargetModel model = getModel();
170
//				fNamedJREsCombo.add(jreName);
171
		if (model != null) {
171
//			fNamedJREsCombo.select(fNamedJREsCombo.indexOf(jreName));
172
			model.removeModelChangedListener(this);
172
//		} else if (jreType == ITargetJRE.TYPE_EXECUTION_ENV) {
173
		}
173
//			if (fExecEnvsCombo.indexOf(jreName) < 0)
174
		super.dispose();
174
//				fExecEnvsCombo.add(jreName);
175
	}
175
//			fExecEnvsCombo.select(fExecEnvsCombo.indexOf(jreName));
176
176
//		}
177
	protected void initializeValues() {
177
//
178
		fExecEnvChoices = new TreeSet();
178
//		if (fExecEnvsCombo.getSelectionIndex() == -1)
179
		IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager();
179
//			fExecEnvsCombo.setText(fExecEnvChoices.first().toString());
180
		IExecutionEnvironment[] envs = manager.getExecutionEnvironments();
180
//
181
		for (int i = 0; i < envs.length; i++)
181
//		if (fNamedJREsCombo.getSelectionIndex() == -1)
182
			fExecEnvChoices.add(envs[i].getId());
182
//			fNamedJREsCombo.setText(VMUtil.getDefaultVMInstallName());
183
	}
183
//
184
184
//		updateWidgets();
185
	protected void updateWidgets() {
185
//		super.refresh();
186
		fNamedJREsCombo.setEnabled(fNamedJREButton.getSelection());
186
//		fBlockChanges = false;
187
		fExecEnvsCombo.setEnabled(fExecEnvButton.getSelection());
187
	}
188
	}
188
189
189
	private void openPreferencePage(String pageID) {
190
	private ITargetJRE getRuntimeInfo() {
190
		fBlockChanges = true;
191
		ITargetJRE info = getTarget().getTargetJREInfo();
191
		PreferencesUtil.createPreferenceDialogOn(fEditor.getEditorSite().getShell(), pageID, new String[] {pageID}, null).open();
192
		if (info == null) {
192
		// reset JRE select because either JDT preference page allows user to add/remove JREs
193
			info = getModel().getFactory().createJREInfo();
193
		fNamedJREsCombo.setItems(VMUtil.getVMInstallNames());
194
			getTarget().setTargetJREInfo(info);
194
		fBlockChanges = false;
195
		}
195
	}
196
		return info;
196
197
	}
197
}
198
199
	private ITarget getTarget() {
200
		return getModel().getTarget();
201
	}
202
203
	private ITargetModel getModel() {
204
		return (ITargetModel) getPage().getPDEEditor().getAggregateModel();
205
	}
206
207
	public void refresh() {
208
		fBlockChanges = true;
209
		ITargetJRE info = getRuntimeInfo();
210
211
		int jreType = info.getJREType();
212
		fDefaultJREButton.setSelection(jreType == ITargetJRE.TYPE_DEFAULT);
213
		fNamedJREButton.setSelection(jreType == ITargetJRE.TYPE_NAMED);
214
		fExecEnvButton.setSelection(jreType == ITargetJRE.TYPE_EXECUTION_ENV);
215
216
		String jreName = info.getJREName();
217
		if (jreType == ITargetJRE.TYPE_NAMED) {
218
			if (fNamedJREsCombo.indexOf(jreName) < 0)
219
				fNamedJREsCombo.add(jreName);
220
			fNamedJREsCombo.select(fNamedJREsCombo.indexOf(jreName));
221
		} else if (jreType == ITargetJRE.TYPE_EXECUTION_ENV) {
222
			if (fExecEnvsCombo.indexOf(jreName) < 0)
223
				fExecEnvsCombo.add(jreName);
224
			fExecEnvsCombo.select(fExecEnvsCombo.indexOf(jreName));
225
		}
226
227
		if (fExecEnvsCombo.getSelectionIndex() == -1)
228
			fExecEnvsCombo.setText(fExecEnvChoices.first().toString());
229
230
		if (fNamedJREsCombo.getSelectionIndex() == -1)
231
			fNamedJREsCombo.setText(VMUtil.getDefaultVMInstallName());
232
233
		updateWidgets();
234
		super.refresh();
235
		fBlockChanges = false;
236
	}
237
238
	private void openPreferencePage(String pageID) {
239
		fBlockChanges = true;
240
		PreferencesUtil.createPreferenceDialogOn(getPage().getEditor().getEditorSite().getShell(), pageID, new String[] {pageID}, null).open();
241
		// reset JRE select because either JDT preference page allows user to add/remove JREs
242
		fNamedJREsCombo.setItems(VMUtil.getVMInstallNames());
243
		fBlockChanges = false;
244
	}
245
246
}
(-)src/org/eclipse/pde/internal/ui/editor/target/LocationDialog.java (-200 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.editor.target;
12
13
import org.eclipse.core.runtime.*;
14
import org.eclipse.debug.ui.StringVariableSelectionDialog;
15
import org.eclipse.jface.dialogs.Dialog;
16
import org.eclipse.jface.dialogs.StatusDialog;
17
import org.eclipse.jface.window.Window;
18
import org.eclipse.pde.core.plugin.TargetPlatform;
19
import org.eclipse.pde.internal.core.itarget.*;
20
import org.eclipse.pde.internal.ui.*;
21
import org.eclipse.pde.internal.ui.util.SWTUtil;
22
import org.eclipse.swt.SWT;
23
import org.eclipse.swt.events.*;
24
import org.eclipse.swt.layout.GridData;
25
import org.eclipse.swt.layout.GridLayout;
26
import org.eclipse.swt.widgets.*;
27
import org.eclipse.ui.PlatformUI;
28
29
public class LocationDialog extends StatusDialog {
30
31
	private Text fPath;
32
	private ITarget fTarget;
33
	private IAdditionalLocation fLocation;
34
	private IStatus fOkStatus;
35
	private IStatus fErrorStatus;
36
37
	public LocationDialog(Shell parent, ITarget target, IAdditionalLocation location) {
38
		super(parent);
39
		fTarget = target;
40
		fLocation = location;
41
	}
42
43
	/*
44
	 * @see org.eclipse.jface.window.Window#configureShell(Shell)
45
	 */
46
	protected void configureShell(Shell shell) {
47
		super.configureShell(shell);
48
		PlatformUI.getWorkbench().getHelpSystem().setHelp(shell, IHelpContextIds.TARGET_LOCATION_DIALOG);
49
	}
50
51
	protected Control createDialogArea(Composite parent) {
52
		Composite container = new Composite(parent, SWT.NULL);
53
		GridLayout layout = new GridLayout();
54
		layout.numColumns = 4;
55
		layout.marginHeight = layout.marginWidth = 10;
56
		container.setLayout(layout);
57
		GridData gd = new GridData(GridData.FILL_BOTH);
58
		container.setLayoutData(gd);
59
60
		createEntry(container);
61
62
		ModifyListener listener = new ModifyListener() {
63
			public void modifyText(ModifyEvent e) {
64
				dialogChanged();
65
			}
66
		};
67
		fPath.addModifyListener(listener);
68
		setTitle(PDEUIMessages.LocationDialog_title);
69
		Dialog.applyDialogFont(container);
70
71
		dialogChanged();
72
73
		return container;
74
	}
75
76
	protected void createEntry(Composite container) {
77
		Label label = new Label(container, SWT.NULL);
78
		label.setText(PDEUIMessages.LocationDialog_path);
79
		label.setLayoutData(new GridData());
80
81
		fPath = new Text(container, SWT.SINGLE | SWT.BORDER);
82
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
83
		gd.horizontalSpan = 3;
84
		fPath.setLayoutData(gd);
85
86
		if (fLocation != null) {
87
			fPath.setText(fLocation.getPath());
88
		}
89
90
		label = new Label(container, SWT.NONE);
91
		gd = new GridData(GridData.FILL_HORIZONTAL);
92
		gd.horizontalSpan = 2;
93
		label.setLayoutData(gd);
94
95
		Button fs = new Button(container, SWT.PUSH);
96
		fs.setText(PDEUIMessages.LocationDialog_fileSystem);
97
		fs.setLayoutData(new GridData());
98
		fs.addSelectionListener(new SelectionAdapter() {
99
			public void widgetSelected(SelectionEvent e) {
100
				handleBrowseFileSystem();
101
			}
102
		});
103
		SWTUtil.setButtonDimensionHint(fs);
104
105
		Button var = new Button(container, SWT.PUSH);
106
		var.setText(PDEUIMessages.LocationDialog_variables);
107
		var.setLayoutData(new GridData());
108
		var.addSelectionListener(new SelectionAdapter() {
109
			public void widgetSelected(SelectionEvent e) {
110
				handleInsertVariable();
111
			}
112
		});
113
		SWTUtil.setButtonDimensionHint(var);
114
	}
115
116
	private IStatus createErrorStatus(String message) {
117
		return new Status(IStatus.ERROR, PDEPlugin.getPluginId(), IStatus.OK, message, null);
118
	}
119
120
	private void dialogChanged() {
121
		IStatus status = null;
122
		if (fPath.getText().length() == 0)
123
			status = getEmptyErrorStatus();
124
		else {
125
			if (hasPath(fPath.getText()))
126
				status = createErrorStatus(PDEUIMessages.LocationDialog_locationExists);
127
		}
128
		if (status == null)
129
			status = getOKStatus();
130
		updateStatus(status);
131
	}
132
133
	private IStatus getOKStatus() {
134
		if (fOkStatus == null)
135
			fOkStatus = new Status(IStatus.OK, PDEPlugin.getPluginId(), IStatus.OK, "", //$NON-NLS-1$
136
					null);
137
		return fOkStatus;
138
	}
139
140
	private IStatus getEmptyErrorStatus() {
141
		if (fErrorStatus == null)
142
			fErrorStatus = createErrorStatus(PDEUIMessages.LocationDialog_emptyPath);
143
		return fErrorStatus;
144
	}
145
146
	protected boolean hasPath(String path) {
147
		Path checkPath = new Path(path);
148
		Path currentPath = (fLocation != null) ? new Path(fLocation.getPath()) : null;
149
		if (checkPath.equals(currentPath))
150
			return false;
151
		IAdditionalLocation[] locs = fTarget.getAdditionalDirectories();
152
		for (int i = 0; i < locs.length; i++) {
153
			if (new Path(locs[i].getPath()).equals(checkPath))
154
				return true;
155
		}
156
		return isTargetLocation(checkPath);
157
	}
158
159
	private boolean isTargetLocation(Path path) {
160
		ILocationInfo info = fTarget.getLocationInfo();
161
		if (info.useDefault()) {
162
			Path home = new Path(TargetPlatform.getDefaultLocation());
163
			return home.equals(path);
164
		}
165
		return new Path(info.getPath()).equals(path);
166
	}
167
168
	protected void handleBrowseFileSystem() {
169
		DirectoryDialog dialog = new DirectoryDialog(getShell());
170
		String text = fPath.getText();
171
		if (text.length() == 0)
172
			text = TargetEditor.LAST_PATH;
173
		dialog.setFilterPath(text);
174
		dialog.setText(PDEUIMessages.BaseBlock_dirSelection);
175
		dialog.setMessage(PDEUIMessages.BaseBlock_dirChoose);
176
		String result = dialog.open();
177
		if (result != null) {
178
			fPath.setText(result);
179
			TargetEditor.LAST_PATH = result;
180
		}
181
	}
182
183
	private void handleInsertVariable() {
184
		StringVariableSelectionDialog dialog = new StringVariableSelectionDialog(getShell());
185
		if (dialog.open() == Window.OK) {
186
			fPath.insert(dialog.getVariableExpression());
187
		}
188
	}
189
190
	protected void okPressed() {
191
		boolean add = fLocation == null;
192
		if (add) {
193
			fLocation = fTarget.getModel().getFactory().createAdditionalLocation();
194
		}
195
		fLocation.setPath(fPath.getText());
196
		if (add)
197
			fTarget.addAdditionalDirectories(new IAdditionalLocation[] {fLocation});
198
		super.okPressed();
199
	}
200
}
(-)src/org/eclipse/pde/internal/ui/editor/target/ContentSection.java (-668 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     Bartosz Michalik <bartosz.michalik@gmail.com> - bug 187646
11
 *     Les Jones <lesojones@gmail.com> - bug 190717
12
 *******************************************************************************/
13
package org.eclipse.pde.internal.ui.editor.target;
14
15
import org.eclipse.pde.internal.ui.dialogs.FeatureSelectionDialog;
16
17
import java.util.*;
18
import org.eclipse.core.resources.IFile;
19
import org.eclipse.core.resources.IProject;
20
import org.eclipse.core.runtime.*;
21
import org.eclipse.jdt.core.IJavaProject;
22
import org.eclipse.jface.action.*;
23
import org.eclipse.jface.viewers.*;
24
import org.eclipse.jface.window.Window;
25
import org.eclipse.osgi.service.resolver.BundleDescription;
26
import org.eclipse.pde.core.IModelChangedEvent;
27
import org.eclipse.pde.core.plugin.IPluginModelBase;
28
import org.eclipse.pde.core.plugin.PluginRegistry;
29
import org.eclipse.pde.internal.core.PDECore;
30
import org.eclipse.pde.internal.core.TargetPlatformHelper;
31
import org.eclipse.pde.internal.core.ifeature.IFeature;
32
import org.eclipse.pde.internal.core.ifeature.IFeatureModel;
33
import org.eclipse.pde.internal.core.itarget.*;
34
import org.eclipse.pde.internal.core.plugin.ExternalPluginModelBase;
35
import org.eclipse.pde.internal.ui.*;
36
import org.eclipse.pde.internal.ui.editor.*;
37
import org.eclipse.pde.internal.ui.editor.feature.FeatureEditor;
38
import org.eclipse.pde.internal.ui.editor.plugin.ManifestEditor;
39
import org.eclipse.pde.internal.ui.elements.DefaultTableProvider;
40
import org.eclipse.pde.internal.ui.parts.ConditionalListSelectionDialog;
41
import org.eclipse.pde.internal.ui.parts.TablePart;
42
import org.eclipse.pde.internal.ui.search.dependencies.DependencyCalculator;
43
import org.eclipse.pde.internal.ui.util.PersistablePluginObject;
44
import org.eclipse.swt.SWT;
45
import org.eclipse.swt.custom.CTabFolder;
46
import org.eclipse.swt.custom.CTabItem;
47
import org.eclipse.swt.events.SelectionAdapter;
48
import org.eclipse.swt.events.SelectionEvent;
49
import org.eclipse.swt.graphics.Color;
50
import org.eclipse.swt.graphics.Image;
51
import org.eclipse.swt.layout.GridData;
52
import org.eclipse.swt.widgets.*;
53
import org.eclipse.ui.*;
54
import org.eclipse.ui.actions.ActionFactory;
55
import org.eclipse.ui.dialogs.IWorkingSetSelectionDialog;
56
import org.eclipse.ui.forms.IFormColors;
57
import org.eclipse.ui.forms.widgets.FormToolkit;
58
import org.eclipse.ui.forms.widgets.Section;
59
60
public class ContentSection extends TableSection {
61
62
	class ContentProvider extends DefaultTableProvider {
63
		public Object[] getElements(Object parent) {
64
			ITarget target = getTarget();
65
			if (fLastTab == 0)
66
				return target.getPlugins();
67
			return target.getFeatures();
68
		}
69
	}
70
71
	private static final String[] TAB_LABELS = new String[2];
72
	static {
73
		TAB_LABELS[0] = PDEUIMessages.ContentSection_plugins;
74
		TAB_LABELS[1] = PDEUIMessages.ContentSection_features;
75
	}
76
77
	private static final String[] BUTTONS = new String[5];
78
	static {
79
		BUTTONS[0] = PDEUIMessages.ContentSection_add;
80
		BUTTONS[1] = PDEUIMessages.ContentSection_remove;
81
		BUTTONS[2] = PDEUIMessages.ContentSection_removeAll;
82
		BUTTONS[3] = PDEUIMessages.ContentSection_workingSet;
83
		BUTTONS[4] = PDEUIMessages.ContentSection_required;
84
	}
85
86
	private TableViewer fContentViewer;
87
	private CTabFolder fTabFolder;
88
	private int fLastTab;
89
	private Button fUseAllPlugins;
90
	private Button fUseSelectedPlugins;
91
	private Image[] fTabImages;
92
	private Button fIncludeOptionalButton;
93
	public static final QualifiedName OPTIONAL_PROPERTY = new QualifiedName(IPDEUIConstants.PLUGIN_ID, "target.includeOptional"); //$NON-NLS-1$
94
95
	public ContentSection(PDEFormPage page, Composite parent) {
96
		super(page, parent, Section.DESCRIPTION, BUTTONS);
97
	}
98
99
	/* (non-Javadoc)
100
	 * @see org.eclipse.pde.internal.ui.editor.PDESection#createClient(org.eclipse.ui.forms.widgets.Section, org.eclipse.ui.forms.widgets.FormToolkit)
101
	 */
102
	protected void createClient(Section section, FormToolkit toolkit) {
103
		section.setLayout(FormLayoutFactory.createClearGridLayout(false, 1));
104
		Composite client = toolkit.createComposite(section);
105
		client.setLayout(FormLayoutFactory.createSectionClientGridLayout(false, 2));
106
		client.setLayoutData(new GridData(GridData.FILL_BOTH));
107
108
		// create radio buttons
109
		SelectionAdapter radioListener = new SelectionAdapter() {
110
			public void widgetSelected(SelectionEvent e) {
111
				getTarget().setUseAllPlugins(fUseAllPlugins.getSelection());
112
			}
113
		};
114
115
		fUseAllPlugins = toolkit.createButton(client, PDEUIMessages.ContentSection_allTarget, SWT.RADIO);
116
		fUseAllPlugins.addSelectionListener(radioListener);
117
		GridData gd = new GridData();
118
		gd.horizontalSpan = 2;
119
		fUseAllPlugins.setLayoutData(gd);
120
121
		fUseSelectedPlugins = toolkit.createButton(client, PDEUIMessages.ContentSection_selectedOnly, SWT.RADIO);
122
		gd = new GridData();
123
		gd.horizontalSpan = 2;
124
		gd.verticalIndent = 5;
125
		fUseSelectedPlugins.setLayoutData(gd);
126
127
		// create tab folder widget
128
		fTabFolder = new CTabFolder(client, SWT.FLAT | SWT.TOP);
129
		gd = new GridData(GridData.FILL_HORIZONTAL);
130
		gd.heightHint = 2;
131
		gd.horizontalSpan = 2;
132
		gd.horizontalIndent = 15;
133
		fTabFolder.setLayoutData(gd);
134
		toolkit.adapt(fTabFolder, true, true);
135
		toolkit.getColors().initializeSectionToolBarColors();
136
		Color selectedColor = toolkit.getColors().getColor(IFormColors.TB_BG);
137
		fTabFolder.setSelectionBackground(new Color[] {selectedColor, toolkit.getColors().getBackground()}, new int[] {100}, true);
138
		fTabFolder.addSelectionListener(new SelectionAdapter() {
139
			public void widgetSelected(SelectionEvent e) {
140
				refresh();
141
			}
142
		});
143
144
		createTabs();
145
146
		// create table widget
147
		createViewerPartControl(client, SWT.MULTI, 2, toolkit);
148
149
		TablePart tablePart = getTablePart();
150
		GridData data = (GridData) tablePart.getControl().getLayoutData();
151
		data.grabExcessVerticalSpace = true;
152
		data.grabExcessHorizontalSpace = true;
153
		data.horizontalIndent = 15;
154
		fContentViewer = tablePart.getTableViewer();
155
		fContentViewer.setContentProvider(new ContentProvider());
156
		fContentViewer.setLabelProvider(PDEPlugin.getDefault().getLabelProvider());
157
		fContentViewer.setComparator(new ViewerComparator() {
158
			public int compare(Viewer viewer, Object e1, Object e2) {
159
				if (e1 instanceof ITargetPlugin) {
160
					ITargetPlugin p1 = (ITargetPlugin) e1;
161
					ITargetPlugin p2 = (ITargetPlugin) e2;
162
					return super.compare(viewer, p1.getId(), p2.getId());
163
				} // else 
164
				ITargetFeature f1 = (ITargetFeature) e1;
165
				ITargetFeature f2 = (ITargetFeature) e2;
166
				return super.compare(viewer, f1.getId(), f2.getId());
167
			}
168
		});
169
		fContentViewer.setInput(PDECore.getDefault().getModelManager());
170
		fContentViewer.addSelectionChangedListener(new ISelectionChangedListener() {
171
			public void selectionChanged(SelectionChangedEvent event) {
172
				updateEnablement();
173
			}
174
		});
175
176
		createOptionalDependenciesButton(client);
177
178
		toolkit.paintBordersFor(client);
179
		section.setClient(client);
180
		section.setText(PDEUIMessages.ContentSection_targetContent);
181
		section.setDescription(PDEUIMessages.ContentSection_targetContentDesc);
182
		section.setLayoutData(new GridData(GridData.FILL_BOTH));
183
		updateEnablement();
184
		getModel().addModelChangedListener(this);
185
	}
186
187
	private void createOptionalDependenciesButton(Composite client) {
188
		if (isEditable()) {
189
			fIncludeOptionalButton = new Button(client, SWT.CHECK);
190
			fIncludeOptionalButton.setText(PDEUIMessages.ContentSection_includeOptional);
191
			// initialize value
192
			IEditorInput input = getPage().getEditorInput();
193
			if (input instanceof IFileEditorInput) {
194
				IFile file = ((IFileEditorInput) input).getFile();
195
				try {
196
					fIncludeOptionalButton.setSelection("true".equals(file.getPersistentProperty(OPTIONAL_PROPERTY))); //$NON-NLS-1$
197
				} catch (CoreException e) {
198
				}
199
			}
200
			fIncludeOptionalButton.setEnabled(!getTarget().useAllPlugins());
201
			// create listener to save value when the checkbox is changed
202
			fIncludeOptionalButton.addSelectionListener(new SelectionAdapter() {
203
				public void widgetSelected(SelectionEvent e) {
204
					IEditorInput input = getPage().getEditorInput();
205
					if (input instanceof IFileEditorInput) {
206
						IFile file = ((IFileEditorInput) input).getFile();
207
						try {
208
							file.setPersistentProperty(OPTIONAL_PROPERTY, fIncludeOptionalButton.getSelection() ? "true" : null); //$NON-NLS-1$
209
						} catch (CoreException e1) {
210
						}
211
					}
212
				}
213
			});
214
		}
215
	}
216
217
	/* (non-Javadoc)
218
	 * @see org.eclipse.pde.internal.ui.editor.StructuredViewerSection#buttonSelected(int)
219
	 */
220
	protected void buttonSelected(int index) {
221
		switch (index) {
222
			case 0 :
223
				handleAdd();
224
				break;
225
			case 1 :
226
				handleDelete();
227
				break;
228
			case 2 :
229
				handleRemoveAll();
230
				break;
231
			case 3 :
232
				handleAddWorkingSet();
233
				break;
234
			case 4 :
235
				handleAddRequired(getTarget().getPlugins(), fIncludeOptionalButton.getSelection());
236
		}
237
	}
238
239
	private void createTabs() {
240
		fTabImages = new Image[] {PDEPluginImages.DESC_PLUGIN_OBJ.createImage(), PDEPluginImages.DESC_FEATURE_OBJ.createImage()};
241
		for (int i = 0; i < TAB_LABELS.length; i++) {
242
			CTabItem item = new CTabItem(fTabFolder, SWT.NULL);
243
			item.setText(TAB_LABELS[i]);
244
			item.setImage(fTabImages[i]);
245
		}
246
		fLastTab = 0;
247
		fTabFolder.setSelection(fLastTab);
248
	}
249
250
	/* (non-Javadoc)
251
	 * @see org.eclipse.ui.forms.AbstractFormPart#refresh()
252
	 */
253
	public void refresh() {
254
		fLastTab = fTabFolder.getSelectionIndex();
255
		fContentViewer.refresh();
256
		updateEnablement();
257
		super.refresh();
258
	}
259
260
	protected void updateEnablement() {
261
		boolean useAllPlugins = getTarget().useAllPlugins();
262
		fUseAllPlugins.setSelection(useAllPlugins);
263
		fUseSelectedPlugins.setSelection(!useAllPlugins);
264
		TablePart table = getTablePart();
265
		boolean itemsSelected = !fContentViewer.getSelection().isEmpty();
266
		boolean hasItems = fContentViewer.getTable().getItemCount() > 0;
267
		table.setEnabled(!useAllPlugins);
268
		table.setButtonEnabled(0, isEditable() && !useAllPlugins);
269
		table.setButtonEnabled(1, isEditable() && !useAllPlugins && itemsSelected);
270
		table.setButtonEnabled(2, isEditable() && !useAllPlugins && hasItems);
271
		boolean pluginTab = (fLastTab == 0);
272
		table.setButtonEnabled(3, isEditable() && pluginTab && !useAllPlugins);
273
		table.setButtonEnabled(4, isEditable() && pluginTab && !useAllPlugins && hasItems);
274
275
		// Fix for defect 190717
276
		// Only show the working set and required buttons on the plugin tab
277
		// (retaining the existing enablement logic in the rare case the 
278
		// platform doesn't support control.visible=false; I can't imagine
279
		// how this would happen, but better to be safe?)
280
		table.setButtonVisible(3, pluginTab);
281
		table.setButtonVisible(4, pluginTab);
282
283
	}
284
285
	protected boolean canPaste(Object target, Object[] objects) {
286
		for (int i = 0; i < objects.length; i++) {
287
			if (objects[i] instanceof ITargetPlugin && fLastTab == 0 || objects[i] instanceof ITargetFeature && fLastTab == 1)
288
				return true;
289
		}
290
		return false;
291
	}
292
293
	private ITarget getTarget() {
294
		return getModel().getTarget();
295
	}
296
297
	private ITargetModel getModel() {
298
		return (ITargetModel) getPage().getPDEEditor().getAggregateModel();
299
	}
300
301
	private void handleAdd() {
302
		if (fLastTab == 0)
303
			handleAddPlugin();
304
		else
305
			handleAddFeature();
306
		updateEnablement();
307
	}
308
309
	private void handleAddPlugin() {
310
		ConditionalListSelectionDialog dialog = new ConditionalListSelectionDialog(PDEPlugin.getActiveWorkbenchShell(), PDEPlugin.getDefault().getLabelProvider(), PDEUIMessages.ContentSection_addDialogButtonLabel);
311
312
		TreeMap map = getBundles();
313
		dialog.setElements(map.values().toArray());
314
		dialog.setConditionalElements(getWorkspaceBundles(map).values().toArray());
315
		dialog.setTitle(PDEUIMessages.PluginSelectionDialog_title);
316
		dialog.setMessage(PDEUIMessages.PluginSelectionDialog_message);
317
		dialog.setMultipleSelection(true);
318
		dialog.create();
319
		PlatformUI.getWorkbench().getHelpSystem().setHelp(dialog.getShell(), IHelpContextIds.PLUGIN_SELECTION);
320
		if (dialog.open() == Window.OK) {
321
			Object[] bundles = dialog.getResult();
322
			ITarget target = getTarget();
323
			ITargetModelFactory factory = getModel().getFactory();
324
			ITargetPlugin[] plugins = new ITargetPlugin[bundles.length];
325
			for (int i = 0; i < bundles.length; i++) {
326
				String id = ((BundleDescription) bundles[i]).getSymbolicName();
327
				ITargetPlugin plugin = factory.createPlugin();
328
				plugin.setId(id);
329
				plugins[i] = plugin;
330
			}
331
			target.addPlugins(plugins);
332
			fContentViewer.setSelection(new StructuredSelection(plugins[plugins.length - 1]));
333
		}
334
	}
335
336
	private TreeMap getBundles() {
337
		TreeMap map = new TreeMap();
338
		ITarget target = getTarget();
339
		IPluginModelBase[] models = PluginRegistry.getExternalModels();
340
		for (int i = 0; i < models.length; i++) {
341
			BundleDescription desc = ((ExternalPluginModelBase) models[i]).getBundleDescription();
342
			String id = desc.getSymbolicName();
343
			if (!target.containsPlugin(id))
344
				map.put(id, desc);
345
		}
346
		return map;
347
	}
348
349
	protected TreeMap getWorkspaceBundles(TreeMap used) {
350
		TreeMap map = new TreeMap();
351
		ITarget target = getTarget();
352
		IPluginModelBase[] models = PluginRegistry.getWorkspaceModels();
353
		for (int i = 0; i < models.length; i++) {
354
			BundleDescription desc = models[i].getBundleDescription();
355
			String id = desc.getSymbolicName();
356
			if (id != null && !target.containsPlugin(id) && !used.containsKey(id))
357
				map.put(id, desc);
358
		}
359
		return map;
360
	}
361
362
	private void handleAddFeature() {
363
		IFeatureModel[] allModels = PDECore.getDefault().getFeatureModelManager().getModels();
364
		ArrayList newModels = new ArrayList();
365
		ITarget target = getTarget();
366
		for (int i = 0; i < allModels.length; i++) {
367
			if (!target.containsFeature(allModels[i].getFeature().getId()))
368
				newModels.add(allModels[i]);
369
		}
370
		IFeatureModel[] candidateModels = (IFeatureModel[]) newModels.toArray(new IFeatureModel[newModels.size()]);
371
		FeatureSelectionDialog dialog = new FeatureSelectionDialog(getSection().getShell(), candidateModels, true);
372
		if (dialog.open() == Window.OK) {
373
			Object[] models = dialog.getResult();
374
			ITargetModelFactory factory = getModel().getFactory();
375
			ITargetFeature[] features = new ITargetFeature[models.length];
376
			for (int i = 0; i < models.length; ++i) {
377
				IFeature feature = ((IFeatureModel) models[i]).getFeature();
378
				String id = feature.getId();
379
				ITargetFeature tfeature = factory.createFeature();
380
				tfeature.setId(id);
381
				features[i] = tfeature;
382
			}
383
			target.addFeatures(features);
384
			fContentViewer.setSelection(new StructuredSelection(features[features.length - 1]));
385
		}
386
	}
387
388
	private void handleDelete() {
389
		IStructuredSelection ssel = (IStructuredSelection) fContentViewer.getSelection();
390
		if (ssel.size() > 0) {
391
			Object[] objects = ssel.toArray();
392
			ITarget target = getTarget();
393
			if (fLastTab == 0) {
394
				ITargetPlugin[] plugins = new ITargetPlugin[objects.length];
395
				System.arraycopy(objects, 0, plugins, 0, objects.length);
396
				target.removePlugins(plugins);
397
			} else {
398
				ITargetFeature[] features = new ITargetFeature[objects.length];
399
				System.arraycopy(objects, 0, features, 0, objects.length);
400
				target.removeFeatures(features);
401
			}
402
		}
403
		updateEnablement();
404
	}
405
406
	private void handleRemoveAll() {
407
		TableItem[] items = fContentViewer.getTable().getItems();
408
		ITarget target = getTarget();
409
		if (fLastTab == 0) {
410
			ITargetPlugin[] plugins = new ITargetPlugin[items.length];
411
			for (int i = 0; i < plugins.length; i++)
412
				plugins[i] = (ITargetPlugin) items[i].getData();
413
			target.removePlugins(plugins);
414
		} else {
415
			ITargetFeature[] features = new ITargetFeature[items.length];
416
			for (int i = 0; i < features.length; i++)
417
				features[i] = (ITargetFeature) items[i].getData();
418
			target.removeFeatures(features);
419
		}
420
		updateEnablement();
421
	}
422
423
	/* (non-Javadoc)
424
	 * @see org.eclipse.pde.internal.ui.editor.TableSection#handleDoubleClick(org.eclipse.jface.viewers.IStructuredSelection)
425
	 */
426
	protected void handleDoubleClick(IStructuredSelection selection) {
427
		handleOpen(selection);
428
	}
429
430
	private void handleOpen(IStructuredSelection selection) {
431
		Object object = selection.getFirstElement();
432
		if (object instanceof ITargetPlugin) {
433
			ManifestEditor.openPluginEditor(((ITargetPlugin) object).getId());
434
		} else if (object instanceof ITargetFeature) {
435
			handleOpenFeature((ITargetFeature) object);
436
		}
437
	}
438
439
	private void handleOpenFeature(ITargetFeature feature) {
440
		IFeatureModel model = PDECore.getDefault().getFeatureModelManager().findFeatureModel(feature.getId());
441
		FeatureEditor.openFeatureEditor(model);
442
	}
443
444
	private void handleAddWorkingSet() {
445
		IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager();
446
		IWorkingSetSelectionDialog dialog = manager.createWorkingSetSelectionDialog(PDEPlugin.getActiveWorkbenchShell(), true);
447
		if (dialog.open() == Window.OK) {
448
			IWorkingSet[] workingSets = dialog.getSelection();
449
			ITarget target = getTarget();
450
			ITargetModelFactory factory = target.getModel().getFactory();
451
			HashSet plugins = new HashSet();
452
			for (int i = 0; i < workingSets.length; i++) {
453
				IAdaptable[] elements = workingSets[i].getElements();
454
				for (int j = 0; j < elements.length; j++) {
455
					IPluginModelBase model = findModel(elements[j]);
456
					if (model != null) {
457
						ITargetPlugin plugin = factory.createPlugin();
458
						plugin.setId(model.getPluginBase().getId());
459
						plugins.add(plugin);
460
					}
461
				}
462
			}
463
			target.addPlugins((ITargetPlugin[]) plugins.toArray(new ITargetPlugin[plugins.size()]));
464
		}
465
		updateEnablement();
466
	}
467
468
	private IPluginModelBase findModel(IAdaptable object) {
469
		if (object instanceof IJavaProject)
470
			object = ((IJavaProject) object).getProject();
471
		if (object instanceof IProject)
472
			return PluginRegistry.findModel((IProject) object);
473
		if (object instanceof PersistablePluginObject) {
474
			return PluginRegistry.findModel(((PersistablePluginObject) object).getPluginID());
475
		}
476
		return null;
477
	}
478
479
	public static void handleAddRequired(ITargetPlugin[] plugins, boolean includeOptional) {
480
		if (plugins.length == 0)
481
			return;
482
483
		ArrayList list = new ArrayList(plugins.length);
484
		for (int i = 0; i < plugins.length; i++) {
485
			list.add(TargetPlatformHelper.getState().getBundle(plugins[i].getId(), null));
486
		}
487
		DependencyCalculator calculator = new DependencyCalculator(includeOptional);
488
		calculator.findDependencies(list.toArray());
489
		Collection dependencies = calculator.getBundleIDs();
490
491
		ITarget target = plugins[0].getTarget();
492
		ITargetModelFactory factory = target.getModel().getFactory();
493
		ITargetPlugin[] pluginsToAdd = new ITargetPlugin[dependencies.size()];
494
		int i = 0;
495
		Iterator iter = dependencies.iterator();
496
		while (iter.hasNext()) {
497
			String id = iter.next().toString();
498
			ITargetPlugin plugin = factory.createPlugin();
499
			plugin.setId(id);
500
			pluginsToAdd[i++] = plugin;
501
		}
502
		target.addPlugins(pluginsToAdd);
503
	}
504
505
	/* (non-Javadoc)
506
	 * @see org.eclipse.pde.internal.ui.editor.PDESection#modelChanged(org.eclipse.pde.core.IModelChangedEvent)
507
	 */
508
	public void modelChanged(IModelChangedEvent e) {
509
		if (e.getChangeType() == IModelChangedEvent.WORLD_CHANGED) {
510
			handleModelEventWorldChanged(e);
511
			return;
512
		}
513
		Object[] objects = e.getChangedObjects();
514
		if (e.getChangeType() == IModelChangedEvent.INSERT) {
515
			for (int i = 0; i < objects.length; i++) {
516
				if ((objects[i] instanceof ITargetPlugin && fLastTab == 0) || (objects[i] instanceof ITargetFeature && fLastTab == 1)) {
517
					fContentViewer.add(objects[i]);
518
				}
519
			}
520
		} else if (e.getChangeType() == IModelChangedEvent.REMOVE) {
521
522
			Table table = fContentViewer.getTable();
523
			int index = table.getSelectionIndex();
524
525
			for (int i = 0; i < objects.length; i++) {
526
				if ((objects[i] instanceof ITargetPlugin && fLastTab == 0) || (objects[i] instanceof ITargetFeature && fLastTab == 1)) {
527
					fContentViewer.remove(objects[i]);
528
				}
529
			}
530
531
			// Update Selection
532
533
			int count = table.getItemCount();
534
535
			if (count == 0) {
536
				// Nothing to select
537
			} else if (index < count) {
538
				table.setSelection(index);
539
			} else {
540
				table.setSelection(count - 1);
541
			}
542
543
		}
544
		if (e.getChangedProperty() == ITarget.P_ALL_PLUGINS) {
545
			refresh();
546
			fIncludeOptionalButton.setEnabled(!((Boolean) e.getNewValue()).booleanValue());
547
		}
548
	}
549
550
	/**
551
	 * @param event
552
	 */
553
	private void handleModelEventWorldChanged(IModelChangedEvent event) {
554
		// Reload input
555
		fContentViewer.setInput(PDECore.getDefault().getModelManager());
556
		// Perform the refresh
557
		refresh();
558
	}
559
560
	public boolean doGlobalAction(String actionId) {
561
		if (actionId.equals(ActionFactory.DELETE.getId())) {
562
			handleDelete();
563
			return true;
564
		}
565
		if (actionId.equals(ActionFactory.CUT.getId())) {
566
			handleDelete();
567
			return false;
568
		}
569
		if (actionId.equals(ActionFactory.PASTE.getId())) {
570
			doPaste();
571
			return true;
572
		}
573
		if (actionId.equals(ActionFactory.SELECT_ALL.getId())) {
574
			handleSelectAll();
575
			return true;
576
		}
577
		return false;
578
	}
579
580
	private void handleSelectAll() {
581
		fContentViewer.getTable().selectAll();
582
	}
583
584
	/* (non-Javadoc)
585
	 * @see org.eclipse.pde.internal.ui.editor.StructuredViewerSection#fillContextMenu(org.eclipse.jface.action.IMenuManager)
586
	 */
587
	protected void fillContextMenu(IMenuManager manager) {
588
		IStructuredSelection ssel = (IStructuredSelection) fContentViewer.getSelection();
589
		if (ssel == null)
590
			return;
591
592
		Action openAction = new Action(PDEUIMessages.ContentSection_open) {
593
			public void run() {
594
				handleDoubleClick((IStructuredSelection) fContentViewer.getSelection());
595
			}
596
		};
597
		openAction.setEnabled(isEditable() && ssel.size() == 1);
598
		manager.add(openAction);
599
600
		manager.add(new Separator());
601
602
		Action removeAction = new Action(PDEUIMessages.ContentSection_remove) {
603
			public void run() {
604
				handleDelete();
605
			}
606
		};
607
		removeAction.setEnabled(isEditable() && ssel.size() > 0);
608
		manager.add(removeAction);
609
610
		Action removeAll = new Action(PDEUIMessages.ContentSection_removeAll) {
611
			public void run() {
612
				handleRemoveAll();
613
			}
614
		};
615
		removeAll.setEnabled(isEditable());
616
		manager.add(removeAll);
617
618
		manager.add(new Separator());
619
620
		getPage().getPDEEditor().getContributor().contextMenuAboutToShow(manager);
621
	}
622
623
	protected void doPaste(Object target, Object[] objects) {
624
		for (int i = 0; i < objects.length; i++) {
625
			if (objects[i] instanceof ITargetPlugin && fLastTab == 0)
626
				getTarget().addPlugin((ITargetPlugin) objects[i]);
627
			else if (objects[i] instanceof ITargetFeature && fLastTab == 1)
628
				getTarget().addFeature((ITargetFeature) objects[i]);
629
		}
630
	}
631
632
	protected void selectionChanged(IStructuredSelection selection) {
633
		getPage().getPDEEditor().setSelection(selection);
634
	}
635
636
	public boolean setFormInput(Object input) {
637
		if (input instanceof ITargetPlugin) {
638
			if (fTabFolder.getSelectionIndex() != 0) {
639
				fTabFolder.setSelection(0);
640
				refresh();
641
			}
642
			fContentViewer.setSelection(new StructuredSelection(input), true);
643
			return true;
644
		} else if (input instanceof ITargetFeature) {
645
			if (fTabFolder.getSelectionIndex() != 1) {
646
				fTabFolder.setSelection(1);
647
				refresh();
648
			}
649
			fContentViewer.setSelection(new StructuredSelection(input), true);
650
			return true;
651
		}
652
		return super.setFormInput(input);
653
	}
654
655
	public void dispose() {
656
		ITargetModel model = getModel();
657
		if (model != null)
658
			model.removeModelChangedListener(this);
659
		if (fTabImages != null)
660
			for (int i = 0; i < fTabImages.length; i++)
661
				fTabImages[i].dispose();
662
		super.dispose();
663
	}
664
665
	protected boolean createCount() {
666
		return true;
667
	}
668
}
(-)src/org/eclipse/pde/internal/ui/editor/target/ContentPage.java (-56 / +51 lines)
Lines 1-56 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.editor.target;
11
package org.eclipse.pde.internal.ui.editor.target;
12
12
13
import org.eclipse.pde.internal.ui.*;
13
import org.eclipse.pde.internal.ui.*;
14
import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
14
import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
15
import org.eclipse.pde.internal.ui.editor.PDEFormPage;
15
import org.eclipse.swt.widgets.Composite;
16
import org.eclipse.swt.widgets.Composite;
16
import org.eclipse.ui.PlatformUI;
17
import org.eclipse.ui.PlatformUI;
17
import org.eclipse.ui.forms.IManagedForm;
18
import org.eclipse.ui.forms.IManagedForm;
18
import org.eclipse.ui.forms.editor.FormEditor;
19
import org.eclipse.ui.forms.editor.FormEditor;
19
import org.eclipse.ui.forms.editor.FormPage;
20
import org.eclipse.ui.forms.widgets.FormToolkit;
20
import org.eclipse.ui.forms.widgets.FormToolkit;
21
import org.eclipse.ui.forms.widgets.ScrolledForm;
21
import org.eclipse.ui.forms.widgets.ScrolledForm;
22
22
23
public class ContentPage extends PDEFormPage {
23
public class ContentPage extends FormPage {
24
24
25
	public static final String PAGE_ID = "content"; //$NON-NLS-1$
25
	public static final String PAGE_ID = "content"; //$NON-NLS-1$
26
26
27
	public ContentPage(FormEditor editor) {
27
	public ContentPage(FormEditor editor) {
28
		super(editor, PAGE_ID, PDEUIMessages.TargetContentPage_title);
28
		super(editor, PAGE_ID, PDEUIMessages.TargetContentPage_title);
29
	}
29
	}
30
30
31
	/* (non-Javadoc)
31
	/* (non-Javadoc)
32
	 * @see org.eclipse.pde.internal.ui.editor.PDEFormPage#createFormContent(org.eclipse.ui.forms.IManagedForm)
32
	 * @see org.eclipse.pde.internal.ui.editor.PDEFormPage#createFormContent(org.eclipse.ui.forms.IManagedForm)
33
	 */
33
	 */
34
	protected void createFormContent(IManagedForm managedForm) {
34
	protected void createFormContent(IManagedForm managedForm) {
35
		super.createFormContent(managedForm);
35
		super.createFormContent(managedForm);
36
		ScrolledForm form = managedForm.getForm();
36
		ScrolledForm form = managedForm.getForm();
37
		FormToolkit toolkit = managedForm.getToolkit();
37
		FormToolkit toolkit = managedForm.getToolkit();
38
		form.setText(PDEUIMessages.TargetContentPage_title);
38
		form.setText(PDEUIMessages.TargetContentPage_title);
39
		form.setImage(PDEPlugin.getDefault().getLabelProvider().get(PDEPluginImages.DESC_FEATURE_OBJ));
39
		form.setImage(PDEPlugin.getDefault().getLabelProvider().get(PDEPluginImages.DESC_FEATURE_OBJ));
40
		fillBody(managedForm, toolkit);
40
		fillBody(managedForm, toolkit);
41
		PlatformUI.getWorkbench().getHelpSystem().setHelp(form.getBody(), IHelpContextIds.TARGET_OVERVIEW_PAGE);
41
		PlatformUI.getWorkbench().getHelpSystem().setHelp(form.getBody(), IHelpContextIds.TARGET_OVERVIEW_PAGE);
42
42
43
	}
43
	}
44
44
45
	private void fillBody(IManagedForm managedForm, FormToolkit toolkit) {
45
	private void fillBody(IManagedForm managedForm, FormToolkit toolkit) {
46
		Composite body = managedForm.getForm().getBody();
46
		Composite body = managedForm.getForm().getBody();
47
		body.setLayout(FormLayoutFactory.createFormGridLayout(false, 1));
47
		body.setLayout(FormLayoutFactory.createFormGridLayout(false, 1));
48
48
//		managedForm.addPart(new ContentSection(this, body));
49
		managedForm.addPart(new ContentSection(this, body));
49
	}
50
	}
50
51
51
}
52
	protected String getHelpResource() {
53
		return "/org.eclipse.pde.doc.user/guide/tools/editors/target_definition_editor/content.htm"; //$NON-NLS-1$
54
	}
55
56
}
(-)src/org/eclipse/pde/internal/ui/editor/target/EnvironmentSection.java (-304 / +262 lines)
Lines 1-304 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2008 IBM Corporation and others.
2
 * Copyright (c) 2005, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.editor.target;
11
package org.eclipse.pde.internal.ui.editor.target;
12
12
13
import java.lang.reflect.InvocationTargetException;
13
import java.lang.reflect.InvocationTargetException;
14
import java.util.TreeSet;
14
import java.util.TreeSet;
15
import org.eclipse.core.runtime.IProgressMonitor;
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.core.runtime.Platform;
16
import org.eclipse.core.runtime.Platform;
17
import org.eclipse.jface.operation.IRunnableWithProgress;
17
import org.eclipse.jface.operation.IRunnableWithProgress;
18
import org.eclipse.pde.core.IModelChangedEvent;
18
import org.eclipse.pde.internal.core.target.provisional.ITargetDefinition;
19
import org.eclipse.pde.internal.core.itarget.*;
19
import org.eclipse.pde.internal.ui.PDEPlugin;
20
import org.eclipse.pde.internal.ui.PDEPlugin;
20
import org.eclipse.pde.internal.ui.PDEUIMessages;
21
import org.eclipse.pde.internal.ui.PDEUIMessages;
21
import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
22
import org.eclipse.pde.internal.ui.editor.*;
22
import org.eclipse.pde.internal.ui.parts.ComboPart;
23
import org.eclipse.pde.internal.ui.parts.ComboPart;
23
import org.eclipse.pde.internal.ui.util.LocaleUtil;
24
import org.eclipse.pde.internal.ui.util.LocaleUtil;
24
import org.eclipse.swt.SWT;
25
import org.eclipse.swt.SWT;
25
import org.eclipse.swt.custom.CCombo;
26
import org.eclipse.swt.custom.CCombo;
26
import org.eclipse.swt.events.*;
27
import org.eclipse.swt.events.*;
27
import org.eclipse.swt.layout.GridData;
28
import org.eclipse.swt.layout.GridData;
28
import org.eclipse.swt.layout.GridLayout;
29
import org.eclipse.swt.layout.GridLayout;
29
import org.eclipse.swt.widgets.*;
30
import org.eclipse.swt.widgets.*;
30
import org.eclipse.ui.PlatformUI;
31
import org.eclipse.ui.PlatformUI;
31
import org.eclipse.ui.forms.IFormColors;
32
import org.eclipse.ui.forms.IFormColors;
32
import org.eclipse.ui.forms.SectionPart;
33
import org.eclipse.ui.forms.widgets.FormToolkit;
33
import org.eclipse.ui.forms.editor.FormPage;
34
import org.eclipse.ui.forms.widgets.Section;
34
import org.eclipse.ui.forms.widgets.*;
35
35
36
public class EnvironmentSection extends PDESection {
36
public class EnvironmentSection extends SectionPart {
37
37
38
	private ComboPart fOSCombo;
38
	private ComboPart fOSCombo;
39
	private ComboPart fWSCombo;
39
	private ComboPart fWSCombo;
40
	private ComboPart fNLCombo;
40
	private ComboPart fNLCombo;
41
	private ComboPart fArchCombo;
41
	private ComboPart fArchCombo;
42
42
43
	private TreeSet fNLChoices;
43
	private TreeSet fNLChoices;
44
	private TreeSet fOSChoices;
44
	private TreeSet fOSChoices;
45
	private TreeSet fWSChoices;
45
	private TreeSet fWSChoices;
46
	private TreeSet fArchChoices;
46
	private TreeSet fArchChoices;
47
	private boolean LOCALES_INITIALIZED = false;
47
	private boolean LOCALES_INITIALIZED = false;
48
48
49
	public EnvironmentSection(PDEFormPage page, Composite parent) {
49
	private TargetEditor fEditor;
50
		super(page, parent, Section.DESCRIPTION);
50
51
		createClient(getSection(), page.getEditor().getToolkit());
51
	public EnvironmentSection(FormPage page, Composite parent) {
52
	}
52
		super(parent, page.getManagedForm().getToolkit(), Section.DESCRIPTION | ExpandableComposite.TITLE_BAR);
53
53
		fEditor = (TargetEditor) page.getEditor();
54
	protected void createClient(Section section, FormToolkit toolkit) {
54
		createClient(getSection(), page.getEditor().getToolkit());
55
		section.setLayout(FormLayoutFactory.createClearGridLayout(false, 1));
55
	}
56
		section.setText(PDEUIMessages.EnvironmentSection_title);
56
57
		section.setDescription(PDEUIMessages.EnvironmentSection_description);
57
	private ITargetDefinition getTarget() {
58
		GridData data = new GridData(GridData.FILL_HORIZONTAL);
58
		return fEditor.getTarget();
59
		data.verticalAlignment = SWT.TOP;
59
	}
60
		data.horizontalSpan = 2;
60
61
		section.setLayoutData(data);
61
	protected void createClient(Section section, FormToolkit toolkit) {
62
62
		section.setLayout(FormLayoutFactory.createClearGridLayout(false, 1));
63
		Composite client = toolkit.createComposite(section);
63
		section.setText(PDEUIMessages.EnvironmentSection_title);
64
		client.setLayout(FormLayoutFactory.createSectionClientGridLayout(true, 2));
64
		section.setDescription(PDEUIMessages.EnvironmentSection_description);
65
		client.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
65
		GridData data = new GridData(GridData.FILL_HORIZONTAL);
66
66
		data.verticalAlignment = SWT.TOP;
67
		Composite left = toolkit.createComposite(client);
67
		data.horizontalSpan = 2;
68
		left.setLayout(new GridLayout(2, false));
68
		section.setLayoutData(data);
69
		GridLayout layout = FormLayoutFactory.createClearGridLayout(false, 2);
69
70
		layout.horizontalSpacing = layout.verticalSpacing = 5;
70
		Composite client = toolkit.createComposite(section);
71
		left.setLayout(layout);
71
		client.setLayout(FormLayoutFactory.createSectionClientGridLayout(true, 2));
72
		left.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
72
		client.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
73
73
74
		IEnvironmentInfo orgEnv = getEnvironment();
74
		Composite left = toolkit.createComposite(client);
75
		initializeChoices(orgEnv);
75
		left.setLayout(new GridLayout(2, false));
76
76
		GridLayout layout = FormLayoutFactory.createClearGridLayout(false, 2);
77
		Label label = toolkit.createLabel(left, PDEUIMessages.EnvironmentSection_operationSystem);
77
		layout.horizontalSpacing = layout.verticalSpacing = 5;
78
		label.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
78
		left.setLayout(layout);
79
79
		left.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
80
		fOSCombo = new ComboPart();
80
81
		fOSCombo.createControl(left, toolkit, SWT.SINGLE | SWT.BORDER);
81
		initializeChoices();
82
		fOSCombo.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
82
83
		fOSCombo.setItems((String[]) fOSChoices.toArray(new String[fOSChoices.size()]));
83
		Label label = toolkit.createLabel(left, PDEUIMessages.EnvironmentSection_operationSystem);
84
84
		label.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
85
		label = toolkit.createLabel(left, PDEUIMessages.EnvironmentSection_windowingSystem);
85
86
		label.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
86
		fOSCombo = new ComboPart();
87
87
		fOSCombo.createControl(left, toolkit, SWT.SINGLE | SWT.BORDER);
88
		fWSCombo = new ComboPart();
88
		fOSCombo.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
89
		fWSCombo.createControl(left, toolkit, SWT.SINGLE | SWT.BORDER);
89
		fOSCombo.setItems((String[]) fOSChoices.toArray(new String[fOSChoices.size()]));
90
		fWSCombo.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
90
91
		fWSCombo.setItems((String[]) fWSChoices.toArray(new String[fWSChoices.size()]));
91
		label = toolkit.createLabel(left, PDEUIMessages.EnvironmentSection_windowingSystem);
92
92
		label.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
93
		Composite right = toolkit.createComposite(client);
93
94
		layout = FormLayoutFactory.createClearGridLayout(false, 2);
94
		fWSCombo = new ComboPart();
95
		layout.verticalSpacing = layout.horizontalSpacing = 5;
95
		fWSCombo.createControl(left, toolkit, SWT.SINGLE | SWT.BORDER);
96
		right.setLayout(layout);
96
		fWSCombo.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
97
		right.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
97
		fWSCombo.setItems((String[]) fWSChoices.toArray(new String[fWSChoices.size()]));
98
98
99
		label = toolkit.createLabel(right, PDEUIMessages.EnvironmentSection_architecture);
99
		Composite right = toolkit.createComposite(client);
100
		label.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
100
		layout = FormLayoutFactory.createClearGridLayout(false, 2);
101
101
		layout.verticalSpacing = layout.horizontalSpacing = 5;
102
		fArchCombo = new ComboPart();
102
		right.setLayout(layout);
103
		fArchCombo.createControl(right, toolkit, SWT.SINGLE | SWT.BORDER);
103
		right.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
104
		fArchCombo.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
104
105
		fArchCombo.setItems((String[]) fArchChoices.toArray(new String[fArchChoices.size()]));
105
		label = toolkit.createLabel(right, PDEUIMessages.EnvironmentSection_architecture);
106
106
		label.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
107
		label = toolkit.createLabel(right, PDEUIMessages.EnvironmentSection_locale);
107
108
		label.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
108
		fArchCombo = new ComboPart();
109
109
		fArchCombo.createControl(right, toolkit, SWT.SINGLE | SWT.BORDER);
110
		fNLCombo = new ComboPart();
110
		fArchCombo.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
111
		fNLCombo.createControl(right, toolkit, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL);
111
		fArchCombo.setItems((String[]) fArchChoices.toArray(new String[fArchChoices.size()]));
112
		fNLCombo.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
112
113
		fNLCombo.setItems((String[]) fNLChoices.toArray(new String[fNLChoices.size()]));
113
		label = toolkit.createLabel(right, PDEUIMessages.EnvironmentSection_locale);
114
114
		label.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
115
		refresh();
115
116
116
		fNLCombo = new ComboPart();
117
		fOSCombo.addModifyListener(new ModifyListener() {
117
		fNLCombo.createControl(right, toolkit, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL);
118
			public void modifyText(ModifyEvent e) {
118
		fNLCombo.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
119
				getEnvironment().setOS(getText(fOSCombo));
119
		fNLCombo.setItems((String[]) fNLChoices.toArray(new String[fNLChoices.size()]));
120
			}
120
121
		});
121
		refresh();
122
		fWSCombo.addModifyListener(new ModifyListener() {
122
123
			public void modifyText(ModifyEvent e) {
123
		fOSCombo.addModifyListener(new ModifyListener() {
124
				getEnvironment().setWS(getText(fWSCombo));
124
			public void modifyText(ModifyEvent e) {
125
			}
125
				markDirty();
126
		});
126
				getTarget().setOS(getText(fOSCombo));
127
		fArchCombo.addModifyListener(new ModifyListener() {
127
			}
128
			public void modifyText(ModifyEvent e) {
128
		});
129
				getEnvironment().setArch(getText(fArchCombo));
129
		fWSCombo.addModifyListener(new ModifyListener() {
130
			}
130
			public void modifyText(ModifyEvent e) {
131
		});
131
				markDirty();
132
		fNLCombo.getControl().addFocusListener(new FocusAdapter() {
132
				getTarget().setWS(getText(fWSCombo));
133
			public void focusGained(FocusEvent event) {
133
			}
134
				// if we haven't gotten all the values for the NL's, display a busy cursor to the user while we find them.
134
		});
135
				if (!LOCALES_INITIALIZED) {
135
		fArchCombo.addModifyListener(new ModifyListener() {
136
					try {
136
			public void modifyText(ModifyEvent e) {
137
						PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() {
137
				markDirty();
138
							public void run(IProgressMonitor monitor) {
138
				getTarget().setArch(getText(fArchCombo));
139
								initializeAllLocales();
139
			}
140
								LOCALES_INITIALIZED = true;
140
		});
141
							}
141
		fNLCombo.getControl().addFocusListener(new FocusAdapter() {
142
						});
142
			public void focusGained(FocusEvent event) {
143
					} catch (InvocationTargetException e) {
143
				// if we haven't gotten all the values for the NL's, display a busy cursor to the user while we find them.
144
						PDEPlugin.log(e);
144
				if (!LOCALES_INITIALIZED) {
145
					} catch (InterruptedException e) {
145
					try {
146
						PDEPlugin.log(e);
146
						PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() {
147
					}
147
							public void run(IProgressMonitor monitor) {
148
				}
148
								initializeAllLocales();
149
149
								LOCALES_INITIALIZED = true;
150
				// first time through, we should have a max item count of 1.
150
							}
151
				// On the first time through, we need to set the new values, and also attach the listener
151
						});
152
				// If we attached the listener initially, when we call setItems(..), it would make the editor dirty (when the user didn't change anything)
152
					} catch (InvocationTargetException e) {
153
				if (fNLCombo.getItemCount() < 3) {
153
						PDEPlugin.log(e);
154
					String current = fNLCombo.getSelection();
154
					} catch (InterruptedException e) {
155
					if (!fNLCombo.getControl().isDisposed()) {
155
						PDEPlugin.log(e);
156
						fNLCombo.setItems((String[]) fNLChoices.toArray(new String[fNLChoices.size()]));
156
					}
157
						fNLCombo.setText(current);
157
				}
158
					}
158
159
159
				// first time through, we should have a max item count of 1.
160
					fNLCombo.addModifyListener(new ModifyListener() {
160
				// On the first time through, we need to set the new values, and also attach the listener
161
						public void modifyText(ModifyEvent e) {
161
				// If we attached the listener initially, when we call setItems(..), it would make the editor dirty (when the user didn't change anything)
162
							String value = getText(fNLCombo);
162
				if (fNLCombo.getItemCount() < 3) {
163
							int index = value.indexOf("-"); //$NON-NLS-1$
163
					String current = fNLCombo.getSelection();
164
							if (index > 0)
164
					if (!fNLCombo.getControl().isDisposed()) {
165
								value = value.substring(0, index);
165
						fNLCombo.setItems((String[]) fNLChoices.toArray(new String[fNLChoices.size()]));
166
							getEnvironment().setNL(value.trim());
166
						fNLCombo.setText(current);
167
						}
167
					}
168
					});
168
169
				}
169
					fNLCombo.addModifyListener(new ModifyListener() {
170
170
						public void modifyText(ModifyEvent e) {
171
			}
171
							String value = getText(fNLCombo);
172
		});
172
							int index = value.indexOf("-"); //$NON-NLS-1$
173
173
							if (index > 0)
174
		toolkit.paintBordersFor(client);
174
								value = value.substring(0, index);
175
		section.setClient(client);
175
							getTarget().setNL(value.trim());
176
176
							markDirty();
177
		// Register to be notified when the model changes
177
						}
178
		getModel().addModelChangedListener(this);
178
					});
179
	}
179
				}
180
180
181
	/* (non-Javadoc)
181
			}
182
	 * @see org.eclipse.pde.internal.ui.editor.PDESection#modelChanged(org.eclipse.pde.core.IModelChangedEvent)
182
		});
183
	 */
183
184
	public void modelChanged(IModelChangedEvent e) {
184
		toolkit.paintBordersFor(client);
185
		// No need to call super, handling world changed event here
185
		section.setClient(client);
186
		if (e.getChangeType() == IModelChangedEvent.WORLD_CHANGED) {
186
	}
187
			handleModelEventWorldChanged(e);
187
188
		}
188
	private void initializeChoices() {
189
	}
189
		ITargetDefinition target = getTarget();
190
190
		fOSChoices = new TreeSet();
191
	/**
191
		String[] os = Platform.knownOSValues();
192
	 * @param event
192
		for (int i = 0; i < os.length; i++)
193
	 */
193
			fOSChoices.add(os[i]);
194
	private void handleModelEventWorldChanged(IModelChangedEvent event) {
194
		fOSChoices.add(""); //$NON-NLS-1$
195
		// Perform the refresh
195
		String fileValue = target.getOS();
196
		refresh();
196
		if (fileValue != null)
197
	}
197
			fOSChoices.add(fileValue);
198
198
199
	/* (non-Javadoc)
199
		fWSChoices = new TreeSet();
200
	 * @see org.eclipse.ui.forms.AbstractFormPart#dispose()
200
		String[] ws = Platform.knownWSValues();
201
	 */
201
		for (int i = 0; i < ws.length; i++)
202
	public void dispose() {
202
			fWSChoices.add(ws[i]);
203
		ITargetModel model = getModel();
203
		fWSChoices.add(""); //$NON-NLS-1$
204
		if (model != null) {
204
		fileValue = target.getWS();
205
			model.removeModelChangedListener(this);
205
		if (fileValue != null)
206
		}
206
			fWSChoices.add(fileValue);
207
		super.dispose();
207
208
	}
208
		fArchChoices = new TreeSet();
209
209
		String[] arch = Platform.knownOSArchValues();
210
	private void initializeChoices(IEnvironmentInfo orgEnv) {
210
		for (int i = 0; i < arch.length; i++)
211
		fOSChoices = new TreeSet();
211
			fArchChoices.add(arch[i]);
212
		String[] os = Platform.knownOSValues();
212
		fArchChoices.add(""); //$NON-NLS-1$
213
		for (int i = 0; i < os.length; i++)
213
		fileValue = target.getArch();
214
			fOSChoices.add(os[i]);
214
		if (fileValue != null)
215
		fOSChoices.add(""); //$NON-NLS-1$
215
			fArchChoices.add(fileValue);
216
		String fileValue = orgEnv.getOS();
216
217
		if (fileValue != null)
217
		fNLChoices = new TreeSet();
218
			fOSChoices.add(fileValue);
218
		fNLChoices.add(""); //$NON-NLS-1$
219
219
	}
220
		fWSChoices = new TreeSet();
220
221
		String[] ws = Platform.knownWSValues();
221
	private void initializeAllLocales() {
222
		for (int i = 0; i < ws.length; i++)
222
		String[] nl = LocaleUtil.getLocales();
223
			fWSChoices.add(ws[i]);
223
		for (int i = 0; i < nl.length; i++)
224
		fWSChoices.add(""); //$NON-NLS-1$
224
			fNLChoices.add(nl[i]);
225
		fileValue = orgEnv.getWS();
225
		String fileValue = getTarget().getNL();
226
		if (fileValue != null)
226
		if (fileValue != null)
227
			fWSChoices.add(fileValue);
227
			fNLChoices.add(LocaleUtil.expandLocaleName(fileValue));
228
228
		LOCALES_INITIALIZED = true;
229
		fArchChoices = new TreeSet();
229
	}
230
		String[] arch = Platform.knownOSArchValues();
230
231
		for (int i = 0; i < arch.length; i++)
231
	private String getText(ComboPart combo) {
232
			fArchChoices.add(arch[i]);
232
		Control control = combo.getControl();
233
		fArchChoices.add(""); //$NON-NLS-1$
233
		if (control instanceof Combo)
234
		fileValue = orgEnv.getArch();
234
			return ((Combo) control).getText();
235
		if (fileValue != null)
235
		return ((CCombo) control).getText();
236
			fArchChoices.add(fileValue);
236
	}
237
237
238
		fNLChoices = new TreeSet();
238
	public void refresh() {
239
		fNLChoices.add(""); //$NON-NLS-1$
239
		ITargetDefinition target = getTarget();
240
	}
240
		String presetValue = (target.getOS() == null) ? "" : target.getOS(); //$NON-NLS-1$
241
241
		fOSCombo.setText(presetValue);
242
	private void initializeAllLocales() {
242
		presetValue = (target.getWS() == null) ? "" : target.getWS(); //$NON-NLS-1$
243
		String[] nl = LocaleUtil.getLocales();
243
		fWSCombo.setText(presetValue);
244
		for (int i = 0; i < nl.length; i++)
244
		presetValue = (target.getArch() == null) ? "" : target.getArch(); //$NON-NLS-1$
245
			fNLChoices.add(nl[i]);
245
		fArchCombo.setText(presetValue);
246
		String fileValue = getEnvironment().getNL();
246
		presetValue = (target.getNL() == null) ? "" : LocaleUtil.expandLocaleName(target.getNL()); //$NON-NLS-1$
247
		if (fileValue != null)
247
		fNLCombo.setText(presetValue);
248
			fNLChoices.add(LocaleUtil.expandLocaleName(fileValue));
248
		super.refresh();
249
		LOCALES_INITIALIZED = true;
249
	}
250
	}
250
251
251
	protected void updateChoices() {
252
	private String getText(ComboPart combo) {
252
		if (LOCALES_INITIALIZED)
253
		Control control = combo.getControl();
253
			return;
254
		if (control instanceof Combo)
254
		// kick off thread in background to find the NL values
255
			return ((Combo) control).getText();
255
		new Thread(new Runnable() {
256
		return ((CCombo) control).getText();
256
			public void run() {
257
	}
257
				initializeAllLocales();
258
258
			}
259
	private IEnvironmentInfo getEnvironment() {
259
		}).start();
260
		IEnvironmentInfo info = getTarget().getEnvironment();
260
	}
261
		if (info == null) {
261
262
			info = getModel().getFactory().createEnvironment();
262
}
263
			getTarget().setEnvironment(info);
264
		}
265
		return info;
266
	}
267
268
	private ITarget getTarget() {
269
		return getModel().getTarget();
270
	}
271
272
	private ITargetModel getModel() {
273
		return (ITargetModel) getPage().getPDEEditor().getAggregateModel();
274
	}
275
276
	public void refresh() {
277
		IEnvironmentInfo orgEnv = getEnvironment();
278
		String presetValue = (orgEnv.getOS() == null) ? "" : orgEnv.getOS(); //$NON-NLS-1$
279
		fOSCombo.setText(presetValue);
280
		presetValue = (orgEnv.getWS() == null) ? "" : orgEnv.getWS(); //$NON-NLS-1$
281
		fWSCombo.setText(presetValue);
282
		presetValue = (orgEnv.getArch() == null) ? "" : orgEnv.getArch(); //$NON-NLS-1$
283
		fArchCombo.setText(presetValue);
284
		presetValue = (orgEnv.getNL() == null) ? "" : LocaleUtil.expandLocaleName(orgEnv.getNL()); //$NON-NLS-1$
285
		fNLCombo.setText(presetValue);
286
287
		super.refresh();
288
	}
289
290
	protected void updateChoices() {
291
		if (LOCALES_INITIALIZED)
292
			return;
293
		// prevent NPE Mike found, which we can't reproduce.  Somehow we call initializeAllLocales before the ITargetModel exists.
294
		if (getModel() == null)
295
			return;
296
		// kick off thread in backgroud to find the NL values
297
		new Thread(new Runnable() {
298
			public void run() {
299
				initializeAllLocales();
300
			}
301
		}).start();
302
	}
303
304
}
(-)src/org/eclipse/pde/internal/ui/editor/target/TargetInputContextManager.java (-35 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.editor.target;
12
13
import org.eclipse.pde.core.IBaseModel;
14
import org.eclipse.pde.internal.ui.editor.PDEFormEditor;
15
import org.eclipse.pde.internal.ui.editor.context.InputContext;
16
import org.eclipse.pde.internal.ui.editor.context.InputContextManager;
17
18
public class TargetInputContextManager extends InputContextManager {
19
20
	/**
21
	 * @param editor
22
	 */
23
	public TargetInputContextManager(PDEFormEditor editor) {
24
		super(editor);
25
	}
26
27
	/* (non-Javadoc)
28
	 * @see org.eclipse.pde.internal.ui.editor.context.InputContextManager#getAggregateModel()
29
	 */
30
	public IBaseModel getAggregateModel() {
31
		InputContext context = findContext(TargetInputContext.CONTEXT_ID);
32
		return (context != null) ? context.getModel() : null;
33
	}
34
35
}
(-)src/org/eclipse/pde/internal/ui/editor/target/TargetEditorContributor.java (-4 / +22 lines)
Lines 10-21 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.editor.target;
11
package org.eclipse.pde.internal.ui.editor.target;
12
12
13
import org.eclipse.pde.internal.ui.editor.PDEFormEditorContributor;
13
import org.eclipse.jface.action.Action;
14
import org.eclipse.ui.IEditorPart;
15
import org.eclipse.ui.actions.ActionFactory;
16
import org.eclipse.ui.part.MultiPageEditorActionBarContributor;
17
import org.eclipse.ui.texteditor.IUpdate;
14
18
15
public class TargetEditorContributor extends PDEFormEditorContributor {
19
public class TargetEditorContributor extends MultiPageEditorActionBarContributor {
16
20
17
	public TargetEditorContributor() {
21
	private TargetEditor fEditor;
18
		super("Product"); //$NON-NLS-1$
22
23
	class RevertAction extends Action implements IUpdate {
24
		public void run() {
25
			if (fEditor != null)
26
				fEditor.doRevert();
27
		}
28
29
		public void update() {
30
			setEnabled(fEditor != null ? fEditor.isDirty() : false);
31
		}
19
	}
32
	}
20
33
34
	public void setActivePage(IEditorPart activeEditor) {
35
		fEditor = (TargetEditor) activeEditor;
36
		getActionBars().setGlobalActionHandler(ActionFactory.REVERT.getId(), new RevertAction());
37
		getActionBars().updateActionBars();
38
	}
21
}
39
}
(-)src/org/eclipse/pde/internal/ui/editor/target/EnvironmentPage.java (-62 / +52 lines)
Lines 1-62 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.editor.target;
11
package org.eclipse.pde.internal.ui.editor.target;
12
12
13
import org.eclipse.pde.internal.ui.*;
13
import org.eclipse.pde.internal.ui.*;
14
import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
14
import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
15
import org.eclipse.pde.internal.ui.editor.PDEFormPage;
15
import org.eclipse.swt.widgets.Composite;
16
import org.eclipse.swt.widgets.Composite;
16
import org.eclipse.ui.PlatformUI;
17
import org.eclipse.ui.PlatformUI;
17
import org.eclipse.ui.forms.IManagedForm;
18
import org.eclipse.ui.forms.IManagedForm;
18
import org.eclipse.ui.forms.editor.FormEditor;
19
import org.eclipse.ui.forms.editor.FormEditor;
19
import org.eclipse.ui.forms.editor.FormPage;
20
import org.eclipse.ui.forms.widgets.FormToolkit;
20
import org.eclipse.ui.forms.widgets.FormToolkit;
21
import org.eclipse.ui.forms.widgets.ScrolledForm;
21
import org.eclipse.ui.forms.widgets.ScrolledForm;
22
22
23
public class EnvironmentPage extends PDEFormPage {
23
public class EnvironmentPage extends FormPage {
24
24
25
	private EnvironmentSection fEnvSection;
25
	public static final String PAGE_ID = "environment"; //$NON-NLS-1$
26
26
27
	public static final String PAGE_ID = "environment"; //$NON-NLS-1$
27
	public EnvironmentPage(FormEditor editor) {
28
28
		super(editor, PAGE_ID, PDEUIMessages.EnvironmentPage_title);
29
	public EnvironmentPage(FormEditor editor) {
29
	}
30
		super(editor, PAGE_ID, PDEUIMessages.EnvironmentPage_title);
30
31
	}
31
	protected void createFormContent(IManagedForm managedForm) {
32
32
		super.createFormContent(managedForm);
33
	protected void createFormContent(IManagedForm managedForm) {
33
		ScrolledForm form = managedForm.getForm();
34
		super.createFormContent(managedForm);
34
		form.setText(PDEUIMessages.EnvironmentPage_title);
35
		ScrolledForm form = managedForm.getForm();
35
		form.setImage(PDEPlugin.getDefault().getLabelProvider().get(PDEPluginImages.DESC_TARGET_ENVIRONMENT));
36
		form.setText(PDEUIMessages.EnvironmentPage_title);
36
		FormToolkit toolkit = managedForm.getToolkit();
37
		form.setImage(PDEPlugin.getDefault().getLabelProvider().get(PDEPluginImages.DESC_TARGET_ENVIRONMENT));
37
		fillBody(managedForm, toolkit);
38
		FormToolkit toolkit = managedForm.getToolkit();
38
		toolkit.decorateFormHeading(form.getForm());
39
		fillBody(managedForm, toolkit);
39
		PlatformUI.getWorkbench().getHelpSystem().setHelp(form.getBody(), IHelpContextIds.ENVIRONMENT_PAGE);
40
40
	}
41
		PlatformUI.getWorkbench().getHelpSystem().setHelp(form.getBody(), IHelpContextIds.ENVIRONMENT_PAGE);
41
42
	}
42
	private void fillBody(IManagedForm managedForm, FormToolkit toolkit) {
43
43
		Composite body = managedForm.getForm().getBody();
44
	private void fillBody(IManagedForm managedForm, FormToolkit toolkit) {
44
		body.setLayout(FormLayoutFactory.createFormGridLayout(false, 2));
45
		Composite body = managedForm.getForm().getBody();
45
46
		body.setLayout(FormLayoutFactory.createFormGridLayout(false, 2));
46
		managedForm.addPart(new EnvironmentSection(this, body));
47
47
		managedForm.addPart(new JRESection(this, body));
48
		managedForm.addPart(fEnvSection = new EnvironmentSection(this, body));
48
		managedForm.addPart(new ArgumentsSection(this, body));
49
		managedForm.addPart(new JRESection(this, body));
49
		managedForm.addPart(new ImplicitDependenciesSection(this, body));
50
		managedForm.addPart(new ArgumentsSection(this, body));
50
	}
51
		managedForm.addPart(new ImplicitDependenciesSection(this, body));
51
52
	}
52
}
53
54
	protected void updateChoices() {
55
		fEnvSection.updateChoices();
56
	}
57
58
	protected String getHelpResource() {
59
		return "/org.eclipse.pde.doc.user/guide/tools/editors/target_definition_editor/environment.htm"; //$NON-NLS-1$
60
	}
61
62
}
(-)src/org/eclipse/pde/internal/ui/editor/target/ImplicitDependenciesSection.java (-272 / +253 lines)
Lines 1-272 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.editor.target;
11
package org.eclipse.pde.internal.ui.editor.target;
12
12
13
import java.util.*;
13
import org.eclipse.pde.internal.ui.editor.target.TargetEditor;
14
import org.eclipse.jface.viewers.*;
14
15
import org.eclipse.jface.window.Window;
15
import org.eclipse.jface.viewers.*;
16
import org.eclipse.osgi.service.resolver.BundleDescription;
16
import org.eclipse.pde.internal.core.itarget.ITargetPlugin;
17
import org.eclipse.pde.core.IModelChangedEvent;
17
import org.eclipse.pde.internal.core.target.provisional.ITargetDefinition;
18
import org.eclipse.pde.core.plugin.IPluginModelBase;
18
import org.eclipse.pde.internal.ui.PDEPlugin;
19
import org.eclipse.pde.core.plugin.PluginRegistry;
19
import org.eclipse.pde.internal.ui.PDEUIMessages;
20
import org.eclipse.pde.internal.core.itarget.*;
20
import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
21
import org.eclipse.pde.internal.ui.PDEPlugin;
21
import org.eclipse.pde.internal.ui.editor.plugin.ManifestEditor;
22
import org.eclipse.pde.internal.ui.PDEUIMessages;
22
import org.eclipse.pde.internal.ui.elements.DefaultTableProvider;
23
import org.eclipse.pde.internal.ui.editor.*;
23
import org.eclipse.swt.SWT;
24
import org.eclipse.pde.internal.ui.editor.plugin.ManifestEditor;
24
import org.eclipse.swt.events.*;
25
import org.eclipse.pde.internal.ui.elements.DefaultTableProvider;
25
import org.eclipse.swt.layout.GridData;
26
import org.eclipse.pde.internal.ui.parts.TablePart;
26
import org.eclipse.swt.layout.GridLayout;
27
import org.eclipse.swt.SWT;
27
import org.eclipse.swt.widgets.*;
28
import org.eclipse.swt.layout.GridData;
28
import org.eclipse.ui.forms.IFormColors;
29
import org.eclipse.swt.widgets.Composite;
29
import org.eclipse.ui.forms.SectionPart;
30
import org.eclipse.ui.actions.ActionFactory;
30
import org.eclipse.ui.forms.editor.FormPage;
31
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
31
import org.eclipse.ui.forms.widgets.*;
32
import org.eclipse.ui.forms.widgets.FormToolkit;
32
33
import org.eclipse.ui.forms.widgets.Section;
33
public class ImplicitDependenciesSection extends SectionPart {
34
34
35
public class ImplicitDependenciesSection extends TableSection {
35
	private TableViewer fViewer;
36
36
	private TargetEditor fEditor;
37
	private TableViewer fViewer;
37
	private Button fAdd;
38
	private static final int ADD_INDEX = 0;
38
	private Button fRemove;
39
	private static final int REMOVE_INDEX = 1;
39
	private Button fRemoveAll;
40
	private static final int REMOVE_ALL_INDEX = 2;
40
	private Label fCount;
41
41
42
	public ImplicitDependenciesSection(PDEFormPage page, Composite parent) {
42
	public ImplicitDependenciesSection(FormPage page, Composite parent) {
43
		super(page, parent, Section.DESCRIPTION, new String[] {PDEUIMessages.ImplicitDependenicesSection_Add, PDEUIMessages.ImplicitDependenicesSection_Remove, PDEUIMessages.ImplicitDependenicesSection_RemoveAll});
43
		super(parent, page.getManagedForm().getToolkit(), Section.DESCRIPTION | ExpandableComposite.TITLE_BAR);
44
	}
44
		fEditor = (TargetEditor) page.getEditor();
45
45
		createClient(getSection(), page.getEditor().getToolkit());
46
	protected void createClient(Section section, FormToolkit toolkit) {
46
	}
47
		section.setLayout(FormLayoutFactory.createClearGridLayout(false, 1));
47
48
		section.setText(PDEUIMessages.ImplicitDependenicesSection_Title);
48
	private ITargetDefinition getTarget() {
49
		section.setDescription(PDEUIMessages.TargetImplicitPluginsTab_desc);
49
		return fEditor.getTarget();
50
		Composite container = toolkit.createComposite(section);
50
	}
51
		container.setLayout(FormLayoutFactory.createSectionClientGridLayout(false, 2));
51
52
		container.setLayoutData(new GridData(GridData.FILL_BOTH));
52
	protected void createClient(Section section, FormToolkit toolkit) {
53
		createViewerPartControl(container, SWT.MULTI, 2, toolkit);
53
		section.setLayout(FormLayoutFactory.createClearGridLayout(false, 1));
54
		fViewer = getTablePart().getTableViewer();
54
		section.setText(PDEUIMessages.ImplicitDependenicesSection_Title);
55
		fViewer.setContentProvider(new DefaultTableProvider() {
55
		section.setDescription(PDEUIMessages.TargetImplicitPluginsTab_desc);
56
			public Object[] getElements(Object inputElement) {
56
		Composite container = toolkit.createComposite(section);
57
				return getImplicitPluginsInfo().getPlugins();
57
		container.setLayout(FormLayoutFactory.createSectionClientGridLayout(false, 2));
58
			}
58
		container.setLayoutData(new GridData(GridData.FILL_BOTH));
59
		});
59
60
		fViewer.setLabelProvider(PDEPlugin.getDefault().getLabelProvider());
60
		createTableViewer(toolkit, container);
61
		fViewer.setComparator(new ViewerComparator() {
61
62
			public int compare(Viewer viewer, Object e1, Object e2) {
62
		Composite buttonComp = toolkit.createComposite(container);
63
				ITargetPlugin p1 = (ITargetPlugin) e1;
63
		GridLayout layout = new GridLayout();
64
				ITargetPlugin p2 = (ITargetPlugin) e2;
64
		layout.marginWidth = layout.marginHeight = 0;
65
				return super.compare(viewer, p1.getId(), p2.getId());
65
		buttonComp.setLayout(layout);
66
			}
66
		buttonComp.setLayoutData(new GridData(GridData.FILL_VERTICAL));
67
		});
67
68
		fViewer.setInput(getTarget());
68
		createButtons(toolkit, buttonComp);
69
		fViewer.addSelectionChangedListener(new ISelectionChangedListener() {
69
70
			public void selectionChanged(SelectionChangedEvent event) {
70
		toolkit.paintBordersFor(container);
71
				updateButtons();
71
		section.setClient(container);
72
			}
72
		GridData gd = new GridData(GridData.FILL_BOTH);
73
		});
73
		section.setLayoutData(gd);
74
74
		updateButtons();
75
		toolkit.paintBordersFor(container);
75
	}
76
		section.setClient(container);
76
77
		GridData gd = new GridData(GridData.FILL_BOTH);
77
	private void createTableViewer(FormToolkit toolkit, Composite parent) {
78
		section.setLayoutData(gd);
78
		Table table = toolkit.createTable(parent, SWT.H_SCROLL | SWT.V_SCROLL);
79
		updateButtons();
79
		table.setLayoutData(new GridData(GridData.FILL_BOTH));
80
		getModel().addModelChangedListener(this);
80
		fViewer = new TableViewer(table);
81
	}
81
		fViewer.setContentProvider(new DefaultTableProvider() {
82
82
			public Object[] getElements(Object inputElement) {
83
	public boolean doGlobalAction(String actionId) {
83
//				return getTarget().getImplicitPlugins();
84
		if (actionId.equals(ActionFactory.DELETE.getId())) {
84
				return null;
85
			handleRemove();
85
			}
86
			return true;
86
		});
87
		}
87
		fViewer.setLabelProvider(PDEPlugin.getDefault().getLabelProvider());
88
		if (actionId.equals(ActionFactory.CUT.getId())) {
88
//		fViewer.setComparator(new ViewerComparator() {
89
			// delete here and let the editor transfer
89
		// TODO Compare bundle infos?
90
			// the selection to the clipboard
90
//			public int compare(Viewer viewer, Object e1, Object e2) {
91
			handleRemove();
91
//				 p1 = (ITargetPlugin) e1;
92
			return false;
92
//				ITargetPlugin p2 = (ITargetPlugin) e2;
93
		}
93
//				return super.compare(viewer, p1.getId(), p2.getId());
94
		if (actionId.equals(ActionFactory.PASTE.getId())) {
94
//			}
95
			doPaste();
95
//		});
96
			return true;
96
		// TODO Input might be the list of implicit dependencies
97
		}
97
//		fViewer.setInput(getTarget());
98
		return false;
98
		fViewer.addSelectionChangedListener(new ISelectionChangedListener() {
99
	}
99
			public void selectionChanged(SelectionChangedEvent event) {
100
100
				updateButtons();
101
	private void updateButtons() {
101
			}
102
		TablePart part = getTablePart();
102
		});
103
		boolean empty = fViewer.getSelection().isEmpty();
103
		fViewer.addDoubleClickListener(new IDoubleClickListener() {
104
		part.setButtonEnabled(1, !empty);
104
			public void doubleClick(DoubleClickEvent event) {
105
		boolean hasElements = fViewer.getTable().getItemCount() > 0;
105
				Object object = ((IStructuredSelection) event.getSelection()).getFirstElement();
106
		part.setButtonEnabled(2, hasElements);
106
				ManifestEditor.openPluginEditor(((ITargetPlugin) object).getId());
107
	}
107
			}
108
108
		});
109
	protected void buttonSelected(int index) {
109
	}
110
		switch (index) {
110
111
			case ADD_INDEX :
111
//	public boolean doGlobalAction(String actionId) {
112
				handleAdd();
112
//		if (actionId.equals(ActionFactory.DELETE.getId())) {
113
				break;
113
//			handleRemove();
114
			case REMOVE_INDEX :
114
//			return true;
115
				handleRemove();
115
//		}
116
				break;
116
//		if (actionId.equals(ActionFactory.CUT.getId())) {
117
			case REMOVE_ALL_INDEX :
117
//			// delete here and let the editor transfer
118
				handleRemoveAll();
118
//			// the selection to the clipboard
119
		}
119
//			handleRemove();
120
	}
120
//			return false;
121
121
//		}
122
	protected void handleAdd() {
122
//		if (actionId.equals(ActionFactory.PASTE.getId())) {
123
		ElementListSelectionDialog dialog = new ElementListSelectionDialog(PDEPlugin.getActiveWorkbenchShell(), PDEPlugin.getDefault().getLabelProvider());
123
//			doPaste();
124
124
//			return true;
125
		dialog.setElements(getValidBundles());
125
//		}
126
		dialog.setTitle(PDEUIMessages.PluginSelectionDialog_title);
126
//		return false;
127
		dialog.setMessage(PDEUIMessages.PluginSelectionDialog_message);
127
//	}
128
		dialog.setMultipleSelection(true);
128
129
		if (dialog.open() == Window.OK) {
129
	private void createButtons(FormToolkit toolkit, Composite parent) {
130
			Object[] models = dialog.getResult();
130
		fAdd = toolkit.createButton(parent, PDEUIMessages.ImplicitDependenicesSection_Add, SWT.PUSH);
131
			ArrayList pluginsToAdd = new ArrayList();
131
		fAdd.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));
132
			ITargetModel model = getModel();
132
		fAdd.addSelectionListener(new SelectionAdapter() {
133
			for (int i = 0; i < models.length; i++) {
133
			public void widgetSelected(SelectionEvent e) {
134
				BundleDescription desc = (BundleDescription) models[i];
134
				handleAdd();
135
				ITargetPlugin plugin = model.getFactory().createPlugin();
135
			}
136
				plugin.setId(desc.getSymbolicName());
136
		});
137
				plugin.setModel(model);
137
		fRemove = toolkit.createButton(parent, PDEUIMessages.ImplicitDependenicesSection_Remove, SWT.PUSH);
138
				pluginsToAdd.add(plugin);
138
		fRemove.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));
139
			}
139
		fRemove.addSelectionListener(new SelectionAdapter() {
140
			getImplicitPluginsInfo().addPlugins((ITargetPlugin[]) pluginsToAdd.toArray(new ITargetPlugin[pluginsToAdd.size()]));
140
			public void widgetSelected(SelectionEvent e) {
141
			updateButtons();
141
				handleRemove();
142
		}
142
			}
143
	}
143
		});
144
144
		fRemoveAll = toolkit.createButton(parent, PDEUIMessages.ImplicitDependenicesSection_RemoveAll, SWT.PUSH);
145
	protected Object[] getValidBundles() {
145
		fRemoveAll.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));
146
		ITargetPlugin[] plugins = getImplicitPluginsInfo().getPlugins();
146
		fRemoveAll.addSelectionListener(new SelectionAdapter() {
147
		Set currentPlugins = new HashSet((4 / 3) * plugins.length + 1);
147
			public void widgetSelected(SelectionEvent e) {
148
		for (int i = 0; i < plugins.length; i++) {
148
				handleRemoveAll();
149
			currentPlugins.add(plugins[i].getId());
149
			}
150
		}
150
		});
151
151
		Composite countComp = toolkit.createComposite(parent);
152
		IPluginModelBase[] models = PluginRegistry.getActiveModels(false);
152
		GridLayout layout = new GridLayout();
153
		Set result = new HashSet((4 / 3) * models.length + 1);
153
		layout.marginWidth = layout.marginHeight = 0;
154
		for (int i = 0; i < models.length; i++) {
154
		countComp.setLayout(layout);
155
			BundleDescription desc = models[i].getBundleDescription();
155
		countComp.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_END | GridData.FILL_BOTH));
156
			if (desc != null) {
156
		fCount = toolkit.createLabel(parent, ""); //$NON-NLS-1$
157
				if (!currentPlugins.contains(desc.getSymbolicName()))
157
		fCount.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
158
					result.add(desc);
158
		fCount.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
159
			}
159
		fViewer.getTable().addPaintListener(new PaintListener() {
160
		}
160
			public void paintControl(PaintEvent e) {
161
		return result.toArray();
161
				updateLabel();
162
	}
162
			}
163
163
		});
164
	protected void handleRemove() {
164
	}
165
		Object[] src = ((IStructuredSelection) fViewer.getSelection()).toArray();
165
166
		ITargetPlugin[] plugins = new ITargetPlugin[src.length];
166
	private void updateButtons() {
167
		System.arraycopy(src, 0, plugins, 0, src.length);
167
		fRemove.setEnabled(!fViewer.getSelection().isEmpty());
168
		getImplicitPluginsInfo().removePlugins(plugins);
168
		fRemoveAll.setEnabled(fViewer.getTable().getItemCount() > 0);
169
		updateButtons();
169
	}
170
	}
170
171
171
	private void updateLabel() {
172
	protected void handleRemoveAll() {
172
		// TODO Finish
173
		IImplicitDependenciesInfo info = getImplicitPluginsInfo();
173
	}
174
		info.removePlugins(info.getPlugins());
174
175
		updateButtons();
175
	protected void handleAdd() {
176
	}
176
//		ElementListSelectionDialog dialog = new ElementListSelectionDialog(PDEPlugin.getActiveWorkbenchShell(), PDEPlugin.getDefault().getLabelProvider());
177
177
//
178
	private IImplicitDependenciesInfo getImplicitPluginsInfo() {
178
//		dialog.setElements(getValidBundles());
179
		IImplicitDependenciesInfo info = getTarget().getImplicitPluginsInfo();
179
//		dialog.setTitle(PDEUIMessages.PluginSelectionDialog_title);
180
		if (info == null) {
180
//		dialog.setMessage(PDEUIMessages.PluginSelectionDialog_message);
181
			info = getModel().getFactory().createImplicitPluginInfo();
181
//		dialog.setMultipleSelection(true);
182
			getTarget().setImplicitPluginsInfo(info);
182
//		if (dialog.open() == Window.OK) {
183
		}
183
//			Object[] models = dialog.getResult();
184
		return info;
184
//			ArrayList pluginsToAdd = new ArrayList();
185
	}
185
//			ITargetModel model = getModel();
186
186
//			for (int i = 0; i < models.length; i++) {
187
	private ITarget getTarget() {
187
//				BundleDescription desc = (BundleDescription) models[i];
188
		return getModel().getTarget();
188
//				ITargetPlugin plugin = model.getFactory().createPlugin();
189
	}
189
//				plugin.setId(desc.getSymbolicName());
190
190
//				plugin.setModel(model);
191
	private ITargetModel getModel() {
191
//				pluginsToAdd.add(plugin);
192
		return (ITargetModel) getPage().getPDEEditor().getAggregateModel();
192
//			}
193
	}
193
//			getImplicitPluginsInfo().addPlugins((ITargetPlugin[]) pluginsToAdd.toArray(new ITargetPlugin[pluginsToAdd.size()]));
194
194
//			updateButtons();
195
	/* (non-Javadoc)
195
//		}
196
	 * @see org.eclipse.pde.internal.ui.editor.PDESection#modelChanged(org.eclipse.pde.core.IModelChangedEvent)
196
	}
197
	 */
197
198
	public void modelChanged(IModelChangedEvent e) {
198
//	protected Object[] getValidBundles() {
199
		if (e.getChangeType() == IModelChangedEvent.WORLD_CHANGED) {
199
//		ITargetPlugin[] plugins = getImplicitPluginsInfo().getPlugins();
200
			handleModelEventWorldChanged(e);
200
//		Set currentPlugins = new HashSet((4 / 3) * plugins.length + 1);
201
			return;
201
//		for (int i = 0; i < plugins.length; i++) {
202
		}
202
//			currentPlugins.add(plugins[i].getId());
203
		if (e.getChangeType() == IModelChangedEvent.CHANGE && e.getChangedProperty().equals(IImplicitDependenciesInfo.P_IMPLICIT_PLUGINS)) {
203
//		}
204
			ITargetPlugin[] plugins = (ITargetPlugin[]) e.getOldValue();
204
//
205
			for (int i = 0; i < plugins.length; i++)
205
//		IPluginModelBase[] models = PluginRegistry.getActiveModels(false);
206
				fViewer.remove(plugins[i]);
206
//		Set result = new HashSet((4 / 3) * models.length + 1);
207
			plugins = (ITargetPlugin[]) e.getNewValue();
207
//		for (int i = 0; i < models.length; i++) {
208
			for (int i = 0; i < plugins.length; i++)
208
//			BundleDescription desc = models[i].getBundleDescription();
209
				fViewer.add(plugins[i]);
209
//			if (desc != null) {
210
		}
210
//				if (!currentPlugins.contains(desc.getSymbolicName()))
211
	}
211
//					result.add(desc);
212
212
//			}
213
	/**
213
//		}
214
	 * @param event
214
//		return result.toArray();
215
	 */
215
//	}
216
	private void handleModelEventWorldChanged(IModelChangedEvent event) {
216
217
		// Reload input
217
	private void handleRemove() {
218
		fViewer.setInput(getTarget());
218
//		Object[] src = ((IStructuredSelection) fViewer.getSelection()).toArray();
219
		// Perform the refresh
219
//		ITargetPlugin[] plugins = new ITargetPlugin[src.length];
220
		refresh();
220
//		System.arraycopy(src, 0, plugins, 0, src.length);
221
	}
221
//		getImplicitPluginsInfo().removePlugins(plugins);
222
222
//		updateButtons();
223
	/* (non-Javadoc)
223
	}
224
	 * @see org.eclipse.ui.forms.AbstractFormPart#refresh()
224
225
	 */
225
	private void handleRemoveAll() {
226
	public void refresh() {
226
//		IImplicitDependenciesInfo info = getImplicitPluginsInfo();
227
		fViewer.refresh();
227
//		info.removePlugins(info.getPlugins());
228
		updateButtons();
228
//		updateButtons();
229
		super.refresh();
229
	}
230
	}
230
231
231
//	
232
	/* (non-Javadoc)
232
//		if (e.getChangeType() == IModelChangedEvent.CHANGE && e.getChangedProperty().equals(IImplicitDependenciesInfo.P_IMPLICIT_PLUGINS)) {
233
	 * @see org.eclipse.pde.internal.ui.editor.TableSection#handleDoubleClick(org.eclipse.jface.viewers.IStructuredSelection)
233
//			ITargetPlugin[] plugins = (ITargetPlugin[]) e.getOldValue();
234
	 */
234
//			for (int i = 0; i < plugins.length; i++)
235
	protected void handleDoubleClick(IStructuredSelection selection) {
235
//				fViewer.remove(plugins[i]);
236
		handleOpen(selection);
236
//			plugins = (ITargetPlugin[]) e.getNewValue();
237
	}
237
//			for (int i = 0; i < plugins.length; i++)
238
238
//				fViewer.add(plugins[i]);
239
	private void handleOpen(IStructuredSelection selection) {
239
//		}
240
		Object object = selection.getFirstElement();
240
//	}
241
		ManifestEditor.openPluginEditor(((ITargetPlugin) object).getId());
241
242
	}
242
	/* (non-Javadoc)
243
243
	 * @see org.eclipse.ui.forms.AbstractFormPart#refresh()
244
	protected boolean canPaste(Object target, Object[] objects) {
244
	 */
245
		for (int i = 0; i < objects.length; i++) {
245
	public void refresh() {
246
			if (!(objects[i] instanceof ITargetPlugin))
246
		// TODO Input may not be the target
247
				return false;
247
//		fViewer.setInput(getTarget());
248
		}
248
		fViewer.refresh();
249
		return true;
249
		updateButtons();
250
	}
250
		super.refresh();
251
251
	}
252
	protected void doPaste(Object target, Object[] objects) {
252
253
		for (int i = 0; i < objects.length; i++) {
253
}
254
			if (objects[i] instanceof ITargetPlugin)
255
				getImplicitPluginsInfo().addPlugin((ITargetPlugin) objects[i]);
256
		}
257
	}
258
259
	protected void selectionChanged(IStructuredSelection selection) {
260
		getPage().getPDEEditor().setSelection(selection);
261
	}
262
263
	public void dispose() {
264
		ITargetModel model = getModel();
265
		if (model != null)
266
			model.removeModelChangedListener(this);
267
	}
268
269
	protected boolean createCount() {
270
		return true;
271
	}
272
}
(-)src/org/eclipse/pde/internal/ui/editor/target/LocationsSection.java (-281 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.editor.target;
12
13
import org.eclipse.core.runtime.Path;
14
import org.eclipse.jface.action.*;
15
import org.eclipse.jface.viewers.*;
16
import org.eclipse.pde.core.IModelChangedEvent;
17
import org.eclipse.pde.core.plugin.TargetPlatform;
18
import org.eclipse.pde.internal.core.itarget.*;
19
import org.eclipse.pde.internal.ui.PDEPlugin;
20
import org.eclipse.pde.internal.ui.PDEUIMessages;
21
import org.eclipse.pde.internal.ui.editor.*;
22
import org.eclipse.pde.internal.ui.elements.DefaultTableProvider;
23
import org.eclipse.pde.internal.ui.parts.TablePart;
24
import org.eclipse.pde.internal.ui.util.SWTUtil;
25
import org.eclipse.swt.SWT;
26
import org.eclipse.swt.custom.BusyIndicator;
27
import org.eclipse.swt.layout.GridData;
28
import org.eclipse.swt.widgets.Composite;
29
import org.eclipse.ui.actions.ActionFactory;
30
import org.eclipse.ui.forms.widgets.FormToolkit;
31
import org.eclipse.ui.forms.widgets.Section;
32
33
public class LocationsSection extends TableSection {
34
35
	private TableViewer fContentViewer;
36
37
	class ContentProvider extends DefaultTableProvider {
38
		public Object[] getElements(Object parent) {
39
			ITarget target = getTarget();
40
			return target.getAdditionalDirectories();
41
		}
42
	}
43
44
	public LocationsSection(PDEFormPage page, Composite parent) {
45
		super(page, parent, Section.DESCRIPTION, new String[] {PDEUIMessages.LocationsSection_add, PDEUIMessages.LocationsSection_edit, PDEUIMessages.LocationsSection_remove});
46
	}
47
48
	protected void createClient(Section section, FormToolkit toolkit) {
49
		section.setLayout(FormLayoutFactory.createClearTableWrapLayout(false, 1));
50
		Composite client = toolkit.createComposite(section);
51
		client.setLayout(FormLayoutFactory.createSectionClientGridLayout(false, 2));
52
		client.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_VERTICAL));
53
54
		createViewerPartControl(client, SWT.MULTI, 2, toolkit);
55
56
		TablePart tablePart = getTablePart();
57
		GridData data = (GridData) tablePart.getControl().getLayoutData();
58
		data.grabExcessVerticalSpace = true;
59
		data.grabExcessHorizontalSpace = true;
60
		fContentViewer = tablePart.getTableViewer();
61
		fContentViewer.setContentProvider(new ContentProvider());
62
		fContentViewer.setLabelProvider(PDEPlugin.getDefault().getLabelProvider());
63
		fContentViewer.setInput(getTarget());
64
		fContentViewer.addSelectionChangedListener(new ISelectionChangedListener() {
65
			public void selectionChanged(SelectionChangedEvent event) {
66
				updateButtons();
67
			}
68
		});
69
		fContentViewer.setComparator(new ViewerComparator() {
70
			public int compare(Viewer viewer, Object e1, Object e2) {
71
				IAdditionalLocation loc1 = (IAdditionalLocation) e1;
72
				return loc1.getPath().compareToIgnoreCase(((IAdditionalLocation) e2).getPath());
73
			}
74
		});
75
		fContentViewer.addDoubleClickListener(new IDoubleClickListener() {
76
			public void doubleClick(DoubleClickEvent event) {
77
				// if user double clicked on one selected item
78
				if (((StructuredSelection) fContentViewer.getSelection()).toArray().length == 1)
79
					handleEdit();
80
			}
81
		});
82
83
		toolkit.paintBordersFor(client);
84
		section.setClient(client);
85
		section.setText(PDEUIMessages.LocationsSection_title);
86
		section.setDescription(PDEUIMessages.LocationsSection_description);
87
		GridData sectionData = new GridData(GridData.FILL_BOTH);
88
		sectionData.horizontalSpan = 2;
89
		section.setLayoutData(sectionData);
90
		updateButtons();
91
92
		getModel().addModelChangedListener(this);
93
	}
94
95
	private ITarget getTarget() {
96
		return getModel().getTarget();
97
	}
98
99
	private ITargetModel getModel() {
100
		return (ITargetModel) getPage().getPDEEditor().getAggregateModel();
101
	}
102
103
	protected void updateButtons() {
104
		int selectionNum = ((StructuredSelection) fContentViewer.getSelection()).toArray().length;
105
		TablePart table = getTablePart();
106
		table.setButtonEnabled(1, selectionNum == 1);
107
		table.setButtonEnabled(2, selectionNum > 0);
108
	}
109
110
	protected void buttonSelected(int index) {
111
		switch (index) {
112
			case 0 :
113
				handleAdd();
114
				break;
115
			case 1 :
116
				handleEdit();
117
				break;
118
			case 2 :
119
				handleDelete();
120
		}
121
	}
122
123
	protected void handleAdd() {
124
		showDialog(null);
125
	}
126
127
	protected void handleEdit() {
128
		showDialog((IAdditionalLocation) ((StructuredSelection) fContentViewer.getSelection()).iterator().next());
129
	}
130
131
	protected void handleDelete() {
132
		IStructuredSelection ssel = (IStructuredSelection) fContentViewer.getSelection();
133
		if (ssel.size() > 0) {
134
			Object[] objects = ssel.toArray();
135
			ITarget target = getTarget();
136
			IAdditionalLocation[] dirs = new IAdditionalLocation[objects.length];
137
			System.arraycopy(objects, 0, dirs, 0, objects.length);
138
			target.removeAdditionalDirectories(dirs);
139
		}
140
	}
141
142
	private void showDialog(final IAdditionalLocation location) {
143
		final ITarget model = getTarget();
144
		BusyIndicator.showWhile(fContentViewer.getTable().getDisplay(), new Runnable() {
145
			public void run() {
146
				LocationDialog dialog = new LocationDialog(fContentViewer.getTable().getShell(), model, location);
147
				dialog.create();
148
				SWTUtil.setDialogSize(dialog, 500, -1);
149
				dialog.open();
150
			}
151
		});
152
	}
153
154
	/* (non-Javadoc)
155
	 * @see org.eclipse.pde.internal.ui.editor.PDESection#modelChanged(org.eclipse.pde.core.IModelChangedEvent)
156
	 */
157
	public void modelChanged(IModelChangedEvent e) {
158
		if (e.getChangeType() == IModelChangedEvent.WORLD_CHANGED) {
159
			handleModelEventWorldChanged(e);
160
			return;
161
		}
162
		Object[] objects = e.getChangedObjects();
163
		if (e.getChangeType() == IModelChangedEvent.INSERT) {
164
			for (int i = 0; i < objects.length; i++) {
165
				if (objects[i] instanceof IAdditionalLocation) {
166
					fContentViewer.add(objects[i]);
167
				}
168
			}
169
		} else if (e.getChangeType() == IModelChangedEvent.REMOVE) {
170
			for (int i = 0; i < objects.length; i++) {
171
				if (objects[i] instanceof IAdditionalLocation) {
172
					fContentViewer.remove(objects[i]);
173
				}
174
			}
175
		}
176
		if (e.getChangedProperty() == IAdditionalLocation.P_PATH) {
177
			fContentViewer.refresh();
178
		}
179
	}
180
181
	/**
182
	 * @param event
183
	 */
184
	private void handleModelEventWorldChanged(IModelChangedEvent event) {
185
		// Reload input
186
		fContentViewer.setInput(getTarget());
187
		// Perform the refresh
188
		refresh();
189
	}
190
191
	public boolean doGlobalAction(String actionId) {
192
		if (actionId.equals(ActionFactory.DELETE.getId())) {
193
			handleDelete();
194
			return true;
195
		}
196
		if (actionId.equals(ActionFactory.CUT.getId())) {
197
			handleDelete();
198
			return false;
199
		}
200
		if (actionId.equals(ActionFactory.PASTE.getId())) {
201
			doPaste();
202
			return true;
203
		}
204
		return false;
205
	}
206
207
	protected boolean canPaste(Object target, Object[] objects) {
208
		for (int i = 0; i < objects.length; i++) {
209
			if (objects[i] instanceof IAdditionalLocation)
210
				return true;
211
		}
212
		return false;
213
	}
214
215
	protected void doPaste(Object target, Object[] objects) {
216
		for (int i = 0; i < objects.length; i++) {
217
			if (objects[i] instanceof IAdditionalLocation && !hasPath(((IAdditionalLocation) objects[i]).getPath())) {
218
				IAdditionalLocation loc = (IAdditionalLocation) objects[i];
219
				loc.setModel(getModel());
220
				getTarget().addAdditionalDirectories(new IAdditionalLocation[] {loc});
221
			}
222
		}
223
	}
224
225
	protected boolean hasPath(String path) {
226
		Path checkPath = new Path(path);
227
		IAdditionalLocation[] locs = getModel().getTarget().getAdditionalDirectories();
228
		for (int i = 0; i < locs.length; i++) {
229
			if (new Path(locs[i].getPath()).equals(checkPath))
230
				return true;
231
		}
232
		return isTargetLocation(checkPath);
233
	}
234
235
	private boolean isTargetLocation(Path path) {
236
		ILocationInfo info = getModel().getTarget().getLocationInfo();
237
		if (info.useDefault()) {
238
			Path home = new Path(TargetPlatform.getDefaultLocation());
239
			return home.equals(path);
240
		}
241
		return new Path(info.getPath()).equals(path);
242
	}
243
244
	public void dispose() {
245
		ITargetModel model = getModel();
246
		if (model != null)
247
			model.removeModelChangedListener(this);
248
		super.dispose();
249
	}
250
251
	/* (non-Javadoc)
252
	 * @see org.eclipse.ui.forms.AbstractFormPart#refresh()
253
	 */
254
	public void refresh() {
255
		fContentViewer.refresh();
256
		updateButtons();
257
		super.refresh();
258
	}
259
260
	protected void fillContextMenu(IMenuManager manager) {
261
		IStructuredSelection ssel = (IStructuredSelection) fContentViewer.getSelection();
262
		if (ssel == null)
263
			return;
264
265
		Action removeAction = new Action(PDEUIMessages.ContentSection_remove) {
266
			public void run() {
267
				handleDelete();
268
			}
269
		};
270
		removeAction.setEnabled(isEditable() && ssel.size() > 0);
271
		manager.add(removeAction);
272
273
		manager.add(new Separator());
274
275
		getPage().getPDEEditor().getContributor().contextMenuAboutToShow(manager);
276
	}
277
278
	protected void selectionChanged(IStructuredSelection selection) {
279
		getPage().getPDEEditor().setSelection(selection);
280
	}
281
}
(-)src/org/eclipse/pde/internal/ui/editor/target/TargetInputContext.java (-98 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.editor.target;
12
13
import java.io.*;
14
import java.util.ArrayList;
15
import org.eclipse.core.resources.IFile;
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.jface.text.IDocument;
18
import org.eclipse.pde.core.*;
19
import org.eclipse.pde.internal.core.itarget.ITargetModel;
20
import org.eclipse.pde.internal.core.target.TargetModel;
21
import org.eclipse.pde.internal.core.target.WorkspaceTargetModel;
22
import org.eclipse.pde.internal.ui.PDEPlugin;
23
import org.eclipse.pde.internal.ui.editor.PDEFormEditor;
24
import org.eclipse.pde.internal.ui.editor.context.UTF8InputContext;
25
import org.eclipse.ui.*;
26
27
public class TargetInputContext extends UTF8InputContext {
28
29
	public static final String CONTEXT_ID = "target-context"; //$NON-NLS-1$
30
31
	public TargetInputContext(PDEFormEditor editor, IEditorInput input, boolean primary) {
32
		super(editor, input, primary);
33
		create();
34
	}
35
36
	/* (non-Javadoc)
37
	 * @see org.eclipse.pde.internal.ui.editor.context.InputContext#getId()
38
	 */
39
	public String getId() {
40
		return CONTEXT_ID;
41
	}
42
43
	/* (non-Javadoc)
44
	 * @see org.eclipse.pde.internal.ui.editor.context.InputContext#createModel(org.eclipse.ui.IEditorInput)
45
	 */
46
	protected IBaseModel createModel(IEditorInput input) throws CoreException {
47
		ITargetModel model = null;
48
		if (input instanceof IStorageEditorInput) {
49
			try {
50
				if (input instanceof IFileEditorInput) {
51
					IFile file = ((IFileEditorInput) input).getFile();
52
					model = new WorkspaceTargetModel(file, true);
53
					model.load();
54
				} else if (input instanceof IStorageEditorInput) {
55
					InputStream is = new BufferedInputStream(((IStorageEditorInput) input).getStorage().getContents());
56
					model = new TargetModel();
57
					model.load(is, false);
58
				}
59
			} catch (CoreException e) {
60
				PDEPlugin.logException(e);
61
				return null;
62
			}
63
		}
64
		return model;
65
	}
66
67
	/* (non-Javadoc)
68
	 * @see org.eclipse.pde.internal.ui.editor.context.InputContext#addTextEditOperation(java.util.ArrayList, org.eclipse.pde.core.IModelChangedEvent)
69
	 */
70
	protected void addTextEditOperation(ArrayList ops, IModelChangedEvent event) {
71
	}
72
73
	/* (non-Javadoc)
74
	 * @see org.eclipse.pde.internal.ui.editor.context.InputContext#flushModel(org.eclipse.jface.text.IDocument)
75
	 */
76
	protected void flushModel(IDocument doc) {
77
		if (!(getModel() instanceof IEditable))
78
			return;
79
		IEditable editableModel = (IEditable) getModel();
80
		if (editableModel.isDirty() == false)
81
			return;
82
		try {
83
			StringWriter swriter = new StringWriter();
84
			PrintWriter writer = new PrintWriter(swriter);
85
			editableModel.save(writer);
86
			writer.flush();
87
			swriter.close();
88
			doc.set(swriter.toString());
89
		} catch (IOException e) {
90
			PDEPlugin.logException(e);
91
		}
92
	}
93
94
	protected String getPartitionName() {
95
		return "___target_partition"; //$NON-NLS-1$
96
	}
97
98
}
(-)src/org/eclipse/pde/internal/ui/editor/target/TargetEditor.java (-225 / +63 lines)
Lines 1-264 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.editor.target;
1
package org.eclipse.pde.internal.ui.editor.target;
12
2
13
import java.io.File;
3
import org.eclipse.core.runtime.CoreException;
14
import java.lang.reflect.InvocationTargetException;
4
import org.eclipse.core.runtime.IProgressMonitor;
15
import java.net.URL;
5
import org.eclipse.pde.internal.core.PDECore;
16
import org.eclipse.core.filesystem.EFS;
6
import org.eclipse.pde.internal.core.target.provisional.*;
17
import org.eclipse.core.filesystem.IFileStore;
7
import org.eclipse.pde.internal.ui.PDEPlugin;
18
import org.eclipse.core.resources.IFile;
8
import org.eclipse.swt.widgets.Display;
19
import org.eclipse.core.runtime.*;
20
import org.eclipse.jface.action.ControlContribution;
21
import org.eclipse.jface.action.IToolBarManager;
22
import org.eclipse.jface.dialogs.*;
23
import org.eclipse.jface.operation.IRunnableWithProgress;
24
import org.eclipse.osgi.service.datalocation.Location;
25
import org.eclipse.pde.internal.core.LoadTargetOperation;
26
import org.eclipse.pde.internal.core.itarget.ITarget;
27
import org.eclipse.pde.internal.core.itarget.ITargetModel;
28
import org.eclipse.pde.internal.ui.*;
29
import org.eclipse.pde.internal.ui.editor.ISortableContentOutlinePage;
30
import org.eclipse.pde.internal.ui.editor.PDEFormEditor;
31
import org.eclipse.pde.internal.ui.editor.context.InputContext;
32
import org.eclipse.pde.internal.ui.editor.context.InputContextManager;
33
import org.eclipse.swt.SWT;
34
import org.eclipse.swt.widgets.Composite;
35
import org.eclipse.swt.widgets.Control;
36
import org.eclipse.ui.*;
9
import org.eclipse.ui.*;
37
import org.eclipse.ui.forms.events.HyperlinkEvent;
10
import org.eclipse.ui.forms.editor.FormEditor;
38
import org.eclipse.ui.forms.events.IHyperlinkListener;
11
import org.eclipse.ui.forms.widgets.FormToolkit;
39
import org.eclipse.ui.forms.widgets.ImageHyperlink;
40
import org.eclipse.ui.ide.FileStoreEditorInput;
41
import org.eclipse.ui.progress.IProgressService;
42
43
public class TargetEditor extends PDEFormEditor {
44
45
	protected static String LAST_PATH;
46
47
	static {
48
		Location installLoc = Platform.getInstallLocation();
49
		if (installLoc == null) {
50
			LAST_PATH = ""; //$NON-NLS-1$
51
		}
52
		URL url = installLoc.getURL();
53
		LAST_PATH = new Path(url.getPath()).toOSString();
54
	}
55
56
	public TargetEditor() {
57
		super();
58
	}
59
60
	/* (non-Javadoc)
61
	 * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#getEditorID()
62
	 */
63
	protected String getEditorID() {
64
		return IPDEUIConstants.TARGET_EDITOR_ID;
65
	}
66
12
67
	/* (non-Javadoc)
13
public class TargetEditor extends FormEditor {
68
	 * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#isSaveAsAllowed()
69
	 */
70
	public boolean isSaveAsAllowed() {
71
		return true;
72
	}
73
74
	/* (non-Javadoc)
75
	 * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#getContextIDForSaveAs()
76
	 */
77
	public String getContextIDForSaveAs() {
78
		return TargetInputContext.CONTEXT_ID;
79
	}
80
81
	/* (non-Javadoc)
82
	 * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#createInputContextManager()
83
	 */
84
	protected InputContextManager createInputContextManager() {
85
		return new TargetInputContextManager(this);
86
	}
87
88
	/* (non-Javadoc)
89
	 * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#createResourceContexts(org.eclipse.pde.internal.ui.editor.context.InputContextManager, org.eclipse.ui.IFileEditorInput)
90
	 */
91
	protected void createResourceContexts(InputContextManager manager, IFileEditorInput input) {
92
		manager.putContext(input, new TargetInputContext(this, input, true));
93
		manager.monitorFile(input.getFile());
94
	}
95
96
	/* (non-Javadoc)
97
	 * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#createSystemFileContexts(org.eclipse.pde.internal.ui.editor.context.InputContextManager, org.eclipse.pde.internal.ui.editor.SystemFileEditorInput)
98
	 */
99
	protected void createSystemFileContexts(InputContextManager manager, FileStoreEditorInput input) {
100
		File file = (File) input.getAdapter(File.class);
101
		if (file != null) {
102
			String name = file.getName();
103
			if (name.endsWith(".target")) { //$NON-NLS-1$
104
				IFileStore store;
105
				try {
106
					store = EFS.getStore(file.toURI());
107
					IEditorInput in = new FileStoreEditorInput(store);
108
					manager.putContext(in, new TargetInputContext(this, in, true));
109
				} catch (CoreException e) {
110
					PDEPlugin.logException(e);
111
				}
112
			}
113
		}
114
	}
115
116
	/* (non-Javadoc)
117
	 * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#createStorageContexts(org.eclipse.pde.internal.ui.editor.context.InputContextManager, org.eclipse.ui.IStorageEditorInput)
118
	 */
119
	protected void createStorageContexts(InputContextManager manager, IStorageEditorInput input) {
120
		if (input.getName().endsWith(".target")) { //$NON-NLS-1$
121
			manager.putContext(input, new TargetInputContext(this, input, true));
122
		}
123
	}
124
14
125
	/* (non-Javadoc)
15
	private ITargetDefinition fInput;
126
	 * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#createContentOutline()
127
	 */
128
	protected ISortableContentOutlinePage createContentOutline() {
129
		return new TargetOutlinePage(this);
130
	}
131
16
132
	/* (non-Javadoc)
17
	protected FormToolkit createToolkit(Display display) {
133
	 * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#getInputContext(java.lang.Object)
18
		return new FormToolkit(PDEPlugin.getDefault().getFormColors(display));
134
	 */
135
	protected InputContext getInputContext(Object object) {
136
		return fInputContextManager.findContext(TargetInputContext.CONTEXT_ID);
137
	}
19
	}
138
20
139
	/* (non-Javadoc)
21
	protected void addPages() {
140
	 * @see org.eclipse.ui.forms.editor.FormEditor#addPages()
141
	 */
142
	protected void addEditorPages() {
143
		try {
22
		try {
144
			addPage(new OverviewPage(this));
23
			setActiveEditor(this);
145
			addPage(new ContentPage(this));
24
			setPartName(getEditorInput().getName());
25
			addPage(new TargetDefinitionPage(this));
146
			addPage(new EnvironmentPage(this));
26
			addPage(new EnvironmentPage(this));
147
			addPageChangedListener(new IPageChangedListener() {
148
149
				public void pageChanged(PageChangedEvent event) {
150
					Object o = event.getSelectedPage();
151
					if (o instanceof EnvironmentPage)
152
						((EnvironmentPage) o).updateChoices();
153
				}
154
155
			});
156
		} catch (PartInitException e) {
27
		} catch (PartInitException e) {
157
			PDEPlugin.log(e);
28
			PDEPlugin.log(e);
158
		}
29
		}
159
	}
30
	}
160
31
161
	/* (non-Javadoc)
32
	/* (non-Javadoc)
162
	 * @see org.eclipse.pde.internal.ui.editor.context.IInputContextListener#contextAdded(org.eclipse.pde.internal.ui.editor.context.InputContext)
33
	 * @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor)
163
	 */
34
	 */
164
	public void editorContextAdded(InputContext context) {
35
	public void doSave(IProgressMonitor monitor) {
165
	}
36
		// TODO Better error handling
37
		commitPages(true);
38
		ITargetDefinition target = getTarget();
39
		if (target != null) {
40
			ITargetPlatformService service = (ITargetPlatformService) PDECore.getDefault().acquireService(ITargetPlatformService.class.getName());
41
			if (service != null) {
42
				try {
43
					service.saveTargetDefinition(target);
44
				} catch (CoreException e) {
45
					PDEPlugin.log(e);
46
				}
47
			}
48
		}
166
49
167
	/* (non-Javadoc)
50
		editorDirtyStateChanged();
168
	 * @see org.eclipse.pde.internal.ui.editor.context.IInputContextListener#contextRemoved(org.eclipse.pde.internal.ui.editor.context.InputContext)
169
	 */
170
	public void contextRemoved(InputContext context) {
171
		close(false);
172
	}
51
	}
173
52
174
	/* (non-Javadoc)
53
	/* (non-Javadoc)
175
	 * @see org.eclipse.pde.internal.ui.editor.context.IInputContextListener#monitoredFileAdded(org.eclipse.core.resources.IFile)
54
	 * @see org.eclipse.ui.part.EditorPart#doSaveAs()
176
	 */
55
	 */
177
	public void monitoredFileAdded(IFile monitoredFile) {
56
	public void doSaveAs() {
57
		// TODO Auto-generated method stub
178
	}
58
	}
179
59
180
	/* (non-Javadoc)
60
	/* (non-Javadoc)
181
	 * @see org.eclipse.pde.internal.ui.editor.context.IInputContextListener#monitoredFileRemoved(org.eclipse.core.resources.IFile)
61
	 * @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
182
	 */
62
	 */
183
	public boolean monitoredFileRemoved(IFile monitoredFile) {
63
	public boolean isSaveAsAllowed() {
184
		return true;
64
		return true;
185
	}
65
	}
186
66
187
	public void contributeToToolbar(IToolBarManager manager) {
67
	public ITargetDefinition getTarget() {
188
		ControlContribution save = new ControlContribution("Set") { //$NON-NLS-1$
68
		// TODO Better error handling
189
			protected Control createControl(Composite parent) {
69
		if (fInput == null) {
190
				final ImageHyperlink hyperlink = new ImageHyperlink(parent, SWT.NONE);
70
			ITargetPlatformService service = (ITargetPlatformService) PDECore.getDefault().acquireService(ITargetPlatformService.class.getName());
191
				hyperlink.setText(PDEUIMessages.AbstractTargetPage_setTarget);
71
			if (service != null) {
192
				hyperlink.setUnderlined(true);
72
				IEditorInput input = getEditorInput();
193
				hyperlink.setForeground(getToolkit().getHyperlinkGroup().getForeground());
73
				if (input instanceof IFileEditorInput) {
194
				hyperlink.addHyperlinkListener(new IHyperlinkListener() {
74
					ITargetHandle fileHandle = service.getTarget(((IFileEditorInput) input).getFile());
195
					public void linkActivated(HyperlinkEvent e) {
75
					try {
196
						doLoadTarget();
76
						fInput = fileHandle.getTargetDefinition();
197
					}
77
					} catch (CoreException e) {
198
78
						PDEPlugin.log(e);
199
					public void linkEntered(HyperlinkEvent e) {
200
						hyperlink.setForeground(getToolkit().getHyperlinkGroup().getActiveForeground());
201
					}
202
203
					public void linkExited(HyperlinkEvent e) {
204
						hyperlink.setForeground(getToolkit().getHyperlinkGroup().getForeground());
205
					}
206
				});
207
				return hyperlink;
208
			}
209
		};
210
		manager.add(save);
211
	}
212
213
	private void doLoadTarget() {
214
		IRunnableWithProgress run = new IRunnableWithProgress() {
215
			public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
216
				try {
217
					ITargetModel model = getTargetModel();
218
					if (!model.isLoaded()) {
219
						MessageDialog.openError(getActiveEditor().getSite().getShell(), PDEUIMessages.TargetPlatformPreferencePage_invalidTitle, PDEUIMessages.TargetPlatformPreferencePage_invalidDescription);
220
						monitor.done();
221
						return;
222
					}
79
					}
223
					LoadTargetOperation op = new LoadTargetOperation(getTarget(), getFilePath());
224
					PDEPlugin.getWorkspace().run(op, monitor);
225
					Object[] features = op.getMissingFeatures();
226
					Object[] plugins = op.getMissingPlugins();
227
					if (plugins.length + features.length > 0)
228
						TargetErrorDialog.showDialog(getActiveEditor().getSite().getShell(), features, plugins);
229
				} catch (CoreException e) {
230
					throw new InvocationTargetException(e);
231
				} catch (OperationCanceledException e) {
232
					throw new InterruptedException(e.getMessage());
233
				} finally {
234
					monitor.done();
235
				}
80
				}
81
				// TODO Support storage editor input?
236
			}
82
			}
237
		};
238
		IProgressService service = PlatformUI.getWorkbench().getProgressService();
239
		try {
240
			service.runInUI(service, run, PDEPlugin.getWorkspace().getRoot());
241
		} catch (InvocationTargetException e) {
242
		} catch (InterruptedException e) {
243
		}
83
		}
84
		return fInput;
244
	}
85
	}
245
86
246
	private ITarget getTarget() {
87
//	public void init(IEditorSite site, IEditorInput input) throws PartInitException {
247
		return getTargetModel().getTarget();
88
//		// TODO Auto-generated method stub
248
	}
89
//		super.init(site, input);
90
//		
91
//	}
249
92
250
	private ITargetModel getTargetModel() {
93
	public void doRevert() {
251
		return ((ITargetModel) getAggregateModel());
94
		try {
252
	}
95
			init(getEditorSite(), getEditorInput());
253
96
		} catch (PartInitException e) {
254
	private IPath getFilePath() {
97
			// TODO Auto-generated catch block
255
		IEditorInput input = getEditorInput();
98
			e.printStackTrace();
256
		if (input instanceof IFileEditorInput) {
257
			IFile file = ((IFileEditorInput) input).getFile();
258
			if (file != null)
259
				return file.getFullPath();
260
		}
99
		}
261
		return null;
262
	}
100
	}
263
101
264
}
102
}
(-)src/org/eclipse/pde/internal/ui/editor/target/TargetOutlinePage.java (-109 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.editor.target;
12
13
import org.eclipse.jface.viewers.ILabelProvider;
14
import org.eclipse.pde.core.IModelChangedEvent;
15
import org.eclipse.pde.internal.core.itarget.*;
16
import org.eclipse.pde.internal.ui.*;
17
import org.eclipse.pde.internal.ui.editor.FormOutlinePage;
18
import org.eclipse.pde.internal.ui.editor.PDEFormEditor;
19
import org.eclipse.swt.graphics.Image;
20
import org.eclipse.ui.forms.editor.FormPage;
21
22
public class TargetOutlinePage extends FormOutlinePage {
23
24
	public class TargetContentNode {
25
26
		private ITarget fTarget;
27
		private boolean fFeatureBased = false;
28
29
		public String toString() {
30
			return fFeatureBased ? PDEUIMessages.TargetOutlinePage_features : PDEUIMessages.TargetOutlinePage_plugins;
31
		}
32
33
		public TargetContentNode(ITarget target, boolean featureBased) {
34
			fTarget = target;
35
			fFeatureBased = featureBased;
36
		}
37
38
		public ITargetObject[] getModels() {
39
			if (fTarget.useAllPlugins())
40
				return new ITargetObject[0];
41
			if (fFeatureBased)
42
				return fTarget.getFeatures();
43
			return fTarget.getPlugins();
44
		}
45
46
		public boolean isFeatureBased() {
47
			return fFeatureBased;
48
		}
49
50
	}
51
52
	private TargetContentNode pNode;
53
	private TargetContentNode fNode;
54
55
	public TargetOutlinePage(PDEFormEditor editor) {
56
		super(editor);
57
	}
58
59
	public void modelChanged(IModelChangedEvent event) {
60
		if (ITarget.P_ALL_PLUGINS.equals(event.getChangedProperty()) || event.getChangeType() == IModelChangedEvent.WORLD_CHANGED) {
61
			super.modelChanged(event);
62
			return;
63
		}
64
65
		if (event.getChangeType() == IModelChangedEvent.INSERT || event.getChangeType() == IModelChangedEvent.REMOVE) {
66
			Object object = event.getChangedObjects()[0];
67
			if (object instanceof ITargetPlugin)
68
				getTreeViewer().refresh(pNode);
69
			else
70
				getTreeViewer().refresh(fNode);
71
			return;
72
		}
73
	}
74
75
	protected Object[] getChildren(Object parent) {
76
		if (parent instanceof ContentPage) {
77
			ContentPage page = (ContentPage) parent;
78
			ITarget target = ((ITargetModel) page.getModel()).getTarget();
79
			if (target.useAllPlugins())
80
				return new Object[0];
81
82
			if (pNode == null)
83
				pNode = new TargetContentNode(target, false);
84
			if (fNode == null)
85
				fNode = new TargetContentNode(target, true);
86
			return new Object[] {pNode, fNode};
87
		}
88
		if (parent instanceof TargetContentNode)
89
			return ((TargetContentNode) parent).getModels();
90
		return new Object[0];
91
	}
92
93
	public ILabelProvider createLabelProvider() {
94
		return new BasicLabelProvider(PDEPlugin.getDefault().getLabelProvider()) {
95
			public Image getImage(Object element) {
96
				PDELabelProvider provider = PDEPlugin.getDefault().getLabelProvider();
97
				if (element instanceof TargetContentNode) {
98
					if (((TargetContentNode) element).isFeatureBased())
99
						return provider.get(PDEPluginImages.DESC_FEATURE_OBJ);
100
					return provider.get(PDEPluginImages.DESC_PLUGIN_OBJ);
101
				}
102
				if (element instanceof FormPage)
103
					return super.getImage(element);
104
				return provider.getImage(element);
105
			}
106
		};
107
	}
108
109
}
(-)src/org/eclipse/pde/internal/ui/editor/target/ArgumentsSection.java (-197 / +156 lines)
Lines 1-197 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.editor.target;
11
package org.eclipse.pde.internal.ui.editor.target;
12
12
13
import org.eclipse.debug.ui.StringVariableSelectionDialog;
13
import org.eclipse.debug.ui.StringVariableSelectionDialog;
14
import org.eclipse.pde.core.IModelChangedEvent;
14
import org.eclipse.pde.internal.core.target.provisional.ITargetDefinition;
15
import org.eclipse.pde.internal.core.itarget.*;
15
import org.eclipse.pde.internal.ui.PDEPluginImages;
16
import org.eclipse.pde.internal.ui.PDEPluginImages;
16
import org.eclipse.pde.internal.ui.PDEUIMessages;
17
import org.eclipse.pde.internal.ui.PDEUIMessages;
17
import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
18
import org.eclipse.pde.internal.ui.editor.*;
18
import org.eclipse.pde.internal.ui.parts.FormEntry;
19
import org.eclipse.pde.internal.ui.parts.FormEntry;
19
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.custom.CTabFolder;
21
import org.eclipse.swt.custom.CTabFolder;
21
import org.eclipse.swt.custom.CTabItem;
22
import org.eclipse.swt.custom.CTabItem;
22
import org.eclipse.swt.events.SelectionAdapter;
23
import org.eclipse.swt.dnd.Clipboard;
23
import org.eclipse.swt.events.SelectionEvent;
24
import org.eclipse.swt.events.SelectionAdapter;
24
import org.eclipse.swt.graphics.Color;
25
import org.eclipse.swt.events.SelectionEvent;
25
import org.eclipse.swt.graphics.Image;
26
import org.eclipse.swt.graphics.Color;
26
import org.eclipse.swt.layout.GridData;
27
import org.eclipse.swt.graphics.Image;
27
import org.eclipse.swt.widgets.Button;
28
import org.eclipse.swt.layout.GridData;
28
import org.eclipse.swt.widgets.Composite;
29
import org.eclipse.swt.widgets.*;
29
import org.eclipse.ui.forms.IFormColors;
30
import org.eclipse.ui.IActionBars;
30
import org.eclipse.ui.forms.SectionPart;
31
import org.eclipse.ui.forms.IFormColors;
31
import org.eclipse.ui.forms.editor.FormPage;
32
import org.eclipse.ui.forms.widgets.FormToolkit;
32
import org.eclipse.ui.forms.widgets.*;
33
import org.eclipse.ui.forms.widgets.Section;
33
34
34
public class ArgumentsSection extends SectionPart {
35
public class ArgumentsSection extends PDESection {
35
36
36
	private CTabFolder fTabFolder;
37
	private static final String[] TAB_LABELS = new String[2];
37
	private FormEntry fProgramArguments;
38
	static {
38
	private FormEntry fVMArguments;
39
		TAB_LABELS[0] = PDEUIMessages.ArgumentsSection_programTabLabel;
39
	private Image fImage;
40
		TAB_LABELS[1] = PDEUIMessages.ArgumentsSection_vmTabLabel;
40
	private TargetEditor fEditor;
41
	}
41
42
42
	public ArgumentsSection(FormPage page, Composite parent) {
43
	private CTabFolder fTabFolder;
43
		super(parent, page.getManagedForm().getToolkit(), Section.DESCRIPTION | ExpandableComposite.TITLE_BAR);
44
	private FormEntry fArgument;
44
		fEditor = (TargetEditor) page.getEditor();
45
	private int fLastTab;
45
		fImage = PDEPluginImages.DESC_ARGUMENT_TAB.createImage();
46
	private Image fImage;
46
		createClient(getSection(), page.getEditor().getToolkit());
47
47
	}
48
	public ArgumentsSection(PDEFormPage page, Composite parent) {
48
49
		super(page, parent, Section.DESCRIPTION);
49
	private ITargetDefinition getTarget() {
50
		fImage = PDEPluginImages.DESC_ARGUMENT_TAB.createImage();
50
		return fEditor.getTarget();
51
		createClient(getSection(), page.getEditor().getToolkit());
51
	}
52
	}
52
53
53
	protected void createClient(Section section, FormToolkit toolkit) {
54
	protected void createClient(Section section, FormToolkit toolkit) {
54
		section.setLayout(FormLayoutFactory.createClearGridLayout(false, 1));
55
		section.setLayout(FormLayoutFactory.createClearGridLayout(false, 1));
55
		section.setText(PDEUIMessages.ArgumentsSection_editorTitle);
56
		section.setText(PDEUIMessages.ArgumentsSection_editorTitle);
56
		section.setDescription(PDEUIMessages.ArgumentsSection_description);
57
		section.setDescription(PDEUIMessages.ArgumentsSection_description);
57
		GridData data = new GridData(GridData.FILL_BOTH);
58
		GridData data = new GridData(GridData.FILL_BOTH);
58
		data.horizontalSpan = 1;
59
		data.horizontalSpan = 1;
59
		section.setLayoutData(data);
60
		section.setLayoutData(data);
60
61
61
		Composite client = toolkit.createComposite(section);
62
		Composite client = toolkit.createComposite(section);
62
		client.setLayout(FormLayoutFactory.createSectionClientGridLayout(false, 1));
63
		client.setLayout(FormLayoutFactory.createSectionClientGridLayout(false, 1));
63
		GridData gd = new GridData(GridData.FILL_BOTH);
64
		GridData gd = new GridData(GridData.FILL_BOTH);
64
		gd.widthHint = 100;
65
		gd.widthHint = 100;
65
		client.setLayoutData(gd);
66
		client.setLayoutData(gd);
66
67
67
		fTabFolder = new CTabFolder(client, SWT.FLAT | SWT.TOP);
68
		fTabFolder = new CTabFolder(client, SWT.FLAT | SWT.TOP);
68
		toolkit.adapt(fTabFolder, true, true);
69
		toolkit.adapt(fTabFolder, true, true);
69
		gd = new GridData(GridData.FILL_BOTH);
70
		gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
70
		fTabFolder.setLayoutData(gd);
71
		fTabFolder.setLayoutData(gd);
71
		toolkit.getColors().initializeSectionToolBarColors();
72
		gd.heightHint = 2;
72
		Color selectedColor = toolkit.getColors().getColor(IFormColors.TB_BG);
73
		toolkit.getColors().initializeSectionToolBarColors();
73
		fTabFolder.setSelectionBackground(new Color[] {selectedColor, toolkit.getColors().getBackground()}, new int[] {100}, true);
74
		Color selectedColor = toolkit.getColors().getColor(IFormColors.TB_BG);
74
75
		fTabFolder.setSelectionBackground(new Color[] {selectedColor, toolkit.getColors().getBackground()}, new int[] {100}, true);
75
		Composite programComp = toolkit.createComposite(fTabFolder);
76
		fTabFolder.addSelectionListener(new SelectionAdapter() {
76
		programComp.setLayout(FormLayoutFactory.createSectionClientGridLayout(false, 1));
77
			public void widgetSelected(SelectionEvent e) {
77
		programComp.setLayoutData(new GridData(GridData.FILL_BOTH));
78
				if (fArgument.isDirty())
78
		fProgramArguments = new FormEntry(programComp, toolkit, "Program Arguments:", SWT.MULTI | SWT.WRAP);
79
					fArgument.commit();
79
		fProgramArguments.getText().setLayoutData(new GridData(GridData.FILL_BOTH));
80
				refresh();
80
		fProgramArguments.setFormEntryListener(new TargetFormEntryAdapter(this) {
81
			}
81
			public void textValueChanged(FormEntry entry) {
82
		});
82
				getTarget().setProgramArguments(entry.getValue());
83
83
			}
84
		IActionBars actionBars = getPage().getPDEEditor().getEditorSite().getActionBars();
84
		});
85
85
		Button variables = toolkit.createButton(programComp, PDEUIMessages.ArgumentsSection_variableButtonTitle, SWT.NONE);
86
		fArgument = new FormEntry(client, toolkit, PDEUIMessages.ArgumentsSection_argumentsTextLabel, SWT.MULTI | SWT.WRAP);
86
		variables.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
87
		fArgument.getText().setLayoutData(new GridData(GridData.FILL_BOTH));
87
		variables.addSelectionListener(new SelectionAdapter() {
88
		fArgument.setFormEntryListener(new FormEntryAdapter(this, actionBars) {
88
			public void widgetSelected(SelectionEvent e) {
89
			public void textValueChanged(FormEntry entry) {
89
				StringVariableSelectionDialog dialog = new StringVariableSelectionDialog(getSection().getShell());
90
				if (fLastTab == 0)
90
				dialog.open();
91
					getArgumentInfo().setProgramArguments(fArgument.getValue());
91
				String variable = dialog.getVariableExpression();
92
				else
92
				if (variable != null) {
93
					getArgumentInfo().setVMArguments(fArgument.getValue());
93
					fProgramArguments.getText().insert(variable);
94
			}
94
				}
95
		});
95
			}
96
96
		});
97
		Button variables = toolkit.createButton(client, PDEUIMessages.ArgumentsSection_variableButtonTitle, SWT.NONE);
97
		CTabItem programTab = new CTabItem(fTabFolder, SWT.NULL);
98
		variables.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
98
		programTab.setText(PDEUIMessages.ArgumentsSection_programTabLabel);
99
		variables.addSelectionListener(new SelectionAdapter() {
99
		programTab.setImage(fImage);
100
			public void widgetSelected(SelectionEvent e) {
100
		programTab.setControl(programComp);
101
				StringVariableSelectionDialog dialog = new StringVariableSelectionDialog(getSection().getShell());
101
		toolkit.paintBordersFor(programComp);
102
				dialog.open();
102
103
				String variable = dialog.getVariableExpression();
103
		// TODO Could be done neatly in a method
104
				if (variable != null) {
104
		Composite vmComp = toolkit.createComposite(fTabFolder);
105
					fArgument.getText().insert(variable);
105
		vmComp.setLayout(FormLayoutFactory.createSectionClientGridLayout(false, 1));
106
				}
106
		vmComp.setLayoutData(new GridData(GridData.FILL_BOTH));
107
			}
107
		fVMArguments = new FormEntry(vmComp, toolkit, "VM Arguments:", SWT.MULTI | SWT.WRAP);
108
		});
108
		fVMArguments.getText().setLayoutData(new GridData(GridData.FILL_BOTH));
109
109
		fVMArguments.setFormEntryListener(new TargetFormEntryAdapter(this) {
110
		createTabs();
110
			public void textValueChanged(FormEntry entry) {
111
		toolkit.paintBordersFor(client);
111
				getTarget().setVMArguments(entry.getValue());
112
		section.setClient(client);
112
			}
113
113
		});
114
		// Register to be notified when the model changes
114
		variables = toolkit.createButton(vmComp, PDEUIMessages.ArgumentsSection_variableButtonTitle, SWT.NONE);
115
		getModel().addModelChangedListener(this);
115
		variables.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
116
	}
116
		variables.addSelectionListener(new SelectionAdapter() {
117
117
			public void widgetSelected(SelectionEvent e) {
118
	/* (non-Javadoc)
118
				StringVariableSelectionDialog dialog = new StringVariableSelectionDialog(getSection().getShell());
119
	 * @see org.eclipse.pde.internal.ui.editor.PDESection#modelChanged(org.eclipse.pde.core.IModelChangedEvent)
119
				dialog.open();
120
	 */
120
				String variable = dialog.getVariableExpression();
121
	public void modelChanged(IModelChangedEvent e) {
121
				if (variable != null) {
122
		// No need to call super, handling world changed event here
122
					fVMArguments.getText().insert(variable);
123
		if (e.getChangeType() == IModelChangedEvent.WORLD_CHANGED) {
123
				}
124
			handleModelEventWorldChanged(e);
124
			}
125
		}
125
		});
126
	}
126
		CTabItem vmTab = new CTabItem(fTabFolder, SWT.NULL);
127
127
		vmTab.setText(PDEUIMessages.ArgumentsSection_vmTabLabel);
128
	/**
128
		vmTab.setImage(fImage);
129
	 * @param event
129
		vmTab.setControl(vmComp);
130
	 */
130
		toolkit.paintBordersFor(vmComp);
131
	private void handleModelEventWorldChanged(IModelChangedEvent event) {
131
132
		// Perform the refresh
132
		fTabFolder.setSelection(programTab);
133
		refresh();
133
134
	}
134
		toolkit.paintBordersFor(client);
135
135
		section.setClient(client);
136
	private void createTabs() {
136
	}
137
		for (int i = 0; i < TAB_LABELS.length; i++) {
137
138
			CTabItem item = new CTabItem(fTabFolder, SWT.NULL);
138
	public void refresh() {
139
			item.setText(TAB_LABELS[i]);
139
		fProgramArguments.setValue(getTarget().getProgramArguments(), true);
140
			item.setImage(fImage);
140
		fVMArguments.setValue(getTarget().getVMArguments(), true);
141
		}
141
		super.refresh();
142
		fLastTab = 0;
142
	}
143
		fTabFolder.setSelection(fLastTab);
143
144
	}
144
	public void commit(boolean onSave) {
145
145
		fProgramArguments.commit();
146
	private IArgumentsInfo getArgumentInfo() {
146
		fVMArguments.commit();
147
		IArgumentsInfo info = getTarget().getArguments();
147
		super.commit(onSave);
148
		if (info == null) {
148
	}
149
			info = getModel().getFactory().createArguments();
149
150
			getTarget().setArguments(info);
150
	public void dispose() {
151
		}
151
		if (fImage != null)
152
		return info;
152
			fImage.dispose();
153
	}
153
		super.dispose();
154
154
	}
155
	private ITarget getTarget() {
155
156
		return getModel().getTarget();
156
}
157
	}
158
159
	private ITargetModel getModel() {
160
		return (ITargetModel) getPage().getPDEEditor().getAggregateModel();
161
	}
162
163
	public void refresh() {
164
		fLastTab = fTabFolder.getSelectionIndex();
165
		if (fLastTab == 0)
166
			fArgument.setValue(getArgumentInfo().getProgramArguments(), true);
167
		else
168
			fArgument.setValue(getArgumentInfo().getVMArguments(), true);
169
		super.refresh();
170
	}
171
172
	public void commit(boolean onSave) {
173
		fArgument.commit();
174
		super.commit(onSave);
175
	}
176
177
	public void cancelEdit() {
178
		fArgument.cancelEdit();
179
		super.cancelEdit();
180
	}
181
182
	public boolean canPaste(Clipboard clipboard) {
183
		Display d = getSection().getDisplay();
184
		return d.getFocusControl() instanceof Text;
185
	}
186
187
	public void dispose() {
188
		ITargetModel model = getModel();
189
		if (model != null) {
190
			model.removeModelChangedListener(this);
191
		}
192
		if (fImage != null)
193
			fImage.dispose();
194
		super.dispose();
195
	}
196
197
}
(-)META-INF/MANIFEST.MF (-1 / +2 lines)
Lines 98-104 Link Here
98
 org.eclipse.equinox.p2.core;bundle-version="[1.0.0,2.0.0)",
98
 org.eclipse.equinox.p2.core;bundle-version="[1.0.0,2.0.0)",
99
 org.eclipse.equinox.p2.director;bundle-version="[1.0.100,2.0.0)",
99
 org.eclipse.equinox.p2.director;bundle-version="[1.0.100,2.0.0)",
100
 org.eclipse.equinox.p2.artifact.repository;bundle-version="[1.0.100,2.0.0)",
100
 org.eclipse.equinox.p2.artifact.repository;bundle-version="[1.0.100,2.0.0)",
101
 org.eclipse.equinox.p2.metadata.repository;bundle-version="[1.0.100,2.0.0)"
101
 org.eclipse.equinox.p2.metadata.repository;bundle-version="[1.0.100,2.0.0)",
102
 org.eclipse.equinox.frameworkadmin;bundle-version="[1.0.100,2.0.0)"
102
Eclipse-LazyStart: true
103
Eclipse-LazyStart: true
103
Import-Package: com.ibm.icu.text,
104
Import-Package: com.ibm.icu.text,
104
 org.eclipse.jdt.debug.core
105
 org.eclipse.jdt.debug.core
(-)src/org/eclipse/pde/internal/ui/editor/target/TargetInformationSection.java (+92 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.editor.target;
12
13
import org.eclipse.pde.internal.core.target.provisional.ITargetDefinition;
14
import org.eclipse.pde.internal.ui.PDEUIMessages;
15
import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
16
import org.eclipse.pde.internal.ui.parts.FormEntry;
17
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.layout.GridData;
19
import org.eclipse.swt.widgets.Composite;
20
import org.eclipse.ui.forms.SectionPart;
21
import org.eclipse.ui.forms.editor.FormPage;
22
import org.eclipse.ui.forms.widgets.*;
23
24
public class TargetInformationSection extends SectionPart {
25
26
	private FormEntry fNameEntry;
27
	private FormEntry fDescEntry;
28
	private TargetEditor fEditor;
29
30
	public TargetInformationSection(FormPage page, Composite parent) {
31
		super(parent, page.getManagedForm().getToolkit(), Section.DESCRIPTION | ExpandableComposite.TITLE_BAR);
32
		fEditor = (TargetEditor) page.getEditor();
33
		createClient(getSection(), page.getEditor().getToolkit());
34
	}
35
36
	private ITargetDefinition getTarget() {
37
		return fEditor.getTarget();
38
	}
39
40
	protected void createClient(Section section, FormToolkit toolkit) {
41
		section.setLayout(FormLayoutFactory.createClearGridLayout(false, 1));
42
		GridData data = new GridData(GridData.FILL_HORIZONTAL);
43
		data.verticalAlignment = SWT.TOP;
44
		data.horizontalSpan = 2;
45
		section.setLayoutData(data);
46
47
		section.setText("Target Information");
48
		section.setDescription("Enter a name and description for this target.");
49
50
		Composite client = toolkit.createComposite(section);
51
		client.setLayout(FormLayoutFactory.createSectionClientGridLayout(false, 2));
52
		client.setLayoutData(new GridData(GridData.FILL_BOTH));
53
54
		fNameEntry = new FormEntry(client, toolkit, PDEUIMessages.TargetDefinitionSection_name, null, false);
55
		fNameEntry.setValue(getTarget().getName());
56
		fNameEntry.setFormEntryListener(new TargetFormEntryAdapter(this) {
57
			public void textValueChanged(FormEntry entry) {
58
				getTarget().setName(entry.getValue());
59
			}
60
		});
61
62
		fDescEntry = new FormEntry(client, toolkit, "Target Description:", null, false);
63
		fDescEntry.setValue(getTarget().getName());
64
		fDescEntry.setFormEntryListener(new TargetFormEntryAdapter(this) {
65
			public void textValueChanged(FormEntry entry) {
66
				getTarget().setDescription(entry.getValue());
67
			}
68
		});
69
70
		toolkit.paintBordersFor(client);
71
		section.setClient(client);
72
	}
73
74
	/* (non-Javadoc)
75
	 * @see org.eclipse.ui.forms.AbstractFormPart#commit(boolean)
76
	 */
77
	public void commit(boolean onSave) {
78
		fNameEntry.commit();
79
		fDescEntry.commit();
80
		super.commit(onSave);
81
	}
82
83
	/* (non-Javadoc)
84
	 * @see org.eclipse.ui.forms.AbstractFormPart#refresh()
85
	 */
86
	public void refresh() {
87
		fNameEntry.setValue(getTarget().getName(), true);
88
		fDescEntry.setValue(getTarget().getDescription(), true);
89
		super.refresh();
90
	}
91
92
}
(-)src/org/eclipse/pde/internal/ui/editor/target/TargetContentSection.java (+78 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.editor.target;
12
13
import org.eclipse.pde.internal.core.target.provisional.ITargetDefinition;
14
import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
15
import org.eclipse.swt.layout.GridData;
16
import org.eclipse.swt.widgets.Composite;
17
import org.eclipse.ui.forms.SectionPart;
18
import org.eclipse.ui.forms.editor.FormPage;
19
import org.eclipse.ui.forms.widgets.*;
20
21
public class TargetContentSection extends SectionPart {
22
23
	private TargetContentTable fTable;
24
	private TargetEditor fEditor;
25
26
	public TargetContentSection(FormPage page, Composite parent) {
27
		super(parent, page.getManagedForm().getToolkit(), Section.DESCRIPTION | ExpandableComposite.TITLE_BAR);
28
		fEditor = (TargetEditor) page.getEditor();
29
		createClient(getSection(), page.getEditor().getToolkit());
30
	}
31
32
	private ITargetDefinition getTarget() {
33
		return fEditor.getTarget();
34
	}
35
36
	protected void createClient(Section section, FormToolkit toolkit) {
37
		section.setLayout(FormLayoutFactory.createClearTableWrapLayout(false, 1));
38
		GridData sectionData = new GridData(GridData.FILL_BOTH);
39
		sectionData.horizontalSpan = 2;
40
		section.setLayoutData(sectionData);
41
		section.setText("Content");
42
		// TODO Delete NL'd messages that are no longer relevent, such as the content/environment description
43
//		section.setDescription(PDEUIMessages.OverviewPage_contentDescription);
44
45
		section.setDescription("Specify the locations and plug-ins to include in your target platform.");
46
		Composite client = toolkit.createComposite(section);
47
		client.setLayout(FormLayoutFactory.createSectionClientGridLayout(false, 1));
48
		client.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_VERTICAL));
49
50
//		Composite tableContainer = toolkit.createComposite(client);
51
//		tableContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
52
//		tableContainer.setLayout(FormLayoutFactory.createClearGridLayout(false, 1));
53
		fTable = TargetContentTable.createTableInForm(client, toolkit);
54
		fTable.setInput(getTarget());
55
56
		toolkit.paintBordersFor(client);
57
58
		section.setClient(client);
59
	}
60
61
//	/* (non-Javadoc)
62
//	 * @see org.eclipse.ui.forms.AbstractFormPart#commit(boolean)
63
//	 */
64
//	public void commit(boolean onSave) {
65
//		// TODO Commit the table? May not be necessary
66
//		fTable.commit(onSave);
67
//	}
68
69
	/* (non-Javadoc)
70
	 * @see org.eclipse.ui.forms.AbstractFormPart#refresh()
71
	 */
72
	public void refresh() {
73
		// TODO Refresh the table
74
//		fTable.refresh();
75
		super.refresh();
76
	}
77
78
}
(-)src/org/eclipse/pde/internal/ui/editor/target/TargetContentTable.java (+212 lines)
Added Link Here
1
package org.eclipse.pde.internal.ui.editor.target;
2
3
import org.eclipse.core.runtime.CoreException;
4
import org.eclipse.core.runtime.NullProgressMonitor;
5
import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo;
6
import org.eclipse.jface.viewers.*;
7
import org.eclipse.pde.internal.core.target.impl.*;
8
import org.eclipse.pde.internal.core.target.provisional.IBundleContainer;
9
import org.eclipse.pde.internal.core.target.provisional.ITargetDefinition;
10
import org.eclipse.pde.internal.ui.PDEPlugin;
11
import org.eclipse.pde.internal.ui.PDEPluginImages;
12
import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
13
import org.eclipse.swt.SWT;
14
import org.eclipse.swt.events.SelectionAdapter;
15
import org.eclipse.swt.events.SelectionEvent;
16
import org.eclipse.swt.graphics.Image;
17
import org.eclipse.swt.layout.GridData;
18
import org.eclipse.swt.layout.GridLayout;
19
import org.eclipse.swt.widgets.*;
20
import org.eclipse.ui.ISharedImages;
21
import org.eclipse.ui.PlatformUI;
22
import org.eclipse.ui.forms.widgets.FormToolkit;
23
24
public class TargetContentTable {
25
26
	private TreeViewer fTreeViewer;
27
	private Button fAddButton;
28
29
	public static TargetContentTable createTableInForm(Composite parent, FormToolkit toolkit) {
30
		TargetContentTable contentTable = new TargetContentTable();
31
		contentTable.createFormContents(parent, toolkit);
32
		return contentTable;
33
	}
34
35
	public static TargetContentTable createTableInDialog(Composite parent) {
36
		TargetContentTable contentTable = new TargetContentTable();
37
		contentTable.createDialogContents(parent);
38
		return contentTable;
39
	}
40
41
	private TargetContentTable() {
42
	}
43
44
	private void createFormContents(Composite parent, FormToolkit toolkit) {
45
		Composite comp = toolkit.createComposite(parent);
46
		comp.setLayout(FormLayoutFactory.createSectionClientGridLayout(false, 2));
47
		comp.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_VERTICAL));
48
49
		Tree atree = toolkit.createTree(comp, SWT.V_SCROLL | SWT.H_SCROLL);
50
		atree.setLayout(new GridLayout());
51
		GridData gd = new GridData(GridData.FILL_BOTH);
52
//		gd.widthHint = 400;
53
//		gd.heightHint = 400;
54
		atree.setLayoutData(gd);
55
		initializeTreeViewer(atree);
56
57
		Composite buttonComp = toolkit.createComposite(comp);
58
		GridLayout layout = new GridLayout();
59
		layout.marginWidth = layout.marginHeight = 0;
60
		buttonComp.setLayout(layout);
61
		buttonComp.setLayoutData(new GridData(GridData.FILL_VERTICAL));
62
63
		fAddButton = toolkit.createButton(buttonComp, "Add...", SWT.PUSH);
64
		fAddButton.addSelectionListener(new SelectionAdapter() {
65
			public void widgetSelected(SelectionEvent e) {
66
				handleAdd();
67
			}
68
		});
69
		fAddButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));
70
		toolkit.paintBordersFor(comp);
71
72
	}
73
74
	/**
75
	 * @param parent
76
	 */
77
	private void createDialogContents(Composite parent) {
78
		// TODO Auto-generated method stub
79
	}
80
81
	private void initializeTreeViewer(Tree aTree) {
82
		fTreeViewer = new TreeViewer(aTree);
83
		fTreeViewer.setContentProvider(new TargetContentProvider());
84
		fTreeViewer.setLabelProvider(new TargetLabelProvider());
85
	}
86
87
	class TargetContentProvider implements ITreeContentProvider {
88
89
		public Object[] getChildren(Object parentElement) {
90
			// TODO If returning null is valid we can simplify this code
91
			if (parentElement instanceof ITargetDefinition) {
92
				IBundleContainer[] containers = ((ITargetDefinition) parentElement).getBundleContainers();
93
				return containers != null ? containers : new Object[0];
94
			} else if (parentElement instanceof IBundleContainer) {
95
				try {
96
					return ((IBundleContainer) parentElement).resolveBundles(new NullProgressMonitor());
97
				} catch (CoreException e) {
98
					// TODO Handle proper status
99
					return new String[] {"Error getting bundle list!"};
100
				}
101
			}
102
			return new Object[0];
103
		}
104
105
		public Object getParent(Object element) {
106
			if (element instanceof IBundleContainer) {
107
			}
108
			return null;
109
		}
110
111
		public boolean hasChildren(Object element) {
112
			if (element instanceof ITargetDefinition) {
113
				IBundleContainer[] containers = ((ITargetDefinition) element).getBundleContainers();
114
				return containers != null && containers.length > 0;
115
			}
116
			if (element instanceof IBundleContainer) {
117
				return true;
118
			}
119
			return false;
120
		}
121
122
		public Object[] getElements(Object inputElement) {
123
			if (inputElement instanceof ITargetDefinition) {
124
				return ((ITargetDefinition) inputElement).getBundleContainers();
125
			}
126
			return new Object[0];
127
		}
128
129
		public void dispose() {
130
		}
131
132
		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
133
		}
134
135
	}
136
137
	// TODO The label provider should be NLS'd
138
	class TargetLabelProvider extends LabelProvider {
139
		public String getText(Object element) {
140
			if (element instanceof FeatureBundleContainer) {
141
				StringBuffer buf = new StringBuffer();
142
				buf.append("Feature (").append(((FeatureBundleContainer) element).getFeatureId());
143
				String version = ((FeatureBundleContainer) element).getFeatureVersion();
144
				if (version != null) {
145
					buf.append(' ').append(version);
146
				}
147
				buf.append(") ");
148
				try {
149
					buf.append(((FeatureBundleContainer) element).getHomeLocation());
150
				} catch (CoreException e) {
151
					buf.append(e.getMessage());
152
				}
153
				return buf.toString();
154
			} else if (element instanceof DirectoryBundleContainer) {
155
				StringBuffer buf = new StringBuffer();
156
				buf.append("Directory ");
157
				try {
158
					buf.append(((DirectoryBundleContainer) element).getHomeLocation());
159
				} catch (CoreException e) {
160
					buf.append(e.getMessage());
161
				}
162
				return buf.toString();
163
			} else if (element instanceof ProfileBundleContainer) {
164
				StringBuffer buf = new StringBuffer();
165
				buf.append("Profile ");
166
				try {
167
					buf.append(((ProfileBundleContainer) element).getHomeLocation());
168
				} catch (CoreException e) {
169
					buf.append(e.getMessage());
170
				}
171
				String configArea = ((ProfileBundleContainer) element).getConfigurationLocation();
172
				if (configArea != null) {
173
					buf.append(" / ").append(configArea);
174
				}
175
				return buf.toString();
176
			} else if (element instanceof BundleInfo) {
177
				StringBuffer buf = new StringBuffer();
178
				buf.append(((BundleInfo) element).getSymbolicName());
179
				String version = ((BundleInfo) element).getVersion();
180
				if (version != null) {
181
					buf.append(' ').append(version);
182
				}
183
				return buf.toString();
184
			}
185
			return super.getText(element);
186
		}
187
188
		public Image getImage(Object element) {
189
			if (element instanceof FeatureBundleContainer) {
190
				return PDEPlugin.getDefault().getLabelProvider().get(PDEPluginImages.DESC_FEATURE_OBJ);
191
			} else if (element instanceof DirectoryBundleContainer) {
192
				return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);
193
			} else if (element instanceof ProfileBundleContainer) {
194
				return PDEPlugin.getDefault().getLabelProvider().get(PDEPluginImages.DESC_PRODUCT_DEFINITION);
195
			} else if (element instanceof BundleInfo) {
196
				return PDEPlugin.getDefault().getLabelProvider().get(PDEPluginImages.DESC_PLUGIN_OBJ);
197
			}
198
			return super.getImage(element);
199
		}
200
	}
201
202
	public void setInput(ITargetDefinition target) {
203
		if (fTreeViewer != null) {
204
			fTreeViewer.setInput(target);
205
		}
206
	}
207
208
	private void handleAdd() {
209
210
	}
211
212
}
(-)src/org/eclipse/pde/internal/ui/editor/target/TargetFormEntryAdapter.java (+41 lines)
Added Link Here
1
package org.eclipse.pde.internal.ui.editor.target;
2
3
import org.eclipse.pde.internal.ui.parts.FormEntry;
4
import org.eclipse.pde.internal.ui.parts.IFormEntryListener;
5
import org.eclipse.ui.forms.AbstractFormPart;
6
import org.eclipse.ui.forms.events.HyperlinkEvent;
7
8
public class TargetFormEntryAdapter implements IFormEntryListener {
9
10
	private AbstractFormPart fFormPart;
11
12
	public TargetFormEntryAdapter(AbstractFormPart formPart) {
13
		fFormPart = formPart;
14
	}
15
16
	public void browseButtonSelected(FormEntry entry) {
17
	}
18
19
	public void focusGained(FormEntry entry) {
20
	}
21
22
	public void selectionChanged(FormEntry entry) {
23
	}
24
25
	public void textDirty(FormEntry entry) {
26
		fFormPart.markDirty();
27
	}
28
29
	public void textValueChanged(FormEntry entry) {
30
	}
31
32
	public void linkActivated(HyperlinkEvent e) {
33
	}
34
35
	public void linkEntered(HyperlinkEvent e) {
36
	}
37
38
	public void linkExited(HyperlinkEvent e) {
39
	}
40
41
}
(-)src/org/eclipse/pde/internal/ui/editor/target/TargetDefinitionPage.java (+95 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.editor.target;
12
13
import org.eclipse.pde.internal.core.target.provisional.ITargetDefinition;
14
import org.eclipse.pde.internal.ui.*;
15
import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
16
import org.eclipse.swt.widgets.Composite;
17
import org.eclipse.ui.PlatformUI;
18
import org.eclipse.ui.forms.IManagedForm;
19
import org.eclipse.ui.forms.editor.FormPage;
20
import org.eclipse.ui.forms.widgets.FormToolkit;
21
import org.eclipse.ui.forms.widgets.ScrolledForm;
22
23
public class TargetDefinitionPage extends FormPage {
24
25
	public static final String PAGE_ID = "overview"; //$NON-NLS-1$
26
27
	public TargetDefinitionPage(TargetEditor editor) {
28
		super(editor, PAGE_ID, "Definition");
29
	}
30
31
	public ITargetDefinition getTarget() {
32
		return ((TargetEditor) getEditor()).getTarget();
33
	}
34
35
	/* (non-Javadoc)
36
	 * @see org.eclipse.pde.internal.ui.editor.PDEFormPage#createFormContent(org.eclipse.ui.forms.IManagedForm)
37
	 */
38
	protected void createFormContent(IManagedForm managedForm) {
39
		super.createFormContent(managedForm);
40
		ScrolledForm form = managedForm.getForm();
41
		FormToolkit toolkit = managedForm.getToolkit();
42
		form.setText("Target Definition");
43
		form.setImage(PDEPlugin.getDefault().getLabelProvider().get(PDEPluginImages.DESC_TARGET_DEFINITION));
44
		toolkit.decorateFormHeading(form.getForm());
45
		fillBody(managedForm, toolkit);
46
		PlatformUI.getWorkbench().getHelpSystem().setHelp(form.getBody(), IHelpContextIds.TARGET_OVERVIEW_PAGE);
47
	}
48
49
	private void fillBody(IManagedForm managedForm, FormToolkit toolkit) {
50
		Composite body = managedForm.getForm().getBody();
51
		body.setLayout(FormLayoutFactory.createFormGridLayout(true, 1));
52
		managedForm.addPart(new TargetInformationSection(this, body));
53
		managedForm.addPart(new TargetContentSection(this, body));
54
//		createEnvironmentSection(body, toolkit);
55
	}
56
57
//	private void createEnvironmentSection(Composite parent, FormToolkit toolkit) {
58
//		Section section = toolkit.createSection(parent, ExpandableComposite.TITLE_BAR);
59
//		section.clientVerticalSpacing = FormLayoutFactory.SECTION_HEADER_VERTICAL_SPACING;
60
//		section.setText(PDEUIMessages.OverviewPage_environmentTitle);
61
//		section.setLayout(FormLayoutFactory.createClearTableWrapLayout(false, 1));
62
//		section.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));
63
//
64
//		Composite container = toolkit.createComposite(section, SWT.NONE);
65
//		container.setLayout(FormLayoutFactory.createSectionClientTableWrapLayout(false, 1));
66
//		section.setClient(container);
67
//		FormText text = toolkit.createFormText(container, true);
68
//		text.setText(PDEUIMessages.OverviewPage_environmentDescription, true, false);
69
//
70
//		TableWrapData data = new TableWrapData(TableWrapData.FILL_GRAB);
71
//		data.maxWidth = 250;
72
//		text.setLayoutData(data);
73
//		text.addHyperlinkListener(new IHyperlinkListener() {
74
//			public void linkActivated(HyperlinkEvent e) {
75
//				getEditor().setActivePage(EnvironmentPage.PAGE_ID);
76
//			}
77
//
78
//			public void linkEntered(HyperlinkEvent e) {
79
//				IStatusLineManager mng = getEditor().getEditorSite().getActionBars().getStatusLineManager();
80
//				mng.setMessage(e.getLabel());
81
//			}
82
//
83
//			public void linkExited(HyperlinkEvent e) {
84
//				IStatusLineManager mng = getEditor().getEditorSite().getActionBars().getStatusLineManager();
85
//				mng.setMessage(null);
86
//			}
87
//		});
88
//	}
89
90
	// TODO Hook up help toolbar action
91
//	protected String getHelpResource() {
92
//		return "/org.eclipse.pde.doc.user/guide/tools/editors/target_definition_editor/overview.htm"; //$NON-NLS-1$
93
//	}
94
95
}

Return to bug 256910