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

Collapse All | Expand All

(-)src/org/eclipse/pde/internal/ui/PDEUIMessages.java (+1 lines)
Lines 2174-2179 Link Here
2174
2174
2175
	public static String ProductJRESection_title;
2175
	public static String ProductJRESection_title;
2176
	public static String ProductJRESection_desc;
2176
	public static String ProductJRESection_desc;
2177
	public static String ProductJRESection_none;
2177
	public static String ProductJRESection_jreName;
2178
	public static String ProductJRESection_jreName;
2178
	public static String ProductJRESection_eeName;
2179
	public static String ProductJRESection_eeName;
2179
	public static String ProductJRESection_browseJREs;
2180
	public static String ProductJRESection_browseJREs;
(-)src/org/eclipse/pde/internal/ui/pderesources.properties (+1 lines)
Lines 1982-1987 Link Here
1982
1982
1983
ProductJRESection_title=Java Runtime Environment
1983
ProductJRESection_title=Java Runtime Environment
1984
ProductJRESection_desc=Specify the JRE to be bundled with the product. Platform-specific JREs should be entered on their respective tabs.
1984
ProductJRESection_desc=Specify the JRE to be bundled with the product. Platform-specific JREs should be entered on their respective tabs.
1985
ProductJRESection_none=None
1985
ProductJRESection_jreName=JRE Name:
1986
ProductJRESection_jreName=JRE Name:
1986
ProductJRESection_eeName=Execution Environment:
1987
ProductJRESection_eeName=Execution Environment:
1987
ProductJRESection_browseJREs=Installed JREs...
1988
ProductJRESection_browseJREs=Installed JREs...
(-)src/org/eclipse/pde/internal/ui/editor/product/JRESection.java (-69 / +100 lines)
Lines 7-31 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Benjamin Cabe <benjamin.cabe@anyware-tech.com> - bug 217908
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.editor.product;
12
package org.eclipse.pde.internal.ui.editor.product;
12
13
13
import com.ibm.icu.text.MessageFormat;
14
import com.ibm.icu.text.MessageFormat;
14
import java.util.ArrayList;
15
import org.eclipse.core.runtime.IPath;
15
import org.eclipse.core.runtime.IPath;
16
import org.eclipse.core.runtime.Platform;
16
import org.eclipse.core.runtime.Platform;
17
import org.eclipse.jdt.launching.IVMInstall;
17
import org.eclipse.jdt.launching.IVMInstall;
18
import org.eclipse.jdt.launching.JavaRuntime;
18
import org.eclipse.jdt.launching.JavaRuntime;
19
import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
19
import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
20
import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager;
21
import org.eclipse.jface.layout.GridDataFactory;
20
import org.eclipse.jface.layout.GridDataFactory;
21
import org.eclipse.jface.viewers.*;
22
import org.eclipse.pde.core.IModelChangedEvent;
22
import org.eclipse.pde.core.IModelChangedEvent;
23
import org.eclipse.pde.core.plugin.TargetPlatform;
23
import org.eclipse.pde.core.plugin.TargetPlatform;
24
import org.eclipse.pde.internal.core.iproduct.*;
24
import org.eclipse.pde.internal.core.iproduct.*;
25
import org.eclipse.pde.internal.ui.*;
25
import org.eclipse.pde.internal.ui.*;
26
import org.eclipse.pde.internal.ui.editor.*;
26
import org.eclipse.pde.internal.ui.editor.*;
27
import org.eclipse.pde.internal.ui.launcher.VMHelper;
27
import org.eclipse.pde.internal.ui.launcher.VMHelper;
28
import org.eclipse.pde.internal.ui.parts.ComboPart;
28
import org.eclipse.pde.internal.ui.parts.ComboViewerPart;
29
import org.eclipse.swt.SWT;
29
import org.eclipse.swt.SWT;
30
import org.eclipse.swt.custom.CTabFolder;
30
import org.eclipse.swt.custom.CTabFolder;
31
import org.eclipse.swt.custom.CTabItem;
31
import org.eclipse.swt.custom.CTabItem;
Lines 42-54 Link Here
42
42
43
public class JRESection extends PDESection {
43
public class JRESection extends PDESection {
44
44
45
	private final class EELabelProvider extends LabelProvider {
46
		public String getText(Object element) {
47
			if (!(element instanceof IExecutionEnvironment))
48
				return ""; //$NON-NLS-1$
49
			IExecutionEnvironment env = (IExecutionEnvironment) element;
50
			IPath path = JavaRuntime.newJREContainerPath(env);
51
			IVMInstall install = JavaRuntime.getVMInstall(path);
52
			String eeItem;
53
			if (install != null) {
54
				eeItem = MessageFormat.format(PDEUIMessages.JRESection_eeBoundJRE, new String[] {env.getId(), install.getName()});
55
			} else {
56
				eeItem = MessageFormat.format(PDEUIMessages.JRESection_eeUnboundJRE, new String[] {env.getId()});
57
			}
58
			return eeItem;
59
		}
60
	}
61
62
	private final class JRELabelProvider extends LabelProvider {
63
		public String getText(Object element) {
64
			if (!(element instanceof IVMInstall))
65
				return ""; //$NON-NLS-1$
66
			IVMInstall vm = (IVMInstall) element;
67
			return vm.getName();
68
		}
69
	}
70
71
	private Button fNoneRadioButton;
45
	private Button fJRERadioButton;
72
	private Button fJRERadioButton;
46
	private Button fEERadioButton;
73
	private Button fEERadioButton;
47
	private Button fInstalledJREsButton;
74
	private Button fInstalledJREsButton;
48
	private Button fExecutionEnvironmentsButton;
75
	private Button fExecutionEnvironmentsButton;
49
	private ComboPart fJREsCombo;
76
	private ComboViewerPart fJREsCombo;
50
	private ComboPart fEEsCombo;
77
	private ComboViewerPart fEEsCombo;
51
	private ArrayList fEEChoices;
52
	private boolean fBlockChanges;
78
	private boolean fBlockChanges;
53
79
54
	private static final String[] TAB_LABELS = {"linux", "macosx", "solaris", "win32"}; //$NON-NLS-1$  //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
80
	private static final String[] TAB_LABELS = {"linux", "macosx", "solaris", "win32"}; //$NON-NLS-1$  //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
Lines 94-117 Link Here
94
		});
120
		});
95
		fTabFolder.setUnselectedImageVisible(false);
121
		fTabFolder.setUnselectedImageVisible(false);
96
122
123
		fNoneRadioButton = toolkit.createButton(client, PDEUIMessages.ProductJRESection_none, SWT.RADIO);
124
		fNoneRadioButton.addSelectionListener(new SelectionAdapter() {
125
			public void widgetSelected(SelectionEvent e) {
126
				if (fNoneRadioButton.getSelection()) {
127
					updateWidgets();
128
					setJRE(null);
129
				}
130
			}
131
		});
132
		GridDataFactory.fillDefaults().span(3, 1).applyTo(fNoneRadioButton);
133
97
		fJRERadioButton = toolkit.createButton(client, PDEUIMessages.ProductJRESection_jreName, SWT.RADIO);
134
		fJRERadioButton = toolkit.createButton(client, PDEUIMessages.ProductJRESection_jreName, SWT.RADIO);
98
		fJRERadioButton.addSelectionListener(new SelectionAdapter() {
135
		fJRERadioButton.addSelectionListener(new SelectionAdapter() {
99
			public void widgetSelected(SelectionEvent e) {
136
			public void widgetSelected(SelectionEvent e) {
100
				updateWidgets();
137
				if (fJRERadioButton.getSelection()) {
101
				setJRE(fJREsCombo.getSelection());
138
					updateWidgets();
139
					if (fJREsCombo.getSelection() == null)
140
						fJREsCombo.select(0);
141
					else
142
						setJRE((IVMInstall) fJREsCombo.getSelection());
143
				}
102
			}
144
			}
103
		});
145
		});
104
146
105
		fJREsCombo = new ComboPart();
147
		fJREsCombo = new ComboViewerPart();
106
		fJREsCombo.createControl(client, toolkit, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY);
148
		fJREsCombo.createControl(client, toolkit, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY);
107
		fJREsCombo.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
149
		fJREsCombo.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
108
		String[] installs = VMHelper.getVMInstallNames();
150
		fJREsCombo.setItems(VMHelper.getAllVMInstances());
109
		fJREsCombo.setItems(installs);
151
		fJREsCombo.setLabelProvider(new JRELabelProvider());
110
		fJREsCombo.add("", 0); //$NON-NLS-1$
152
		fJREsCombo.addSelectionChangedListener(new ISelectionChangedListener() {
111
		fJREsCombo.addSelectionListener(new SelectionAdapter() {
153
			public void selectionChanged(SelectionChangedEvent event) {
112
			public void widgetSelected(SelectionEvent e) {
154
				if (!fBlockChanges) {
113
				if (!fBlockChanges)
155
					setJRE(fJREsCombo.getSelection() == ComboViewerPart.NULL_OBJECT ? null : (IVMInstall) fJREsCombo.getSelection());
114
					setJRE(fJREsCombo.getSelection());
156
				}
115
			}
157
			}
116
		});
158
		});
117
159
Lines 127-145 Link Here
127
		fEERadioButton = toolkit.createButton(client, PDEUIMessages.ProductJRESection_eeName, SWT.RADIO);
169
		fEERadioButton = toolkit.createButton(client, PDEUIMessages.ProductJRESection_eeName, SWT.RADIO);
128
		fEERadioButton.addSelectionListener(new SelectionAdapter() {
170
		fEERadioButton.addSelectionListener(new SelectionAdapter() {
129
			public void widgetSelected(SelectionEvent e) {
171
			public void widgetSelected(SelectionEvent e) {
130
				updateWidgets();
172
				if (fEERadioButton.getSelection()) {
131
				setEE(fEEsCombo.getSelectionIndex());
173
					updateWidgets();
174
					if (fEEsCombo.getSelection() == null)
175
						fEEsCombo.select(0);
176
					else
177
						setEE((IExecutionEnvironment) fEEsCombo.getSelection());
178
				}
132
			}
179
			}
133
		});
180
		});
134
181
135
		fEEsCombo = new ComboPart();
182
		fEEsCombo = new ComboViewerPart();
136
		fEEsCombo.createControl(client, toolkit, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY);
183
		fEEsCombo.createControl(client, toolkit, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY);
137
		fEEsCombo.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
184
		fEEsCombo.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
138
		initializeExecutionEnvironments();
185
		fEEsCombo.setLabelProvider(new EELabelProvider());
139
		fEEsCombo.addSelectionListener(new SelectionAdapter() {
186
		fEEsCombo.setComparator(new ViewerComparator());
140
			public void widgetSelected(SelectionEvent e) {
187
		fEEsCombo.setItems(VMHelper.getExecutionEnvironments());
141
				if (!fBlockChanges)
188
		fEEsCombo.addSelectionChangedListener(new ISelectionChangedListener() {
142
					setEE(fEEsCombo.getSelectionIndex());
189
			public void selectionChanged(SelectionChangedEvent event) {
190
				if (!fBlockChanges) {
191
					setEE((IExecutionEnvironment) ((IStructuredSelection) event.getSelection()).getFirstElement());
192
				}
143
			}
193
			}
144
		});
194
		});
145
195
Lines 159-206 Link Here
159
		getProductModel().addModelChangedListener(this);
209
		getProductModel().addModelChangedListener(this);
160
	}
210
	}
161
211
162
	private void setEE(int selectionIndex) {
212
	private void setEE(IExecutionEnvironment ee) {
163
		if (selectionIndex >= 0 && selectionIndex < fEEChoices.size()) {
213
		IPath eePath = null;
164
			IExecutionEnvironment ee = (IExecutionEnvironment) fEEChoices.get(selectionIndex);
214
		if (ee != null)
165
			if (ee != null) {
215
			eePath = JavaRuntime.newJREContainerPath(ee);
166
				IPath eePath = JavaRuntime.newJREContainerPath(ee);
216
		getJVMLocations().setJREContainerPath(getOS(fLastTab), eePath);
167
				getJVMLocations().setJREContainerPath(getOS(fLastTab), eePath);
168
			}
169
		}
170
	}
171
217
172
	private void setJRE(String vmName) {
173
		IVMInstall install = VMHelper.getVMInstall(vmName);
174
		if (install != null) {
175
			IPath jrePath = JavaRuntime.newJREContainerPath(install);
176
			getJVMLocations().setJREContainerPath(getOS(fLastTab), jrePath);
177
		}
178
	}
218
	}
179
219
180
	private void initializeExecutionEnvironments() {
220
	private void setJRE(IVMInstall install) {
181
		fEEChoices = new ArrayList();
221
		IPath jrePath = null;
182
		IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager();
222
		if (install != null)
183
		IExecutionEnvironment[] envs = manager.getExecutionEnvironments();
223
			jrePath = JavaRuntime.newJREContainerPath(install);
184
		for (int i = 0; i < envs.length; i++) {
224
		getJVMLocations().setJREContainerPath(getOS(fLastTab), jrePath);
185
			addToEECombo(envs[i]);
186
		}
187
	}
188
189
	/**
190
	 * Adds the given execution environment to the list of known EEs and
191
	 * adds an entry to the combo box "EE_ID (Associated_VM)".  The entries
192
	 * will always be added to the end of the list/combo.
193
	 * @param env environment to add
194
	 */
195
	private void addToEECombo(IExecutionEnvironment env) {
196
		IPath path = JavaRuntime.newJREContainerPath(env);
197
		IVMInstall install = JavaRuntime.getVMInstall(path);
198
		fEEChoices.add(env);
199
		if (install != null) {
200
			fEEsCombo.add(MessageFormat.format(PDEUIMessages.JRESection_eeBoundJRE, new String[] {env.getId(), install.getName()}));
201
		} else {
202
			fEEsCombo.add(MessageFormat.format(PDEUIMessages.JRESection_eeUnboundJRE, new String[] {env.getId()}));
203
		}
204
	}
225
	}
205
226
206
	private IProductModel getProductModel() {
227
	private IProductModel getProductModel() {
Lines 246-266 Link Here
246
			String eeID = JavaRuntime.getExecutionEnvironmentId(jrePath);
267
			String eeID = JavaRuntime.getExecutionEnvironmentId(jrePath);
247
			IExecutionEnvironment env = VMHelper.getExecutionEnvironment(eeID);
268
			IExecutionEnvironment env = VMHelper.getExecutionEnvironment(eeID);
248
			if (env != null) {
269
			if (env != null) {
249
				if (!fEEChoices.contains(env))
270
				if (!fEEsCombo.getItems().contains(env))
250
					addToEECombo(env);
271
					fEEsCombo.addItem(env);
251
				fEEsCombo.select(fEEsCombo.getItemCount() - 1);
272
				fEEsCombo.select(env);
273
				fNoneRadioButton.setSelection(false);
252
				fEERadioButton.setSelection(true);
274
				fEERadioButton.setSelection(true);
253
				fJRERadioButton.setSelection(false);
275
				fJRERadioButton.setSelection(false);
276
				fJREsCombo.select(null);
254
			} else {
277
			} else {
255
				IVMInstall install = JavaRuntime.getVMInstall(jrePath);
278
				IVMInstall install = JavaRuntime.getVMInstall(jrePath);
256
				if (install != null) {
279
				if (install != null) {
257
					if (fJREsCombo.indexOf(install.getName()) < 0)
280
					if (!fJREsCombo.getItems().contains(install))
258
						fJREsCombo.add(install.getName());
281
						fJREsCombo.addItem(install);
259
					fJREsCombo.setText(install.getName());
282
					fJREsCombo.select(install);
283
					fNoneRadioButton.setSelection(false);
260
					fJRERadioButton.setSelection(true);
284
					fJRERadioButton.setSelection(true);
261
					fEERadioButton.setSelection(false);
285
					fEERadioButton.setSelection(false);
286
					fEEsCombo.select(null);
262
				}
287
				}
263
			}
288
			}
289
		} else {
290
			fNoneRadioButton.setSelection(true);
291
			fJRERadioButton.setSelection(false);
292
			fJREsCombo.select(null);
293
			fEERadioButton.setSelection(false);
294
			fEEsCombo.select(null);
264
		}
295
		}
265
		updateWidgets();
296
		updateWidgets();
266
		super.refresh();
297
		super.refresh();
(-)src/org/eclipse/pde/internal/ui/parts/ComboViewerPart.java (+120 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
 *     Benjamin Cabe <benjamin.cabe@anyware-tech.com> - creation of this class
11
 *******************************************************************************/
12
package org.eclipse.pde.internal.ui.parts;
13
14
import java.util.*;
15
import java.util.List;
16
import org.eclipse.jface.viewers.*;
17
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.custom.CCombo;
19
import org.eclipse.swt.widgets.*;
20
import org.eclipse.ui.forms.widgets.FormToolkit;
21
22
public class ComboViewerPart {
23
	private Control fCombo;
24
	private ComboViewer fComboViewer;
25
	private List fObjects;
26
27
	/**
28
	 * The magic object used to deal with null content
29
	 */
30
	public static Object NULL_OBJECT = new Object();
31
32
	public ComboViewerPart() {
33
	}
34
35
	public void createControl(Composite parent, FormToolkit toolkit, int style) {
36
		if (toolkit.getBorderStyle() == SWT.BORDER) {
37
			fCombo = new Combo(parent, style | SWT.BORDER);
38
			fComboViewer = new ComboViewer((Combo) fCombo);
39
		} else {
40
			fCombo = new CCombo(parent, style | SWT.FLAT);
41
			fComboViewer = new ComboViewer((CCombo) fCombo);
42
		}
43
44
		fObjects = new ArrayList();
45
		fComboViewer.setLabelProvider(new LabelProvider());
46
		fComboViewer.setContentProvider(new ArrayContentProvider());
47
		fComboViewer.setInput(fObjects);
48
	}
49
50
	public Control getControl() {
51
		return fCombo;
52
	}
53
54
	public void setEnabled(boolean enabled) {
55
		fCombo.setEnabled(enabled);
56
	}
57
58
	public void refresh() {
59
		fComboViewer.refresh();
60
	}
61
62
	public void addItem(Object item) {
63
		fObjects.add((item == null) ? NULL_OBJECT : item);
64
		refresh();
65
	}
66
67
	public void addItem(Object item, int index) {
68
		fObjects.add(index, (item == null) ? NULL_OBJECT : item);
69
		refresh();
70
	}
71
72
	public Collection getItems() {
73
		return fObjects;
74
	}
75
76
	public void setItems(Object[] items) {
77
		fObjects.clear();
78
		for (int i = 0; i < items.length; i++)
79
			fObjects.add((items[i] == null) ? NULL_OBJECT : items[i]);
80
		refresh();
81
	}
82
83
	public void setItems(Collection items) {
84
		fObjects.clear();
85
		Iterator it = items.iterator();
86
		while (it.hasNext()) {
87
			Object o = it.next();
88
			fObjects.add((o == null) ? NULL_OBJECT : o);
89
		}
90
		refresh();
91
	}
92
93
	public void select(Object item) {
94
		if (item != null)
95
			fComboViewer.setSelection(new StructuredSelection(item));
96
		else
97
			fComboViewer.setSelection(null);
98
	}
99
100
	public void select(int index) {
101
		if (index < fObjects.size())
102
			select(fObjects.get(index));
103
	}
104
105
	public void setLabelProvider(IBaseLabelProvider labelProvider) {
106
		fComboViewer.setLabelProvider(labelProvider);
107
	}
108
109
	public void setComparator(ViewerComparator comparator) {
110
		fComboViewer.setComparator(comparator);
111
	}
112
113
	public void addSelectionChangedListener(ISelectionChangedListener listener) {
114
		fComboViewer.addSelectionChangedListener(listener);
115
	}
116
117
	public Object getSelection() {
118
		return ((IStructuredSelection) fComboViewer.getSelection()).getFirstElement();
119
	}
120
}

Return to bug 217908