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

Collapse All | Expand All

(-)src/org/eclipse/pde/internal/ui/editor/product/ProductEditor.java (-3 / +4 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2007 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
Lines 112-118 Link Here
112
	protected void addEditorPages() {
112
	protected void addEditorPages() {
113
		try {
113
		try {
114
			addPage(new OverviewPage(this));
114
			addPage(new OverviewPage(this));
115
			addPage(new ConfigurationPage(this, useFeatures()));
115
			addPage(new DependenciesPage(this, useFeatures()));
116
			addPage(new ConfigurationPage(this, false));
116
			addPage(new LaunchingPage(this));
117
			addPage(new LaunchingPage(this));
117
			addPage(new SplashPage(this));
118
			addPage(new SplashPage(this));
118
			addPage(new BrandingPage(this));
119
			addPage(new BrandingPage(this));
Lines 124-130 Link Here
124
	public void updateConfigurationPage() {
125
	public void updateConfigurationPage() {
125
		try {
126
		try {
126
			removePage(1);
127
			removePage(1);
127
			addPage(1, new ConfigurationPage(this, useFeatures()));
128
			addPage(1, new DependenciesPage(this, useFeatures()));
128
		} catch (PartInitException e) {
129
		} catch (PartInitException e) {
129
		}
130
		}
130
	}
131
	}
(-)src/org/eclipse/pde/internal/ui/editor/product/IntroSection.java (-2 / +2 lines)
Lines 212-220 Link Here
212
			plugin.setId(INTRO_PLUGIN_ID);
212
			plugin.setId(INTRO_PLUGIN_ID);
213
			product.addPlugins(new IProductPlugin[] {plugin});
213
			product.addPlugins(new IProductPlugin[] {plugin});
214
			boolean includeOptional = false;
214
			boolean includeOptional = false;
215
			IFormPage page = getPage().getEditor().findPage(ConfigurationPage.PLUGIN_ID);
215
			IFormPage page = getPage().getEditor().findPage(DependenciesPage.PLUGIN_ID);
216
			if (page != null)
216
			if (page != null)
217
				includeOptional = ((ConfigurationPage) page).includeOptionalDependencies();
217
				includeOptional = ((DependenciesPage) page).includeOptionalDependencies();
218
			PluginSection.handleAddRequired(new IProductPlugin[] {plugin}, includeOptional);
218
			PluginSection.handleAddRequired(new IProductPlugin[] {plugin}, includeOptional);
219
		}
219
		}
220
		if (fManifest == null)
220
		if (fManifest == null)
(-)src/org/eclipse/pde/internal/ui/editor/product/OverviewPage.java (-1 / +1 lines)
Lines 84-90 Link Here
84
				getPDEEditor().doSave(null);
84
				getPDEEditor().doSave(null);
85
			new ProductExportAction(getPDEEditor()).run();
85
			new ProductExportAction(getPDEEditor()).run();
86
		} else if (href.equals("configuration")) { //$NON-NLS-1$
86
		} else if (href.equals("configuration")) { //$NON-NLS-1$
87
			String pageId = ((ProductLauncherFormPageHelper) getLauncherHelper()).getProduct().useFeatures() ? ConfigurationPage.FEATURE_ID : ConfigurationPage.PLUGIN_ID;
87
			String pageId = ((ProductLauncherFormPageHelper) getLauncherHelper()).getProduct().useFeatures() ? DependenciesPage.FEATURE_ID : DependenciesPage.PLUGIN_ID;
88
			getEditor().setActivePage(pageId);
88
			getEditor().setActivePage(pageId);
89
		} else
89
		} else
90
			super.linkActivated(e);
90
			super.linkActivated(e);
(-)src/org/eclipse/pde/internal/ui/editor/product/ProductOutlinePage.java (-4 / +4 lines)
Lines 24-31 Link Here
24
	}
24
	}
25
25
26
	protected Object[] getChildren(Object parent) {
26
	protected Object[] getChildren(Object parent) {
27
		if (parent instanceof ConfigurationPage) {
27
		if (parent instanceof DependenciesPage) {
28
			ConfigurationPage page = (ConfigurationPage) parent;
28
			DependenciesPage page = (DependenciesPage) parent;
29
			IProduct product = ((IProductModel) page.getModel()).getProduct();
29
			IProduct product = ((IProductModel) page.getModel()).getProduct();
30
			if (product.useFeatures())
30
			if (product.useFeatures())
31
				return product.getFeatures();
31
				return product.getFeatures();
Lines 36-44 Link Here
36
36
37
	protected String getParentPageId(Object item) {
37
	protected String getParentPageId(Object item) {
38
		if (item instanceof IProductPlugin)
38
		if (item instanceof IProductPlugin)
39
			return ConfigurationPage.PLUGIN_ID;
39
			return DependenciesPage.PLUGIN_ID;
40
		if (item instanceof IProductFeature)
40
		if (item instanceof IProductFeature)
41
			return ConfigurationPage.FEATURE_ID;
41
			return DependenciesPage.FEATURE_ID;
42
		return super.getParentPageId(item);
42
		return super.getParentPageId(item);
43
	}
43
	}
44
44
(-)src/org/eclipse/pde/internal/ui/editor/product/ConfigurationPage.java (-29 / +14 lines)
Lines 1-12 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
2
 * Copyright (c) 2008 Code 9 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
 *     Code 9 Corporation - initial API and implementation
10
 *     Bartosz Michalik (bartosz.michalik@gmail.com)
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.editor.product;
12
package org.eclipse.pde.internal.ui.editor.product;
12
13
Lines 16-43 Link Here
16
import org.eclipse.swt.widgets.Composite;
17
import org.eclipse.swt.widgets.Composite;
17
import org.eclipse.ui.PlatformUI;
18
import org.eclipse.ui.PlatformUI;
18
import org.eclipse.ui.forms.IManagedForm;
19
import org.eclipse.ui.forms.IManagedForm;
19
import org.eclipse.ui.forms.editor.FormEditor;
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
/**
24
 * @author Bartosz Michalik
25
 */
23
public class ConfigurationPage extends PDEFormPage {
26
public class ConfigurationPage extends PDEFormPage {
24
25
	public static final String PLUGIN_ID = "plugin-configuration"; //$NON-NLS-1$
27
	public static final String PLUGIN_ID = "plugin-configuration"; //$NON-NLS-1$
26
	public static final String FEATURE_ID = "feature-configuration"; //$NON-NLS-1$
27
28
	private boolean fUseFeatures;
29
	private PluginSection fPluginSection = null;
30
31
	public ConfigurationPage(FormEditor editor, boolean useFeatures) {
32
		super(editor, useFeatures ? FEATURE_ID : PLUGIN_ID, PDEUIMessages.Product_ConfigurationPage_title);
33
		fUseFeatures = useFeatures;
34
	}
35
28
36
	/* (non-Javadoc)
29
	/**
37
	 * @see org.eclipse.pde.internal.ui.editor.PDEFormPage#getHelpResource()
30
	 * @param productEditor
31
	 * @param useFeatures
38
	 */
32
	 */
39
	protected String getHelpResource() {
33
	public ConfigurationPage(ProductEditor editor, boolean useFeatures) {
40
		return IPDEUIConstants.PLUGIN_DOC_ROOT + "guide/tools/editors/product_editor/configuration.htm"; //$NON-NLS-1$
34
		super(editor, PLUGIN_ID, PDEUIMessages.ConfigurationPageMock_pageTitle);
41
	}
35
	}
42
36
43
	/* (non-Javadoc)
37
	/* (non-Javadoc)
Lines 48-71 Link Here
48
		ScrolledForm form = managedForm.getForm();
42
		ScrolledForm form = managedForm.getForm();
49
		FormToolkit toolkit = managedForm.getToolkit();
43
		FormToolkit toolkit = managedForm.getToolkit();
50
		form.setImage(PDEPlugin.getDefault().getLabelProvider().get(PDEPluginImages.DESC_FEATURE_OBJ));
44
		form.setImage(PDEPlugin.getDefault().getLabelProvider().get(PDEPluginImages.DESC_FEATURE_OBJ));
51
		form.setText(PDEUIMessages.Product_ConfigurationPage_title);
45
		form.setText(PDEUIMessages.ConfigurationPageMock_pageTitle);
52
		fillBody(managedForm, toolkit);
46
		fillBody(managedForm, toolkit);
53
		PlatformUI.getWorkbench().getHelpSystem().setHelp(form.getBody(), IHelpContextIds.CONFIGURATION_PAGE);
47
		PlatformUI.getWorkbench().getHelpSystem().setHelp(form.getBody(), IHelpContextIds.CONFIGURATION_PAGE);
54
	}
48
	}
55
49
56
	private void fillBody(IManagedForm managedForm, FormToolkit toolkit) {
50
	private void fillBody(IManagedForm managedForm, FormToolkit toolkit) {
57
		Composite body = managedForm.getForm().getBody();
51
		Composite body = managedForm.getForm().getBody();
58
		body.setLayout(FormLayoutFactory.createFormGridLayout(false, 1));
52
		body.setLayout(FormLayoutFactory.createFormGridLayout(false, 2));
59
53
		managedForm.addPart(new PluginConfigurationSection(this, body));
60
		// sections
61
		if (fUseFeatures)
62
			managedForm.addPart(new FeatureSection(this, body));
63
		else
64
			managedForm.addPart(fPluginSection = new PluginSection(this, body));
65
		managedForm.addPart(new ConfigurationSection(this, body));
54
		managedForm.addPart(new ConfigurationSection(this, body));
66
	}
55
	}
67
68
	public boolean includeOptionalDependencies() {
69
		return (fPluginSection != null) ? fPluginSection.includeOptionalDependencies() : false;
70
	}
71
}
56
}
(-)src/org/eclipse/pde/internal/ui/editor/product/ProductInfoSection.java (-2 / +2 lines)
Lines 307-313 Link Here
307
			}
307
			}
308
308
309
			public void linkActivated(HyperlinkEvent e) {
309
			public void linkActivated(HyperlinkEvent e) {
310
				String pageId = fPluginButton.getSelection() ? ConfigurationPage.PLUGIN_ID : ConfigurationPage.FEATURE_ID;
310
				String pageId = fPluginButton.getSelection() ? DependenciesPage.PLUGIN_ID : DependenciesPage.FEATURE_ID;
311
				getPage().getEditor().setActivePage(pageId);
311
				getPage().getEditor().setActivePage(pageId);
312
			}
312
			}
313
		});
313
		});
Lines 447-453 Link Here
447
		// If the current page is the configuration page, switch to the 
447
		// If the current page is the configuration page, switch to the 
448
		// overview page before doing the update; otherwise, widget disposed
448
		// overview page before doing the update; otherwise, widget disposed
449
		// errors may result
449
		// errors may result
450
		if (currentPage instanceof ConfigurationPage) {
450
		if (currentPage instanceof DependenciesPage) {
451
			getPage().getEditor().setActivePage(OverviewPage.PAGE_ID);
451
			getPage().getEditor().setActivePage(OverviewPage.PAGE_ID);
452
		}
452
		}
453
		((ProductEditor) getPage().getEditor()).updateConfigurationPage();
453
		((ProductEditor) getPage().getEditor()).updateConfigurationPage();
(-)src/org/eclipse/pde/internal/ui/pderesources.properties (-1 / +4 lines)
Lines 535-540 Link Here
535
ConfigurationSection_default=Generate a default config.ini file
535
ConfigurationSection_default=Generate a default config.ini file
536
ConfigurationSection_browse=Browse...
536
ConfigurationSection_browse=Browse...
537
ConfigurationAreaBlock_name=configuration area location
537
ConfigurationAreaBlock_name=configuration area location
538
ConfigurationPageMock_pageTitle=Configuration
539
ConfigurationPageMock_sectionTitle=Plug-ins
540
ConfigurationPageMock_sectionDesc=Specify plug-ins and their associated start levels.
538
ConfigurationSection_message=Select a config.ini file:
541
ConfigurationSection_message=Select a config.ini file:
539
ConfigurationTemplateBlock_name=template file location
542
ConfigurationTemplateBlock_name=template file location
540
ConfigurationTab_fileSelection=File Selection
543
ConfigurationTab_fileSelection=File Selection
Lines 1866-1872 Link Here
1866
ProductExportWizardPage_browse=Bro&wse...
1869
ProductExportWizardPage_browse=Bro&wse...
1867
Product_PluginSection_removeAll=Remove All
1870
Product_PluginSection_removeAll=Remove All
1868
Product_PluginSection_newPlugin=New Plug-in...
1871
Product_PluginSection_newPlugin=New Plug-in...
1869
Product_ConfigurationPage_title=Configuration
1872
Product_DependenciesPage_title=Dependencies
1870
ProductFileWizadPage_groupTitle=Initialize the file content
1873
ProductFileWizadPage_groupTitle=Initialize the file content
1871
Product_PluginSection_newFragment=New Fragment...
1874
Product_PluginSection_newFragment=New Fragment...
1872
Product_overview_testing=<form>\
1875
Product_overview_testing=<form>\
(-)src/org/eclipse/pde/internal/ui/PDEUIMessages.java (-1 / +4 lines)
Lines 2110-2116 Link Here
2110
	public static String ProductExportWizardPage_browse;
2110
	public static String ProductExportWizardPage_browse;
2111
	public static String Product_PluginSection_removeAll;
2111
	public static String Product_PluginSection_removeAll;
2112
	public static String Product_PluginSection_newPlugin;
2112
	public static String Product_PluginSection_newPlugin;
2113
	public static String Product_ConfigurationPage_title;
2113
	public static String Product_DependenciesPage_title;
2114
	public static String ProductFileWizadPage_groupTitle;
2114
	public static String ProductFileWizadPage_groupTitle;
2115
	public static String Product_PluginSection_newFragment;
2115
	public static String Product_PluginSection_newFragment;
2116
	public static String Product_overview_testing;
2116
	public static String Product_overview_testing;
Lines 2416-2421 Link Here
2416
	public static String WorkspaceDataBlock_name;
2416
	public static String WorkspaceDataBlock_name;
2417
2417
2418
	public static String ConfigurationAreaBlock_name;
2418
	public static String ConfigurationAreaBlock_name;
2419
	public static String ConfigurationPageMock_pageTitle;
2420
	public static String ConfigurationPageMock_sectionTitle;
2421
	public static String ConfigurationPageMock_sectionDesc;
2419
2422
2420
	public static String AbstractPluginBlock_counter;
2423
	public static String AbstractPluginBlock_counter;
2421
2424
(-)src/org/eclipse/pde/internal/ui/editor/product/PluginConfigurationSection.java (+393 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Bartosz Michalik 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)
11
 *******************************************************************************/
12
package org.eclipse.pde.internal.ui.editor.product;
13
14
import java.util.ArrayList;
15
import org.eclipse.jface.util.Util;
16
import org.eclipse.jface.viewers.*;
17
import org.eclipse.jface.window.Window;
18
import org.eclipse.pde.core.IModelChangedEvent;
19
import org.eclipse.pde.core.plugin.IFragmentModel;
20
import org.eclipse.pde.core.plugin.PluginRegistry;
21
import org.eclipse.pde.internal.core.iproduct.*;
22
import org.eclipse.pde.internal.ui.*;
23
import org.eclipse.pde.internal.ui.editor.PDEFormPage;
24
import org.eclipse.pde.internal.ui.editor.TableSection;
25
import org.eclipse.pde.internal.ui.parts.TablePart;
26
import org.eclipse.swt.SWT;
27
import org.eclipse.swt.custom.CCombo;
28
import org.eclipse.swt.custom.TableEditor;
29
import org.eclipse.swt.events.*;
30
import org.eclipse.swt.graphics.Image;
31
import org.eclipse.swt.layout.GridData;
32
import org.eclipse.swt.widgets.*;
33
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
34
import org.eclipse.ui.forms.widgets.FormToolkit;
35
import org.eclipse.ui.forms.widgets.Section;
36
37
public class PluginConfigurationSection extends TableSection {
38
39
	private class ContentProvider implements IStructuredContentProvider {
40
41
		private IProduct fProduct;
42
43
		ContentProvider() {
44
		}
45
46
		/* (non-Javadoc)
47
		 * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
48
		 */
49
		public Object[] getElements(Object inputElement) {
50
			return fProduct.getPluginConfigurations();
51
		}
52
53
		/* (non-Javadoc)
54
		 * @see org.eclipse.jface.viewers.IContentProvider#dispose()
55
		 */
56
		public void dispose() {
57
58
		}
59
60
		/* (non-Javadoc)
61
		 * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
62
		 */
63
		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
64
			if (oldInput == newInput)
65
				return;
66
			fProduct = (IProduct) newInput;
67
			//TODO refresh
68
		}
69
70
	}
71
72
	private class LabelProvider extends PDELabelProvider {
73
74
		public Image getColumnImage(Object obj, int index) {
75
			if (index == 0)
76
				return super.getColumnImage(PluginRegistry.findModel(((IPluginConfiguration) obj).getId()), index);
77
			return null;
78
		}
79
80
		public String getColumnText(Object obj, int index) {
81
			IPluginConfiguration configuration = (IPluginConfiguration) obj;
82
			switch (index) {
83
				case 0 :
84
					return configuration.getId();
85
					//return super.getColumnText(PluginRegistry.findModel(configuration.getId()), index);
86
				case 1 :
87
					return Integer.toString(configuration.getStartLevel());
88
				case 2 :
89
					return Boolean.toString(configuration.isAutoStart());
90
			}
91
			return null;
92
		}
93
94
	}
95
96
	private TableViewer fConfigurationsTable;
97
	private TableEditor fLevelColumnEditor;
98
	private TableEditor fAutoColumnEditor;
99
100
	private IStructuredSelection fLastSelection = null;
101
102
	/**
103
	 * @param page
104
	 * @param parent
105
	 */
106
	public PluginConfigurationSection(PDEFormPage page, Composite parent) {
107
		super(page, parent, Section.DESCRIPTION, getButtonLabels());
108
	}
109
110
	private static String[] getButtonLabels() {
111
		String[] labels = new String[3];
112
		labels[0] = PDEUIMessages.Product_PluginSection_add;
113
		labels[1] = PDEUIMessages.PluginSection_remove;
114
		labels[2] = PDEUIMessages.Product_PluginSection_removeAll;
115
		return labels;
116
	}
117
118
	/* (non-Javadoc)
119
	 * @see org.eclipse.pde.internal.ui.editor.PDESection#createClient(org.eclipse.ui.forms.widgets.Section, org.eclipse.ui.forms.widgets.FormToolkit)
120
	 */
121
	protected void createClient(Section section, FormToolkit toolkit) {
122
		section.setText(PDEUIMessages.ConfigurationPageMock_sectionTitle);
123
		section.setDescription(PDEUIMessages.ConfigurationPageMock_sectionDesc);
124
		GridData sectionData = new GridData(SWT.FILL, SWT.FILL, true, true);
125
		sectionData.horizontalSpan = 2;
126
		section.setLayoutData(sectionData);
127
		Composite container = createClientContainer(section, 3, toolkit);
128
		createViewerPartControl(container, SWT.SINGLE, 3, toolkit);
129
		fConfigurationsTable = getTablePart().getTableViewer();
130
131
		final Table table = fConfigurationsTable.getTable();
132
		final TableColumn column1 = new TableColumn(table, SWT.LEFT);
133
		column1.setText(PDEUIMessages.ConfigurationPageMock_sectionTitle);
134
		column1.setWidth(300);
135
136
		final TableColumn column2 = new TableColumn(table, SWT.CENTER);
137
		column2.setText(PDEUIMessages.EquinoxPluginBlock_levelColumn);
138
139
		final TableColumn column3 = new TableColumn(table, SWT.CENTER);
140
		column3.setText(PDEUIMessages.EquinoxPluginBlock_autoColumn);
141
142
		table.addControlListener(new ControlListener() {
143
144
			public void controlMoved(ControlEvent e) {
145
			}
146
147
			public void controlResized(ControlEvent e) {
148
				int size = table.getSize().x;
149
				column1.setWidth(size / 7 * 4);
150
				column2.setWidth(size / 7 * 2);
151
				column3.setWidth(size / 7 * 1);
152
			}
153
154
		});
155
156
		table.setHeaderVisible(true);
157
		toolkit.paintBordersFor(container);
158
		fConfigurationsTable.setLabelProvider(getLabelProvider());
159
		fConfigurationsTable.setContentProvider(new ContentProvider());
160
		fConfigurationsTable.setInput(getProduct());
161
		createEditors();
162
163
		section.setClient(container);
164
		getModel().addModelChangedListener(this);
165
		updateRemoveButtons(true, true);
166
	}
167
168
	protected void buttonSelected(int index) {
169
		switch (index) {
170
			case 0 :
171
				handleAdd();
172
				break;
173
			case 1 :
174
				handleRemove();
175
				break;
176
			case 2 :
177
				handleRemoveAll();
178
				break;
179
		}
180
	}
181
182
	private void handleAdd() {
183
		ElementListSelectionDialog dialog = new ElementListSelectionDialog(PDEPlugin.getActiveWorkbenchShell(), PDEPlugin.getDefault().getLabelProvider());
184
		IProductPlugin[] allPlugins = getProduct().getPlugins();
185
		IPluginConfiguration[] configs = getProduct().getPluginConfigurations();
186
		ArrayList filtered = new ArrayList();
187
		for (int i = 0; i < allPlugins.length; ++i) {
188
			boolean match = false;
189
			for (int j = 0; j < configs.length; ++j) {
190
				String id = allPlugins[i].getId();
191
				if (PluginRegistry.findModel(id) instanceof IFragmentModel || id.equals(configs[j].getId())) {
192
					match = true;
193
					break;
194
				}
195
			}
196
			if (!match) {
197
				filtered.add(allPlugins[i]);
198
			}
199
		}
200
		dialog.setElements(filtered.toArray(new IProductPlugin[filtered.size()]));
201
		dialog.setTitle(PDEUIMessages.PluginSelectionDialog_title);
202
		dialog.setMessage(PDEUIMessages.PluginSelectionDialog_message);
203
		dialog.setMultipleSelection(true);
204
		if (dialog.open() == Window.OK) {
205
			Object[] plugins = dialog.getResult();
206
			for (int i = 0; i < plugins.length; i++) {
207
				addPlugin(((IProductPlugin) plugins[i]).getId());
208
			}
209
		}
210
211
	}
212
213
	private void handleRemove() {
214
		IStructuredSelection ssel = (IStructuredSelection) fConfigurationsTable.getSelection();
215
		if (ssel.size() > 0) {
216
			Object[] objects = ssel.toArray();
217
			IPluginConfiguration[] configurations = new IPluginConfiguration[objects.length];
218
			System.arraycopy(objects, 0, configurations, 0, objects.length);
219
			getProduct().removePluginConfigurations(configurations);
220
		}
221
	}
222
223
	private void handleRemoveAll() {
224
		IProduct product = getProduct();
225
		product.removePluginConfigurations(product.getPluginConfigurations());
226
227
	}
228
229
	protected void handleDoubleClick(IStructuredSelection selection) {
230
		// Clean up any previous editor control
231
		clearEditors();
232
233
		if (!selection.isEmpty()) {
234
			Table table = fConfigurationsTable.getTable();
235
			final IPluginConfiguration ppc = (IPluginConfiguration) selection.getFirstElement();
236
			final TableItem item = table.getSelection()[0];
237
			final Spinner spinner = new Spinner(table, SWT.BORDER);
238
239
			spinner.setMinimum(0);
240
			String level = item.getText(1);
241
			int defaultLevel = level.length() == 0 || "default".equals(level) ? 0 : Integer.parseInt(level); //$NON-NLS-1$
242
			spinner.setSelection(defaultLevel);
243
			spinner.addModifyListener(new ModifyListener() {
244
				public void modifyText(ModifyEvent e) {
245
					int selection = spinner.getSelection();
246
					item.setText(1, selection == 0 ? "default" //$NON-NLS-1$
247
							: Integer.toString(selection));
248
					ppc.setStartLevel(selection);
249
				}
250
			});
251
			fLevelColumnEditor.setEditor(spinner, item, 1);
252
253
			final CCombo combo = new CCombo(table, SWT.BORDER | SWT.READ_ONLY);
254
			//TODO is there need for the default options ??
255
			combo.setItems(new String[] {Boolean.toString(true), Boolean.toString(false)});
256
			combo.setText(item.getText(2));
257
			combo.pack();
258
			combo.addSelectionListener(new SelectionAdapter() {
259
				public void widgetSelected(SelectionEvent e) {
260
					item.setText(2, combo.getText());
261
					ppc.setAutoStart(Boolean.getBoolean(combo.getText()));
262
				}
263
			});
264
			fAutoColumnEditor.setEditor(combo, item, 2);
265
		}
266
	}
267
268
	protected void selectionChanged(IStructuredSelection selection) {
269
		if (selection == null || !selection.equals(fLastSelection)) {
270
			clearEditors();
271
		}
272
		updateRemoveButtons(true, false);
273
274
	}
275
276
	private void addPlugin(String id) {
277
		IProduct product = getProduct();
278
		IProductModelFactory factory = product.getModel().getFactory();
279
		IPluginConfiguration configuration = factory.createPluginConfiguration();
280
		configuration.setId(id);
281
		product.addPluginConfigurations(new IPluginConfiguration[] {configuration});
282
		fConfigurationsTable.setSelection(new StructuredSelection(configuration));
283
	}
284
285
	private ILabelProvider getLabelProvider() {
286
		return new LabelProvider();
287
	}
288
289
	private void clearEditors() {
290
		Control oldEditor = fLevelColumnEditor.getEditor();
291
		if (oldEditor != null && !oldEditor.isDisposed())
292
			oldEditor.dispose();
293
294
		oldEditor = fAutoColumnEditor.getEditor();
295
		if (oldEditor != null && !oldEditor.isDisposed())
296
			oldEditor.dispose();
297
	}
298
299
	private void createEditors() {
300
		final Table table = fConfigurationsTable.getTable();
301
302
		fLevelColumnEditor = new TableEditor(table);
303
		fLevelColumnEditor.horizontalAlignment = SWT.CENTER;
304
		fLevelColumnEditor.minimumWidth = 40;
305
		if (Util.isMac())
306
			fLevelColumnEditor.minimumHeight = 27;
307
308
		fAutoColumnEditor = new TableEditor(table);
309
		fAutoColumnEditor.horizontalAlignment = SWT.CENTER;
310
		fAutoColumnEditor.grabHorizontal = true;
311
		fAutoColumnEditor.minimumWidth = 50;
312
	}
313
314
	private IProduct getProduct() {
315
		return getModel().getProduct();
316
	}
317
318
	private IProductModel getModel() {
319
		return (IProductModel) getPage().getPDEEditor().getAggregateModel();
320
	}
321
322
	/* (non-Javadoc)
323
	 * @see org.eclipse.pde.internal.core.IPluginModelListener#modelsChanged(org.eclipse.pde.internal.core.PluginModelDelta)
324
	 */
325
	public void modelChanged(IModelChangedEvent e) {
326
		//TODO update modelChanged method
327
		// No need to call super, handling world changed event here
328
		if (e.getChangeType() == IModelChangedEvent.WORLD_CHANGED) {
329
			handleGlobalRefresh();
330
			return;
331
		}
332
		Table table = fConfigurationsTable.getTable();
333
		int count = table.getItemCount();
334
		Object[] objects = e.getChangedObjects();
335
		boolean refreshRemove = false;
336
		boolean refreshRemoveAll = false;
337
		if (e.getChangeType() == IModelChangedEvent.INSERT) {
338
			if (count == 0) {
339
				refreshRemoveAll = true;
340
			}
341
			for (int i = 0; i < objects.length; i++) {
342
				if (objects[i] instanceof IPluginConfiguration)
343
					fConfigurationsTable.add(objects[i]);
344
			}
345
		} else if (e.getChangeType() == IModelChangedEvent.REMOVE) {
346
			refreshRemove = refreshRemoveAll = true;
347
			int index = table.getSelectionIndex();
348
			boolean global = false;
349
			for (int i = 0; i < objects.length; i++) {
350
				if (objects[i] instanceof IPluginConfiguration)
351
					fConfigurationsTable.remove(objects[i]);
352
				else if (objects[i] instanceof IProductPlugin) {
353
					global = true;
354
					break;
355
				}
356
			}
357
358
			if (global)
359
				handleGlobalRefresh();
360
361
			// Update Selection
362
363
			if (count == 0) {
364
				table.deselectAll();
365
				clearEditors();
366
			} else if (index < count) {
367
				table.setSelection(index);
368
			} else {
369
				table.setSelection(count - 1);
370
			}
371
372
		}
373
		updateRemoveButtons(refreshRemove, refreshRemoveAll);
374
375
	}
376
377
	private void handleGlobalRefresh() {
378
		fConfigurationsTable.setInput(getProduct());
379
		fConfigurationsTable.refresh();
380
	}
381
382
	private void updateRemoveButtons(boolean updateRemove, boolean updateRemoveAll) {
383
		TablePart tablePart = getTablePart();
384
		if (updateRemove) {
385
			ISelection selection = getViewerSelection();
386
			tablePart.setButtonEnabled(1, isEditable() && !selection.isEmpty());
387
		}
388
		int count = fConfigurationsTable.getTable().getItemCount();
389
		if (updateRemoveAll)
390
			tablePart.setButtonEnabled(2, isEditable() && count > 0);
391
	}
392
393
}
(-)src/org/eclipse/pde/internal/ui/editor/product/DependenciesPage.java (+70 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Code 9 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
 *     Code 9 Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.editor.product;
12
13
import org.eclipse.pde.internal.ui.*;
14
import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
15
import org.eclipse.pde.internal.ui.editor.PDEFormPage;
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.FormEditor;
20
import org.eclipse.ui.forms.widgets.FormToolkit;
21
import org.eclipse.ui.forms.widgets.ScrolledForm;
22
23
public class DependenciesPage extends PDEFormPage {
24
25
	public static final String PLUGIN_ID = "plugin-configuration"; //$NON-NLS-1$
26
	public static final String FEATURE_ID = "feature-configuration"; //$NON-NLS-1$
27
28
	private boolean fUseFeatures;
29
	private PluginSection fPluginSection = null;
30
31
	public DependenciesPage(FormEditor editor, boolean useFeatures) {
32
		super(editor, useFeatures ? FEATURE_ID : PLUGIN_ID, PDEUIMessages.Product_DependenciesPage_title);
33
		fUseFeatures = useFeatures;
34
	}
35
36
	/* (non-Javadoc)
37
	 * @see org.eclipse.pde.internal.ui.editor.PDEFormPage#getHelpResource()
38
	 */
39
	protected String getHelpResource() {
40
		return IPDEUIConstants.PLUGIN_DOC_ROOT + "guide/tools/editors/product_editor/configuration.htm"; //$NON-NLS-1$
41
	}
42
43
	/* (non-Javadoc) 
44
	 * @see org.eclipse.pde.internal.ui.editor.PDEFormPage#createFormContent(org.eclipse.ui.forms.IManagedForm)
45
	 */
46
	protected void createFormContent(IManagedForm managedForm) {
47
		super.createFormContent(managedForm);
48
		ScrolledForm form = managedForm.getForm();
49
		FormToolkit toolkit = managedForm.getToolkit();
50
		form.setImage(PDEPlugin.getDefault().getLabelProvider().get(PDEPluginImages.DESC_REQ_PLUGINS_OBJ));
51
		form.setText(PDEUIMessages.Product_DependenciesPage_title);
52
		fillBody(managedForm, toolkit);
53
		PlatformUI.getWorkbench().getHelpSystem().setHelp(form.getBody(), IHelpContextIds.CONFIGURATION_PAGE);
54
	}
55
56
	private void fillBody(IManagedForm managedForm, FormToolkit toolkit) {
57
		Composite body = managedForm.getForm().getBody();
58
		body.setLayout(FormLayoutFactory.createFormGridLayout(false, 1));
59
60
		// sections
61
		if (fUseFeatures)
62
			managedForm.addPart(new FeatureSection(this, body));
63
		else
64
			managedForm.addPart(fPluginSection = new PluginSection(this, body));
65
	}
66
67
	public boolean includeOptionalDependencies() {
68
		return (fPluginSection != null) ? fPluginSection.includeOptionalDependencies() : false;
69
	}
70
}
(-)src/org/eclipse/pde/internal/core/product/WorkspaceProductModel.java (-1 / +1 lines)
Lines 124-130 Link Here
124
	public void save(PrintWriter writer) {
124
	public void save(PrintWriter writer) {
125
		if (isLoaded()) {
125
		if (isLoaded()) {
126
			writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); //$NON-NLS-1$
126
			writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); //$NON-NLS-1$
127
			writer.println("<?pde version=\"3.4\"?>"); //$NON-NLS-1$
127
			writer.println("<?pde version=\"3.5\"?>"); //$NON-NLS-1$
128
			writer.println();
128
			writer.println();
129
			getProduct().write("", writer); //$NON-NLS-1$
129
			getProduct().write("", writer); //$NON-NLS-1$
130
		}
130
		}
(-)src/org/eclipse/pde/internal/core/product/Product.java (-3 / +91 lines)
Lines 26-31 Link Here
26
	private IAboutInfo fAboutInfo;
26
	private IAboutInfo fAboutInfo;
27
27
28
	private TreeMap fPlugins = new TreeMap();
28
	private TreeMap fPlugins = new TreeMap();
29
	private TreeMap fPluginConfigurations = new TreeMap();
29
	private List fFeatures = new ArrayList();
30
	private List fFeatures = new ArrayList();
30
	private IConfigurationFileInfo fConfigIniInfo;
31
	private IConfigurationFileInfo fConfigIniInfo;
31
	private IJREInfo fJVMInfo;
32
	private IJREInfo fJVMInfo;
Lines 202-207 Link Here
202
		}
203
		}
203
204
204
		writer.println();
205
		writer.println();
206
207
		writer.println(indent + "   <configurations>"); //$NON-NLS-1$  
208
		iter = fPluginConfigurations.values().iterator();
209
		while (iter.hasNext()) {
210
			IPluginConfiguration configuration = (IPluginConfiguration) iter.next();
211
			configuration.write(indent + "      ", writer); //$NON-NLS-1$
212
		}
213
		writer.println(indent + "   </configurations>"); //$NON-NLS-1$
214
215
		writer.println();
205
		writer.println("</product>"); //$NON-NLS-1$
216
		writer.println("</product>"); //$NON-NLS-1$
206
	}
217
	}
207
218
Lines 222-227 Link Here
222
		fUseFeatures = false;
233
		fUseFeatures = false;
223
		fAboutInfo = null;
234
		fAboutInfo = null;
224
		fPlugins.clear();
235
		fPlugins.clear();
236
		fPluginConfigurations.clear();
225
		fFeatures.clear();
237
		fFeatures.clear();
226
		fConfigIniInfo = null;
238
		fConfigIniInfo = null;
227
		fWindowImages = null;
239
		fWindowImages = null;
Lines 256-261 Link Here
256
						parsePlugins(child.getChildNodes());
268
						parsePlugins(child.getChildNodes());
257
					} else if (name.equals("features")) { //$NON-NLS-1$
269
					} else if (name.equals("features")) { //$NON-NLS-1$
258
						parseFeatures(child.getChildNodes());
270
						parseFeatures(child.getChildNodes());
271
					} else if (name.equals("configurations")) { //$NON-NLS-1$
272
						parsePluginConfigurations(child.getChildNodes());
259
					} else if (name.equals("configIni")) { //$NON-NLS-1$
273
					} else if (name.equals("configIni")) { //$NON-NLS-1$
260
						fConfigIniInfo = factory.createConfigFileInfo();
274
						fConfigIniInfo = factory.createConfigFileInfo();
261
						fConfigIniInfo.parse(child);
275
						fConfigIniInfo.parse(child);
Lines 296-301 Link Here
296
		}
310
		}
297
	}
311
	}
298
312
313
	private void parsePluginConfigurations(NodeList children) {
314
		for (int i = 0; i < children.getLength(); i++) {
315
			Node child = children.item(i);
316
			if (child.getNodeType() == Node.ELEMENT_NODE) {
317
				if (child.getNodeName().equals("pluginConfiguration")) { //$NON-NLS-1$
318
					IPluginConfiguration configuration = getModel().getFactory().createPluginConfiguration();
319
					configuration.parse(child);
320
					fPluginConfigurations.put(configuration.getId(), configuration);
321
				}
322
			}
323
		}
324
	}
325
299
	private void parseFeatures(NodeList children) {
326
	private void parseFeatures(NodeList children) {
300
		for (int i = 0; i < children.getLength(); i++) {
327
		for (int i = 0; i < children.getLength(); i++) {
301
			Node child = children.item(i);
328
			Node child = children.item(i);
Lines 332-347 Link Here
332
	}
359
	}
333
360
334
	/* (non-Javadoc)
361
	/* (non-Javadoc)
362
	 * @see org.eclipse.pde.internal.core.iproduct.IProduct#addPluginConfigurations(org.eclipse.pde.internal.core.iproduct.IPluginConfiguration[])
363
	 */
364
	public void addPluginConfigurations(IPluginConfiguration[] configuration) {
365
		boolean modified = false;
366
		for (int i = 0; i < configuration.length; i++) {
367
			if (configuration[i] == null)
368
				continue;
369
			String id = configuration[i].getId();
370
			if (id == null || fPluginConfigurations.containsKey(id)) {
371
				configuration[i] = null;
372
				continue;
373
			}
374
375
			configuration[i].setModel(getModel());
376
			fPluginConfigurations.put(id, configuration[i]);
377
			modified = true;
378
		}
379
		if (modified && isEditable())
380
			fireStructureChanged(configuration, IModelChangedEvent.INSERT);
381
	}
382
383
	/* (non-Javadoc)
335
	 * @see org.eclipse.pde.internal.core.iproduct.IProduct#removePlugins(org.eclipse.pde.internal.core.iproduct.IProductPlugin[])
384
	 * @see org.eclipse.pde.internal.core.iproduct.IProduct#removePlugins(org.eclipse.pde.internal.core.iproduct.IProductPlugin[])
336
	 */
385
	 */
337
	public void removePlugins(IProductPlugin[] plugins) {
386
	public void removePlugins(IProductPlugin[] plugins) {
338
		boolean modified = false;
387
		boolean modified = false;
388
		LinkedList removedConfigurations = new LinkedList();
339
		for (int i = 0; i < plugins.length; i++) {
389
		for (int i = 0; i < plugins.length; i++) {
340
			if (fPlugins.remove(plugins[i].getId()) != null)
390
			final String id = plugins[i].getId();
391
			if (fPlugins.remove(id) != null) {
341
				modified = true;
392
				modified = true;
393
				Object configuration = fPluginConfigurations.remove(id);
394
				if (configuration != null)
395
					removedConfigurations.add(configuration);
396
			}
342
		}
397
		}
343
		if (modified && isEditable())
398
		if (isEditable()) {
344
			fireStructureChanged(plugins, IModelChangedEvent.REMOVE);
399
			if (modified)
400
				fireStructureChanged(plugins, IModelChangedEvent.REMOVE);
401
			if (!removedConfigurations.isEmpty()) {
402
				fireStructureChanged((IProductObject[]) removedConfigurations.toArray(new IProductObject[removedConfigurations.size()]), IModelChangedEvent.REMOVE);
403
			}
404
		}
405
	}
406
407
	/* (non-Javadoc)
408
	 * @see org.eclipse.pde.internal.core.iproduct.IProduct#removePluginConfigurations(org.eclipse.pde.internal.core.iproduct.IProductPluginConfiguration[])
409
	 */
410
	public void removePluginConfigurations(IPluginConfiguration[] configurations) {
411
		boolean modified = false;
412
		for (int i = 0; i < configurations.length; i++) {
413
			if (fPluginConfigurations.remove(configurations[i].getId()) != null) {
414
				modified = true;
415
			}
416
		}
417
		if (isEditable() && modified)
418
			fireStructureChanged(configurations, IModelChangedEvent.REMOVE);
345
	}
419
	}
346
420
347
	/* (non-Javadoc)
421
	/* (non-Javadoc)
Lines 352-357 Link Here
352
	}
426
	}
353
427
354
	/* (non-Javadoc)
428
	/* (non-Javadoc)
429
	 * @see org.eclipse.pde.internal.core.iproduct.IProduct#getPluginConfigurations()
430
	 */
431
	public IPluginConfiguration[] getPluginConfigurations() {
432
		return (IPluginConfiguration[]) fPluginConfigurations.values().toArray(new IPluginConfiguration[fPluginConfigurations.size()]);
433
	}
434
435
	/* (non-Javadoc)
355
	 * @see org.eclipse.pde.internal.core.iproduct.IProduct#getConfigurationFileInfo()
436
	 * @see org.eclipse.pde.internal.core.iproduct.IProduct#getConfigurationFileInfo()
356
	 */
437
	 */
357
	public IConfigurationFileInfo getConfigurationFileInfo() {
438
	public IConfigurationFileInfo getConfigurationFileInfo() {
Lines 485-488 Link Here
485
		fireStructureChanged(feature1, IModelChangedEvent.CHANGE);
566
		fireStructureChanged(feature1, IModelChangedEvent.CHANGE);
486
	}
567
	}
487
568
569
	/* (non-Javadoc)
570
	 * @see org.eclipse.pde.internal.core.iproduct.IProduct#findPluginConfiguration(java.lang.String)
571
	 */
572
	public IPluginConfiguration findPluginConfiguration(String id) {
573
		return (IPluginConfiguration) fPluginConfigurations.get(id);
574
	}
575
488
}
576
}
(-)src/org/eclipse/pde/internal/core/product/ProductModelFactory.java (-14 / +9 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2007 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
Lines 10-28 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.core.product;
11
package org.eclipse.pde.internal.core.product;
12
12
13
import org.eclipse.pde.internal.core.iproduct.IAboutInfo;
13
import org.eclipse.pde.internal.core.iproduct.*;
14
import org.eclipse.pde.internal.core.iproduct.IArgumentsInfo;
15
import org.eclipse.pde.internal.core.iproduct.IConfigurationFileInfo;
16
import org.eclipse.pde.internal.core.iproduct.IIntroInfo;
17
import org.eclipse.pde.internal.core.iproduct.IJREInfo;
18
import org.eclipse.pde.internal.core.iproduct.ILauncherInfo;
19
import org.eclipse.pde.internal.core.iproduct.IProduct;
20
import org.eclipse.pde.internal.core.iproduct.IProductFeature;
21
import org.eclipse.pde.internal.core.iproduct.IProductModel;
22
import org.eclipse.pde.internal.core.iproduct.IProductModelFactory;
23
import org.eclipse.pde.internal.core.iproduct.IProductPlugin;
24
import org.eclipse.pde.internal.core.iproduct.ISplashInfo;
25
import org.eclipse.pde.internal.core.iproduct.IWindowImages;
26
14
27
public class ProductModelFactory implements IProductModelFactory {
15
public class ProductModelFactory implements IProductModelFactory {
28
16
Lines 54-59 Link Here
54
	}
42
	}
55
43
56
	/* (non-Javadoc)
44
	/* (non-Javadoc)
45
	 * @see org.eclipse.pde.internal.core.iproduct.IProductModelFactory#createPluginConfiguration()
46
	 */
47
	public IPluginConfiguration createPluginConfiguration() {
48
		return new PluginConfiguration(fModel);
49
	}
50
51
	/* (non-Javadoc)
57
	 * @see org.eclipse.pde.internal.core.iproduct.IProductModelFactory#createConfigFileInfo()
52
	 * @see org.eclipse.pde.internal.core.iproduct.IProductModelFactory#createConfigFileInfo()
58
	 */
53
	 */
59
	public IConfigurationFileInfo createConfigFileInfo() {
54
	public IConfigurationFileInfo createConfigFileInfo() {
(-)src/org/eclipse/pde/internal/core/iproduct/IProductModelFactory.java (+2 lines)
Lines 18-23 Link Here
18
18
19
	IProductPlugin createPlugin();
19
	IProductPlugin createPlugin();
20
20
21
	IPluginConfiguration createPluginConfiguration();
22
21
	IProductFeature createFeature();
23
	IProductFeature createFeature();
22
24
23
	IConfigurationFileInfo createConfigFileInfo();
25
	IConfigurationFileInfo createConfigFileInfo();
(-)src/org/eclipse/pde/internal/core/iproduct/IProduct.java (+8 lines)
Lines 52-65 Link Here
52
52
53
	void addFeatures(IProductFeature[] feature);
53
	void addFeatures(IProductFeature[] feature);
54
54
55
	void addPluginConfigurations(IPluginConfiguration[] configurations);
56
55
	void removePlugins(IProductPlugin[] plugins);
57
	void removePlugins(IProductPlugin[] plugins);
56
58
57
	void removeFeatures(IProductFeature[] feature);
59
	void removeFeatures(IProductFeature[] feature);
58
60
61
	void removePluginConfigurations(IPluginConfiguration[] configurations);
62
63
	IPluginConfiguration findPluginConfiguration(String id);
64
59
	IProductPlugin[] getPlugins();
65
	IProductPlugin[] getPlugins();
60
66
61
	IProductFeature[] getFeatures();
67
	IProductFeature[] getFeatures();
62
68
69
	IPluginConfiguration[] getPluginConfigurations();
70
63
	void setId(String id);
71
	void setId(String id);
64
72
65
	void setVersion(String version);
73
	void setVersion(String version);
(-)src/org/eclipse/pde/internal/core/iproduct/IPluginConfiguration.java (+53 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Bartosz Michalik 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)
11
 *******************************************************************************/
12
package org.eclipse.pde.internal.core.iproduct;
13
14
/**
15
 * PluginConfiguration description defines  plug-in start level, and other properties that can be used
16
 * during product launching/building    
17
 */
18
public interface IPluginConfiguration extends IProductObject {
19
	public static final String P_AUTO_START = "autostart"; //$NON-NLS-1$
20
	public static final String P_START_LEVEL = "startLevel"; //$NON-NLS-1$
21
22
	String getId();
23
24
	void setId(String id);
25
26
	void setAutoStart(boolean autostart);
27
28
	boolean isAutoStart();
29
30
	void setStartLevel(int startLevel);
31
32
	int getStartLevel();
33
34
	/**
35
	 * Adds property, if property exists is overridden 
36
	 * @param key
37
	 * @param value
38
	 * @throws IllegalArgumentException when key or value is empty
39
	 */
40
	void addProperty(String key, String value) throws IllegalArgumentException;
41
42
	/**
43
	 * @param key
44
	 */
45
	void removeProperty(String key);
46
47
	/** 
48
	 * get property from key
49
	 * @param key
50
	 * @return property or <code>null</code>
51
	 */
52
	String getProperty(String key);
53
}
(-)src/org/eclipse/pde/internal/core/product/PluginConfiguration.java (+164 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 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
 *     Bartosz Michalik (bartosz.michalik@gmail.com)
11
 *******************************************************************************/
12
package org.eclipse.pde.internal.core.product;
13
14
import java.io.PrintWriter;
15
import java.util.*;
16
import org.eclipse.pde.internal.core.iproduct.IProductModel;
17
import org.eclipse.pde.internal.core.iproduct.IPluginConfiguration;
18
import org.w3c.dom.*;
19
20
public class PluginConfiguration extends ProductObject implements IPluginConfiguration {
21
22
	private static final long serialVersionUID = -3549668957352554876L;
23
	private boolean fAutoStart;
24
	private int fStartLevel;
25
	private String fId;
26
	private Map fPropertiesMap;
27
28
	/**
29
	 * Only for parsing usage
30
	 * @param model
31
	 */
32
	PluginConfiguration(IProductModel model) {
33
		super(model);
34
		fPropertiesMap = new HashMap();
35
	}
36
37
	/* (non-Javadoc)
38
	 * @see org.eclipse.pde.internal.core.iproduct.IProductObject#parse(org.w3c.dom.Node)
39
	 */
40
	public void parse(Node node) {
41
		if (node.getNodeType() == Node.ELEMENT_NODE) {
42
			Element element = (Element) node;
43
			fId = element.getAttribute("id"); //$NON-NLS-1$
44
			fAutoStart = Boolean.getBoolean((element.getAttribute(P_AUTO_START)));
45
			fStartLevel = Integer.parseInt(element.getAttribute(P_START_LEVEL));
46
			NodeList children = node.getChildNodes();
47
			int length = children.getLength();
48
			for (int i = 0; i < length; ++i) {
49
				Node item = children.item(i);
50
				if (item.getNodeType() == Node.ELEMENT_NODE) {
51
					element = (Element) item;
52
					String key = element.getAttribute("key"); //$NON-NLS-1$
53
					String value = element.getAttribute("value"); //$NON-NLS-1$
54
					fPropertiesMap.put(key, value);
55
				}
56
			}
57
		}
58
59
	}
60
61
	/* (non-Javadoc)
62
	 * @see org.eclipse.pde.core.IWritable#write(java.lang.String, java.io.PrintWriter)
63
	 */
64
	public void write(String indent, PrintWriter writer) {
65
		writer.print(indent + "<pluginConfiguration id=\"" + fId + "\""); //$NON-NLS-1$ //$NON-NLS-2$
66
		writer.print(" autoStart=\"" + fAutoStart + "\""); //$NON-NLS-1$//$NON-NLS-2$
67
		writer.print(" startLevel=\"" + fStartLevel + "\""); //$NON-NLS-1$ //$NON-NLS-2$
68
		if (fPropertiesMap.isEmpty())
69
			writer.println(" />"); //$NON-NLS-1$
70
		else {
71
			writer.println(" >"); //$NON-NLS-1$
72
			Iterator i = fPropertiesMap.keySet().iterator();
73
			while (i.hasNext()) {
74
				String key = (String) i.next();
75
				writer.println(indent + "<property key=\"" + key + " value=\"" + fPropertiesMap.get(key) + "\" />"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
76
			}
77
			writer.println("</pluginConfiguration>"); //$NON-NLS-1$
78
		}
79
80
	}
81
82
	/* (non-Javadoc)
83
	 * @see org.eclipse.pde.internal.core.iproduct.IPluginConfiguration#addProperty(java.lang.String, java.lang.String)
84
	 */
85
	public void addProperty(String key, String value) throws IllegalArgumentException {
86
		if (key == null || key.equals("")) //$NON-NLS-1$
87
			throw new IllegalArgumentException("key cannot empty"); //$NON-NLS-1$
88
		if (value == null || value.equals("")) //$NON-NLS-1$
89
			throw new IllegalArgumentException("value cannot empty"); //$NON-NLS-1$
90
		String oldValue = (String) fPropertiesMap.get(key);
91
		fPropertiesMap.put(key, value);
92
		if (isEditable() && !value.equals(oldValue))
93
			firePropertyChanged(key, oldValue, value);
94
95
	}
96
97
	/* (non-Javadoc)
98
	 * @see org.eclipse.pde.internal.core.iproduct.IPluginConfiguration#getId()
99
	 */
100
	public String getId() {
101
		return fId;
102
	}
103
104
	/* (non-Javadoc)
105
	 * @see org.eclipse.pde.internal.core.iproduct.IPluginConfiguration#getProperty(java.lang.String)
106
	 */
107
	public String getProperty(String key) {
108
		return (String) fPropertiesMap.get(key);
109
	}
110
111
	/* (non-Javadoc)
112
	 * @see org.eclipse.pde.internal.core.iproduct.IPluginConfiguration#getStartLevel()
113
	 */
114
	public int getStartLevel() {
115
		return fStartLevel;
116
	}
117
118
	/* (non-Javadoc)
119
	 * @see org.eclipse.pde.internal.core.iproduct.IPluginConfiguration#isAutoStart()
120
	 */
121
	public boolean isAutoStart() {
122
		return fAutoStart;
123
	}
124
125
	/* (non-Javadoc)
126
	 * @see org.eclipse.pde.internal.core.iproduct.IPluginConfiguration#removeProperty(java.lang.String)
127
	 */
128
	public void removeProperty(String key) {
129
		String oldValue = (String) fPropertiesMap.get(key);
130
		fPropertiesMap.remove(key);
131
		if (isEditable() && oldValue != null)
132
			firePropertyChanged(key, oldValue, null);
133
134
	}
135
136
	/* (non-Javadoc)
137
	 * @see org.eclipse.pde.internal.core.iproduct.IPluginConfiguration#setAutoStart(boolean)
138
	 */
139
	public void setAutoStart(boolean autostart) {
140
		boolean oldValue = fAutoStart;
141
		fAutoStart = autostart;
142
		if (isEditable() && oldValue != fAutoStart)
143
			firePropertyChanged(P_AUTO_START, new Boolean(oldValue), new Boolean(fAutoStart));
144
145
	}
146
147
	/* (non-Javadoc)
148
	 * @see org.eclipse.pde.internal.core.iproduct.IPluginConfiguration#setStartLevel(java.lang.String)
149
	 */
150
	public void setStartLevel(int startLevel) {
151
		int oldValue = fStartLevel;
152
		fStartLevel = startLevel;
153
		if (isEditable() && oldValue != fStartLevel)
154
			firePropertyChanged(P_START_LEVEL, new Integer(oldValue), new Integer(fStartLevel));
155
	}
156
157
	/* (non-Javadoc)
158
	 * @see org.eclipse.pde.internal.core.iproduct.IProductPluginConfiguration#setId(java.lang.String)
159
	 */
160
	public void setId(String id) {
161
		fId = id;
162
	}
163
164
}

Return to bug 240737