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(); |