Lines 1-115
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2009 IBM Corporation and others. |
2 |
* Copyright (c) 2009 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.wizards.target; |
11 |
package org.eclipse.pde.internal.ui.wizards.target; |
12 |
|
12 |
|
13 |
import org.eclipse.pde.internal.core.target.provisional.ITargetDefinition; |
13 |
import java.util.*; |
14 |
import org.eclipse.pde.internal.ui.PDEPluginImages; |
14 |
import org.eclipse.core.runtime.*; |
15 |
import org.eclipse.pde.internal.ui.PDEUIMessages; |
15 |
import org.eclipse.debug.ui.StringVariableSelectionDialog; |
16 |
import org.eclipse.pde.internal.ui.shared.target.BundleContainerTable; |
16 |
import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo; |
17 |
import org.eclipse.swt.SWT; |
17 |
import org.eclipse.jdt.launching.JavaRuntime; |
18 |
import org.eclipse.swt.events.ModifyEvent; |
18 |
import org.eclipse.jdt.launching.environments.IExecutionEnvironment; |
19 |
import org.eclipse.swt.events.ModifyListener; |
19 |
import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager; |
20 |
import org.eclipse.swt.layout.GridData; |
20 |
import org.eclipse.jface.viewers.*; |
21 |
import org.eclipse.swt.layout.GridLayout; |
21 |
import org.eclipse.jface.window.Window; |
22 |
import org.eclipse.swt.widgets.*; |
22 |
import org.eclipse.osgi.service.resolver.BundleDescription; |
23 |
|
23 |
import org.eclipse.pde.core.plugin.IPluginModelBase; |
24 |
/** |
24 |
import org.eclipse.pde.core.plugin.PluginRegistry; |
25 |
* |
25 |
import org.eclipse.pde.internal.core.ICoreConstants; |
26 |
*/ |
26 |
import org.eclipse.pde.internal.core.PDECore; |
27 |
public class TargetDefinitionContentPage extends TargetDefinitionPage { |
27 |
import org.eclipse.pde.internal.core.target.provisional.ITargetDefinition; |
28 |
|
28 |
import org.eclipse.pde.internal.core.util.VMUtil; |
29 |
private Text fNameText; |
29 |
import org.eclipse.pde.internal.ui.*; |
30 |
private Text fDescriptionText; |
30 |
import org.eclipse.pde.internal.ui.elements.DefaultTableProvider; |
31 |
private BundleContainerTable fTable; |
31 |
import org.eclipse.pde.internal.ui.shared.target.BundleContainerTable; |
32 |
|
32 |
import org.eclipse.pde.internal.ui.util.LocaleUtil; |
33 |
/** |
33 |
import org.eclipse.pde.internal.ui.util.SWTUtil; |
34 |
* @param pageName |
34 |
import org.eclipse.swt.SWT; |
35 |
*/ |
35 |
import org.eclipse.swt.events.*; |
36 |
public TargetDefinitionContentPage(ITargetDefinition target) { |
36 |
import org.eclipse.swt.layout.GridData; |
37 |
super("targetContent", target); //$NON-NLS-1$ |
37 |
import org.eclipse.swt.layout.GridLayout; |
38 |
setTitle(PDEUIMessages.TargetDefinitionContentPage_1); |
38 |
import org.eclipse.swt.widgets.*; |
39 |
setDescription(PDEUIMessages.TargetDefinitionContentPage_2); |
39 |
import org.eclipse.ui.dialogs.ElementListSelectionDialog; |
40 |
setImageDescriptor(PDEPluginImages.DESC_TARGET_WIZ); |
40 |
|
41 |
} |
41 |
/** |
42 |
|
42 |
* |
43 |
/* (non-Javadoc) |
43 |
*/ |
44 |
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) |
44 |
public class TargetDefinitionContentPage extends TargetDefinitionPage { |
45 |
*/ |
45 |
|
46 |
public void createControl(Composite parent) { |
46 |
private Text fNameText; |
47 |
Composite comp = new Composite(parent, SWT.NONE); |
47 |
private Text fDescriptionText; |
48 |
comp.setLayout(new GridLayout(1, true)); |
48 |
private BundleContainerTable fTable; |
49 |
comp.setLayoutData(new GridData(GridData.FILL_BOTH)); |
49 |
|
50 |
|
50 |
// Environment pull-downs |
51 |
Group group = new Group(comp, SWT.NONE); |
51 |
private Combo fOSCombo; |
52 |
group.setText(PDEUIMessages.TargetDefinitionContentPage_3); |
52 |
private Combo fWSCombo; |
53 |
group.setLayout(new GridLayout(2, false)); |
53 |
private Combo fArchCombo; |
54 |
group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
54 |
private Combo fNLCombo; |
55 |
|
55 |
|
56 |
Label label = new Label(group, SWT.NONE); |
56 |
// Choices for each pull-down |
57 |
label.setText(PDEUIMessages.TargetDefinitionContentPage_4); |
57 |
private TreeSet fNLChoices; |
58 |
GridData gridData = new GridData(SWT.LEFT, SWT.TOP, false, false); |
58 |
private TreeSet fOSChoices; |
59 |
label.setLayoutData(gridData); |
59 |
private TreeSet fWSChoices; |
60 |
|
60 |
private TreeSet fArchChoices; |
61 |
fNameText = new Text(group, SWT.BORDER); |
61 |
|
62 |
gridData = new GridData(SWT.FILL, SWT.TOP, true, false); |
62 |
// JRE section |
63 |
fNameText.setLayoutData(gridData); |
63 |
private Button fDefaultJREButton; |
64 |
fNameText.addModifyListener(new ModifyListener() { |
64 |
private Button fNamedJREButton; |
65 |
public void modifyText(ModifyEvent e) { |
65 |
private Button fExecEnvButton; |
66 |
getTargetDefinition().setName(fNameText.getText().trim()); |
66 |
private Combo fNamedJREsCombo; |
67 |
} |
67 |
private Combo fExecEnvsCombo; |
68 |
}); |
68 |
private TreeSet fExecEnvChoices; |
69 |
|
69 |
|
70 |
label = new Label(group, SWT.NONE); |
70 |
// argument controls |
71 |
label.setText(PDEUIMessages.TargetDefinitionContentPage_5); |
71 |
private Text fProgramArgs; |
72 |
gridData = new GridData(SWT.LEFT, SWT.TOP, false, false); |
72 |
private Text fVMArgs; |
73 |
label.setLayoutData(gridData); |
73 |
private Button fAppendLauncherArgs; |
74 |
|
74 |
|
75 |
fDescriptionText = new Text(group, SWT.BORDER); |
75 |
// implicit dependencies tab |
76 |
gridData = new GridData(SWT.FILL, SWT.TOP, true, false); |
76 |
private TableViewer fElementViewer; |
77 |
fDescriptionText.setLayoutData(gridData); |
77 |
private Button fAddButton; |
78 |
fDescriptionText.addModifyListener(new ModifyListener() { |
78 |
private Button fRemoveButton; |
79 |
public void modifyText(ModifyEvent e) { |
79 |
private Button fRemoveAllButton; |
80 |
getTargetDefinition().setDescription(fDescriptionText.getText().trim()); |
80 |
|
81 |
} |
81 |
/** |
82 |
}); |
82 |
* @param pageName |
83 |
|
83 |
*/ |
84 |
Group content = new Group(comp, SWT.NONE); |
84 |
public TargetDefinitionContentPage(ITargetDefinition target) { |
85 |
content.setText(PDEUIMessages.TargetDefinitionContentPage_6); |
85 |
super("targetContent", target); //$NON-NLS-1$ |
86 |
content.setLayout(new GridLayout(2, false)); |
86 |
setTitle(PDEUIMessages.TargetDefinitionContentPage_1); |
87 |
gridData = new GridData(GridData.FILL_BOTH); |
87 |
setDescription(PDEUIMessages.TargetDefinitionContentPage_2); |
88 |
gridData.widthHint = 200; |
88 |
setImageDescriptor(PDEPluginImages.DESC_TARGET_WIZ); |
89 |
content.setLayoutData(gridData); |
89 |
} |
90 |
|
90 |
|
91 |
fTable = BundleContainerTable.createTableInDialog(content); |
91 |
/* (non-Javadoc) |
92 |
setControl(comp); |
92 |
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) |
93 |
targetChanged(getTargetDefinition()); |
93 |
*/ |
94 |
} |
94 |
public void createControl(Composite parent) { |
95 |
|
95 |
Composite comp = new Composite(parent, SWT.NONE); |
96 |
/* (non-Javadoc) |
96 |
comp.setLayout(new GridLayout(1, true)); |
97 |
* @see org.eclipse.pde.internal.ui.wizards.target.TargetDefinitionPage#targetChanged() |
97 |
comp.setLayoutData(new GridData(GridData.FILL_BOTH)); |
98 |
*/ |
98 |
|
99 |
protected void targetChanged(ITargetDefinition definition) { |
99 |
Group group = new Group(comp, SWT.NONE); |
100 |
super.targetChanged(definition); |
100 |
group.setText(PDEUIMessages.TargetDefinitionContentPage_3); |
101 |
if (definition != null) { |
101 |
group.setLayout(new GridLayout(2, false)); |
102 |
String name = definition.getName(); |
102 |
group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
103 |
if (name == null) { |
103 |
|
104 |
name = ""; //$NON-NLS-1$ |
104 |
Label label = new Label(group, SWT.NONE); |
105 |
} |
105 |
label.setText(PDEUIMessages.TargetDefinitionContentPage_4); |
106 |
fNameText.setText(name); |
106 |
GridData gridData = new GridData(SWT.LEFT, SWT.TOP, false, false); |
107 |
String des = definition.getDescription(); |
107 |
label.setLayoutData(gridData); |
108 |
if (des == null) { |
108 |
|
109 |
des = ""; //$NON-NLS-1$ |
109 |
fNameText = new Text(group, SWT.BORDER); |
110 |
} |
110 |
gridData = new GridData(SWT.FILL, SWT.TOP, true, false); |
111 |
fDescriptionText.setText(des); |
111 |
fNameText.setLayoutData(gridData); |
112 |
fTable.setInput(definition); |
112 |
fNameText.addModifyListener(new ModifyListener() { |
113 |
} |
113 |
public void modifyText(ModifyEvent e) { |
114 |
} |
114 |
getTargetDefinition().setName(fNameText.getText().trim()); |
115 |
} |
115 |
} |
|
|
116 |
}); |
117 |
|
118 |
label = new Label(group, SWT.NONE); |
119 |
label.setText(PDEUIMessages.TargetDefinitionContentPage_5); |
120 |
gridData = new GridData(SWT.LEFT, SWT.TOP, false, false); |
121 |
label.setLayoutData(gridData); |
122 |
|
123 |
fDescriptionText = new Text(group, SWT.BORDER); |
124 |
gridData = new GridData(SWT.FILL, SWT.TOP, true, false); |
125 |
fDescriptionText.setLayoutData(gridData); |
126 |
fDescriptionText.addModifyListener(new ModifyListener() { |
127 |
public void modifyText(ModifyEvent e) { |
128 |
getTargetDefinition().setDescription(fDescriptionText.getText().trim()); |
129 |
} |
130 |
}); |
131 |
|
132 |
TabFolder tabs = new TabFolder(comp, SWT.NONE); |
133 |
tabs.setLayoutData(new GridData(GridData.FILL_BOTH)); |
134 |
Composite container = new Composite(tabs, SWT.NONE); |
135 |
GridLayout layout = new GridLayout(); |
136 |
layout.verticalSpacing = 15; |
137 |
container.setLayout(layout); |
138 |
container.setLayoutData(new GridData(GridData.FILL_BOTH)); |
139 |
|
140 |
TabItem pluginsTab = new TabItem(tabs, SWT.NONE); |
141 |
pluginsTab.setText(PDEUIMessages.TargetDefinitionContentPage_6); |
142 |
Composite content = new Composite(tabs, SWT.NONE); |
143 |
GridLayout lo = new GridLayout(2, false); |
144 |
lo.marginWidth = 0; |
145 |
lo.marginHeight = 0; |
146 |
content.setLayout(lo); |
147 |
gridData = new GridData(GridData.FILL_BOTH); |
148 |
gridData.widthHint = 200; |
149 |
content.setLayoutData(gridData); |
150 |
fTable = BundleContainerTable.createTableInDialog(content); |
151 |
pluginsTab.setControl(content); |
152 |
|
153 |
TabItem envTab = new TabItem(tabs, SWT.NONE); |
154 |
envTab.setText(PDEUIMessages.TargetDefinitionEnvironmentPage_3); |
155 |
|
156 |
createTargetEnvironmentGroup(container); |
157 |
createJREGroup(container); |
158 |
envTab.setControl(container); |
159 |
|
160 |
TabItem argsTab = new TabItem(tabs, SWT.NONE); |
161 |
argsTab.setText(PDEUIMessages.TargetDefinitionEnvironmentPage_4); |
162 |
argsTab.setControl(createArgumentsGroup(tabs)); |
163 |
|
164 |
TabItem depTab = new TabItem(tabs, SWT.NONE); |
165 |
depTab.setText(PDEUIMessages.TargetDefinitionEnvironmentPage_5); |
166 |
depTab.setControl(createImplicitTabContents(tabs)); |
167 |
|
168 |
setControl(comp); |
169 |
targetChanged(getTargetDefinition()); |
170 |
} |
171 |
|
172 |
/* (non-Javadoc) |
173 |
* @see org.eclipse.pde.internal.ui.wizards.target.TargetDefinitionPage#targetChanged() |
174 |
*/ |
175 |
protected void targetChanged(ITargetDefinition definition) { |
176 |
super.targetChanged(definition); |
177 |
if (definition != null) { |
178 |
String name = definition.getName(); |
179 |
if (name == null) { |
180 |
name = ""; //$NON-NLS-1$ |
181 |
} |
182 |
fNameText.setText(name); |
183 |
String des = definition.getDescription(); |
184 |
if (des == null) { |
185 |
des = ""; //$NON-NLS-1$ |
186 |
} |
187 |
fDescriptionText.setText(des); |
188 |
fTable.setInput(definition); |
189 |
|
190 |
String presetValue = (definition.getOS() == null) ? "" : definition.getOS(); //$NON-NLS-1$ |
191 |
fOSCombo.setText(presetValue); |
192 |
presetValue = (definition.getWS() == null) ? "" : definition.getWS(); //$NON-NLS-1$ |
193 |
fWSCombo.setText(presetValue); |
194 |
presetValue = (definition.getArch() == null) ? "" : definition.getArch(); //$NON-NLS-1$ |
195 |
fArchCombo.setText(presetValue); |
196 |
presetValue = (definition.getNL() == null) ? "" : LocaleUtil.expandLocaleName(definition.getNL()); //$NON-NLS-1$ |
197 |
fNLCombo.setText(presetValue); |
198 |
|
199 |
IPath jrePath = definition.getJREContainer(); |
200 |
if (jrePath == null || jrePath.equals(JavaRuntime.newDefaultJREContainerPath())) { |
201 |
fDefaultJREButton.setSelection(true); |
202 |
} else { |
203 |
String ee = JavaRuntime.getExecutionEnvironmentId(jrePath); |
204 |
if (ee != null) { |
205 |
fExecEnvButton.setSelection(true); |
206 |
fExecEnvsCombo.select(fExecEnvsCombo.indexOf(ee)); |
207 |
} else { |
208 |
String vm = JavaRuntime.getVMInstallName(jrePath); |
209 |
if (vm != null) { |
210 |
fNamedJREButton.setSelection(true); |
211 |
fNamedJREsCombo.select(fNamedJREsCombo.indexOf(vm)); |
212 |
} |
213 |
} |
214 |
} |
215 |
|
216 |
if (fExecEnvsCombo.getSelectionIndex() == -1) |
217 |
fExecEnvsCombo.setText(fExecEnvChoices.first().toString()); |
218 |
|
219 |
if (fNamedJREsCombo.getSelectionIndex() == -1) |
220 |
fNamedJREsCombo.setText(VMUtil.getDefaultVMInstallName()); |
221 |
|
222 |
updateJREWidgets(); |
223 |
|
224 |
presetValue = (definition.getProgramArguments() == null) ? "" : definition.getProgramArguments(); //$NON-NLS-1$ |
225 |
fProgramArgs.setText(presetValue); |
226 |
presetValue = (definition.getVMArguments() == null) ? "" : definition.getVMArguments(); //$NON-NLS-1$ |
227 |
fVMArgs.setText(presetValue); |
228 |
|
229 |
fElementViewer.refresh(); |
230 |
} |
231 |
} |
232 |
|
233 |
private void createTargetEnvironmentGroup(Composite container) { |
234 |
Group group = new Group(container, SWT.NULL); |
235 |
GridLayout layout = new GridLayout(); |
236 |
layout.numColumns = 2; |
237 |
group.setLayout(layout); |
238 |
group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
239 |
group.setText(PDEUIMessages.EnvironmentBlock_targetEnv); |
240 |
|
241 |
initializeChoices(); |
242 |
|
243 |
Label label = new Label(group, SWT.NULL); |
244 |
label.setText(PDEUIMessages.Preferences_TargetEnvironmentPage_os); |
245 |
|
246 |
fOSCombo = new Combo(group, SWT.SINGLE | SWT.BORDER); |
247 |
fOSCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
248 |
fOSCombo.setItems((String[]) fOSChoices.toArray(new String[fOSChoices.size()])); |
249 |
fOSCombo.addModifyListener(new ModifyListener() { |
250 |
public void modifyText(ModifyEvent e) { |
251 |
getTargetDefinition().setOS(getModelValue(fOSCombo.getText())); |
252 |
} |
253 |
}); |
254 |
|
255 |
label = new Label(group, SWT.NULL); |
256 |
label.setText(PDEUIMessages.Preferences_TargetEnvironmentPage_ws); |
257 |
|
258 |
fWSCombo = new Combo(group, SWT.SINGLE | SWT.BORDER); |
259 |
fWSCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
260 |
fWSCombo.setItems((String[]) fWSChoices.toArray(new String[fWSChoices.size()])); |
261 |
fWSCombo.addModifyListener(new ModifyListener() { |
262 |
public void modifyText(ModifyEvent e) { |
263 |
getTargetDefinition().setWS(getModelValue(fWSCombo.getText())); |
264 |
} |
265 |
}); |
266 |
|
267 |
label = new Label(group, SWT.NULL); |
268 |
label.setText(PDEUIMessages.Preferences_TargetEnvironmentPage_arch); |
269 |
|
270 |
fArchCombo = new Combo(group, SWT.SINGLE | SWT.BORDER); |
271 |
fArchCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
272 |
fArchCombo.setItems((String[]) fArchChoices.toArray(new String[fArchChoices.size()])); |
273 |
fArchCombo.addModifyListener(new ModifyListener() { |
274 |
public void modifyText(ModifyEvent e) { |
275 |
getTargetDefinition().setArch(getModelValue(fArchCombo.getText())); |
276 |
} |
277 |
}); |
278 |
|
279 |
label = new Label(group, SWT.NULL); |
280 |
label.setText(PDEUIMessages.Preferences_TargetEnvironmentPage_nl); |
281 |
|
282 |
fNLCombo = new Combo(group, SWT.SINGLE | SWT.BORDER); |
283 |
fNLCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
284 |
fNLCombo.setItems((String[]) fNLChoices.toArray(new String[fNLChoices.size()])); |
285 |
fNLCombo.addModifyListener(new ModifyListener() { |
286 |
public void modifyText(ModifyEvent e) { |
287 |
String value = fNLCombo.getText(); |
288 |
int index = value.indexOf("-"); //$NON-NLS-1$ |
289 |
if (index > 0) |
290 |
value = value.substring(0, index); |
291 |
getTargetDefinition().setNL(getModelValue(value)); |
292 |
} |
293 |
}); |
294 |
|
295 |
} |
296 |
|
297 |
/** |
298 |
* Returns the given string or <code>null</code> if empty to set a value in the |
299 |
* target definition. |
300 |
* |
301 |
* @param value |
302 |
* @return |
303 |
*/ |
304 |
private String getModelValue(String value) { |
305 |
if (value != null) { |
306 |
value = value.trim(); |
307 |
if (value.length() == 0) { |
308 |
return null; |
309 |
} |
310 |
} |
311 |
return value; |
312 |
} |
313 |
|
314 |
private void addExtraChoices(Set set, String preference) { |
315 |
StringTokenizer tokenizer = new StringTokenizer(preference, ","); //$NON-NLS-1$ |
316 |
while (tokenizer.hasMoreTokens()) { |
317 |
set.add(tokenizer.nextToken().trim()); |
318 |
} |
319 |
} |
320 |
|
321 |
private void initializeChoices() { |
322 |
Preferences preferences = PDECore.getDefault().getPluginPreferences(); |
323 |
|
324 |
fOSChoices = new TreeSet(); |
325 |
String[] os = Platform.knownOSValues(); |
326 |
for (int i = 0; i < os.length; i++) |
327 |
fOSChoices.add(os[i]); |
328 |
addExtraChoices(fOSChoices, preferences.getString(ICoreConstants.OS_EXTRA)); |
329 |
|
330 |
fWSChoices = new TreeSet(); |
331 |
String[] ws = Platform.knownWSValues(); |
332 |
for (int i = 0; i < ws.length; i++) |
333 |
fWSChoices.add(ws[i]); |
334 |
addExtraChoices(fWSChoices, preferences.getString(ICoreConstants.WS_EXTRA)); |
335 |
|
336 |
fArchChoices = new TreeSet(); |
337 |
String[] arch = Platform.knownOSArchValues(); |
338 |
for (int i = 0; i < arch.length; i++) |
339 |
fArchChoices.add(arch[i]); |
340 |
addExtraChoices(fArchChoices, preferences.getString(ICoreConstants.ARCH_EXTRA)); |
341 |
|
342 |
fNLChoices = new TreeSet(); |
343 |
initializeAllLocales(); |
344 |
} |
345 |
|
346 |
private void initializeAllLocales() { |
347 |
Preferences preferences = PDECore.getDefault().getPluginPreferences(); |
348 |
String[] nl = LocaleUtil.getLocales(); |
349 |
for (int i = 0; i < nl.length; i++) |
350 |
fNLChoices.add(nl[i]); |
351 |
addExtraChoices(fNLChoices, preferences.getString(ICoreConstants.NL_EXTRA)); |
352 |
} |
353 |
|
354 |
private void createJREGroup(Composite container) { |
355 |
Group group = new Group(container, SWT.NULL); |
356 |
GridLayout layout = new GridLayout(); |
357 |
layout.numColumns = 2; |
358 |
group.setLayout(layout); |
359 |
group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
360 |
group.setText(PDEUIMessages.EnvironmentBlock_jreTitle); |
361 |
|
362 |
initializeJREValues(); |
363 |
|
364 |
Label label = new Label(group, SWT.WRAP); |
365 |
label.setText(PDEUIMessages.JRESection_description); |
366 |
GridData data = new GridData(GridData.FILL_HORIZONTAL); |
367 |
data.verticalAlignment = SWT.TOP; |
368 |
data.horizontalSpan = 2; |
369 |
label.setLayoutData(data); |
370 |
|
371 |
fDefaultJREButton = new Button(group, SWT.RADIO); |
372 |
fDefaultJREButton.setText(PDEUIMessages.JRESection_defaultJRE); |
373 |
GridData gd = new GridData(); |
374 |
gd.horizontalSpan = 2; |
375 |
fDefaultJREButton.setLayoutData(gd); |
376 |
fDefaultJREButton.addSelectionListener(new SelectionAdapter() { |
377 |
public void widgetSelected(SelectionEvent e) { |
378 |
updateJREWidgets(); |
379 |
getTargetDefinition().setJREContainer(JavaRuntime.newDefaultJREContainerPath()); |
380 |
} |
381 |
}); |
382 |
|
383 |
fNamedJREButton = new Button(group, SWT.RADIO); |
384 |
fNamedJREButton.setText(PDEUIMessages.JRESection_JREName); |
385 |
fNamedJREButton.addSelectionListener(new SelectionAdapter() { |
386 |
public void widgetSelected(SelectionEvent e) { |
387 |
updateJREWidgets(); |
388 |
getTargetDefinition().setJREContainer(JavaRuntime.newJREContainerPath(VMUtil.getVMInstall(fNamedJREsCombo.getText()))); |
389 |
} |
390 |
}); |
391 |
|
392 |
fNamedJREsCombo = new Combo(group, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY); |
393 |
fNamedJREsCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
394 |
String[] installs = VMUtil.getVMInstallNames(); |
395 |
fNamedJREsCombo.setItems(installs); |
396 |
fNamedJREsCombo.addModifyListener(new ModifyListener() { |
397 |
public void modifyText(ModifyEvent e) { |
398 |
getTargetDefinition().setJREContainer(JavaRuntime.newJREContainerPath(VMUtil.getVMInstall(fNamedJREsCombo.getText()))); |
399 |
} |
400 |
}); |
401 |
|
402 |
fExecEnvButton = new Button(group, SWT.RADIO); |
403 |
fExecEnvButton.setText(PDEUIMessages.JRESection_ExecutionEnv); |
404 |
fExecEnvButton.addSelectionListener(new SelectionAdapter() { |
405 |
public void widgetSelected(SelectionEvent e) { |
406 |
updateJREWidgets(); |
407 |
getTargetDefinition().setJREContainer(JavaRuntime.newJREContainerPath(VMUtil.getExecutionEnvironment(fExecEnvsCombo.getText()))); |
408 |
} |
409 |
}); |
410 |
|
411 |
fExecEnvsCombo = new Combo(group, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY); |
412 |
fExecEnvsCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
413 |
fExecEnvsCombo.setItems((String[]) fExecEnvChoices.toArray(new String[fExecEnvChoices.size()])); |
414 |
fExecEnvsCombo.addModifyListener(new ModifyListener() { |
415 |
public void modifyText(ModifyEvent e) { |
416 |
getTargetDefinition().setJREContainer(JavaRuntime.newJREContainerPath(VMUtil.getExecutionEnvironment(fExecEnvsCombo.getText()))); |
417 |
} |
418 |
}); |
419 |
|
420 |
} |
421 |
|
422 |
/** |
423 |
* Initializes the combo with possible execution enviroments |
424 |
*/ |
425 |
protected void initializeJREValues() { |
426 |
fExecEnvChoices = new TreeSet(); |
427 |
IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager(); |
428 |
IExecutionEnvironment[] envs = manager.getExecutionEnvironments(); |
429 |
for (int i = 0; i < envs.length; i++) |
430 |
fExecEnvChoices.add(envs[i].getId()); |
431 |
} |
432 |
|
433 |
protected void updateJREWidgets() { |
434 |
fNamedJREsCombo.setEnabled(fNamedJREButton.getSelection()); |
435 |
fExecEnvsCombo.setEnabled(fExecEnvButton.getSelection()); |
436 |
} |
437 |
|
438 |
private Control createArgumentsGroup(Composite parent) { |
439 |
Composite container = new Composite(parent, SWT.NONE); |
440 |
container.setLayout(new GridLayout()); |
441 |
|
442 |
Label description = new Label(container, SWT.WRAP); |
443 |
description.setText(PDEUIMessages.JavaArgumentsTab_description); |
444 |
GridData gd = new GridData(); |
445 |
gd.widthHint = 200; |
446 |
description.setLayoutData(gd); |
447 |
|
448 |
Group programGroup = new Group(container, SWT.NONE); |
449 |
programGroup.setLayout(new GridLayout()); |
450 |
programGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
451 |
programGroup.setText(PDEUIMessages.JavaArgumentsTab_progamArgsGroup); |
452 |
|
453 |
fProgramArgs = new Text(programGroup, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL); |
454 |
gd = new GridData(GridData.FILL_BOTH); |
455 |
gd.widthHint = 200; |
456 |
gd.heightHint = 60; |
457 |
fProgramArgs.setLayoutData(gd); |
458 |
fProgramArgs.addModifyListener(new ModifyListener() { |
459 |
public void modifyText(ModifyEvent e) { |
460 |
getTargetDefinition().setProgramArguments(fProgramArgs.getText().trim()); |
461 |
} |
462 |
}); |
463 |
|
464 |
Button programVars = new Button(programGroup, SWT.NONE); |
465 |
programVars.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); |
466 |
programVars.setText(PDEUIMessages.JavaArgumentsTab_programVariables); |
467 |
programVars.addSelectionListener(getListener(fProgramArgs)); |
468 |
|
469 |
Group vmGroup = new Group(container, SWT.NONE); |
470 |
vmGroup.setLayout(new GridLayout(2, false)); |
471 |
vmGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
472 |
vmGroup.setText(PDEUIMessages.JavaArgumentsTab_vmArgsGroup); |
473 |
|
474 |
fVMArgs = new Text(vmGroup, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL); |
475 |
gd = new GridData(GridData.FILL_BOTH); |
476 |
gd.widthHint = 200; |
477 |
gd.heightHint = 60; |
478 |
gd.horizontalSpan = 2; |
479 |
fVMArgs.setLayoutData(gd); |
480 |
fVMArgs.addModifyListener(new ModifyListener() { |
481 |
public void modifyText(ModifyEvent e) { |
482 |
getTargetDefinition().setVMArguments(fVMArgs.getText().trim()); |
483 |
} |
484 |
}); |
485 |
|
486 |
fAppendLauncherArgs = new Button(vmGroup, SWT.CHECK); |
487 |
fAppendLauncherArgs.setText(PDEUIMessages.JavaArgumentsTab_appendLauncherIni); |
488 |
|
489 |
Button vmVars = new Button(vmGroup, SWT.NONE); |
490 |
vmVars.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); |
491 |
vmVars.setText(PDEUIMessages.JavaArgumentsTab_vmVariables); |
492 |
vmVars.addSelectionListener(getListener(fVMArgs)); |
493 |
return container; |
494 |
} |
495 |
|
496 |
protected SelectionListener getListener(final Text textControl) { |
497 |
return new SelectionListener() { |
498 |
public void widgetSelected(SelectionEvent e) { |
499 |
StringVariableSelectionDialog dialog = new StringVariableSelectionDialog(getShell()); |
500 |
dialog.open(); |
501 |
String variable = dialog.getVariableExpression(); |
502 |
if (variable != null) { |
503 |
textControl.insert(variable); |
504 |
} |
505 |
} |
506 |
|
507 |
public void widgetDefaultSelected(SelectionEvent e) { |
508 |
} |
509 |
}; |
510 |
} |
511 |
|
512 |
private Control createImplicitTabContents(Composite parent) { |
513 |
Composite container = new Composite(parent, SWT.NONE); |
514 |
GridLayout layout = new GridLayout(2, false); |
515 |
container.setLayout(layout); |
516 |
container.setLayoutData(new GridData(GridData.FILL_BOTH)); |
517 |
|
518 |
createImpLabel(container); |
519 |
createImpTable(container); |
520 |
createImpButtons(container); |
521 |
// TODO: PlatformUI.getWorkbench().getHelpSystem().setHelp(container, IHelpContextIds.IMPLICIT_PLUGINS_PREFERENCE_PAGE); |
522 |
return container; |
523 |
} |
524 |
|
525 |
private void createImpLabel(Composite container) { |
526 |
Label label = new Label(container, SWT.NONE); |
527 |
label.setText(PDEUIMessages.TargetImplicitPluginsTab_desc); |
528 |
GridData gd = new GridData(GridData.FILL_HORIZONTAL); |
529 |
gd.horizontalSpan = 2; |
530 |
label.setLayoutData(gd); |
531 |
} |
532 |
|
533 |
private void createImpTable(Composite container) { |
534 |
fElementViewer = new TableViewer(container, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER); |
535 |
GridData gd = new GridData(GridData.FILL_BOTH); |
536 |
fElementViewer.getControl().setLayoutData(gd); |
537 |
fElementViewer.setContentProvider(new DefaultTableProvider() { |
538 |
public Object[] getElements(Object inputElement) { |
539 |
ITargetDefinition target = getTargetDefinition(); |
540 |
if (target != null) { |
541 |
BundleInfo[] bundles = target.getImplicitDependencies(); |
542 |
if (bundles != null) { |
543 |
return bundles; |
544 |
} |
545 |
} |
546 |
return new BundleInfo[0]; |
547 |
} |
548 |
}); |
549 |
fElementViewer.setLabelProvider(new LabelProvider() { |
550 |
public String getText(Object element) { |
551 |
if (element instanceof BundleInfo) { |
552 |
return ((BundleInfo) element).getSymbolicName(); |
553 |
} |
554 |
return super.getText(element); |
555 |
} |
556 |
// TODO: labels |
557 |
}); |
558 |
fElementViewer.setInput(PDEPlugin.getDefault()); |
559 |
fElementViewer.setComparator(new ViewerComparator() { |
560 |
public int compare(Viewer viewer, Object e1, Object e2) { |
561 |
BundleInfo bundle1 = (BundleInfo) e1; |
562 |
BundleInfo bundle2 = (BundleInfo) e2; |
563 |
return super.compare(viewer, bundle1.getSymbolicName(), bundle2.getSymbolicName()); |
564 |
} |
565 |
}); |
566 |
fElementViewer.addSelectionChangedListener(new ISelectionChangedListener() { |
567 |
public void selectionChanged(SelectionChangedEvent event) { |
568 |
updateImpButtons(); |
569 |
} |
570 |
}); |
571 |
fElementViewer.getTable().addKeyListener(new KeyAdapter() { |
572 |
public void keyPressed(KeyEvent e) { |
573 |
if (e.character == SWT.DEL && e.stateMask == 0) { |
574 |
handleRemove(); |
575 |
} |
576 |
} |
577 |
}); |
578 |
|
579 |
} |
580 |
|
581 |
private void createImpButtons(Composite container) { |
582 |
Composite buttonContainer = new Composite(container, SWT.NONE); |
583 |
GridLayout layout = new GridLayout(); |
584 |
layout.marginWidth = layout.marginHeight = 0; |
585 |
buttonContainer.setLayout(layout); |
586 |
buttonContainer.setLayoutData(new GridData(GridData.FILL_VERTICAL)); |
587 |
|
588 |
fAddButton = new Button(buttonContainer, SWT.PUSH); |
589 |
fAddButton.setText(PDEUIMessages.SourceBlock_add); |
590 |
fAddButton.setLayoutData(new GridData(GridData.FILL | GridData.VERTICAL_ALIGN_BEGINNING)); |
591 |
SWTUtil.setButtonDimensionHint(fAddButton); |
592 |
fAddButton.addSelectionListener(new SelectionAdapter() { |
593 |
public void widgetSelected(SelectionEvent e) { |
594 |
handleAdd(); |
595 |
} |
596 |
}); |
597 |
|
598 |
fRemoveButton = new Button(buttonContainer, SWT.PUSH); |
599 |
fRemoveButton.setText(PDEUIMessages.SourceBlock_remove); |
600 |
fRemoveButton.setLayoutData(new GridData(GridData.FILL | GridData.VERTICAL_ALIGN_BEGINNING)); |
601 |
SWTUtil.setButtonDimensionHint(fRemoveButton); |
602 |
fRemoveButton.addSelectionListener(new SelectionAdapter() { |
603 |
public void widgetSelected(SelectionEvent e) { |
604 |
handleRemove(); |
605 |
} |
606 |
}); |
607 |
|
608 |
fRemoveAllButton = new Button(buttonContainer, SWT.PUSH); |
609 |
fRemoveAllButton.setText(PDEUIMessages.TargetImplicitPluginsTab_removeAll3); |
610 |
fRemoveAllButton.setLayoutData(new GridData(GridData.FILL | GridData.VERTICAL_ALIGN_BEGINNING)); |
611 |
SWTUtil.setButtonDimensionHint(fRemoveAllButton); |
612 |
fRemoveAllButton.addSelectionListener(new SelectionAdapter() { |
613 |
public void widgetSelected(SelectionEvent e) { |
614 |
handleRemoveAll(); |
615 |
} |
616 |
}); |
617 |
updateImpButtons(); |
618 |
} |
619 |
|
620 |
protected void handleAdd() { |
621 |
ElementListSelectionDialog dialog = new ElementListSelectionDialog(PDEPlugin.getActiveWorkbenchShell(), PDEPlugin.getDefault().getLabelProvider()); |
622 |
|
623 |
dialog.setElements(getValidBundles()); |
624 |
dialog.setTitle(PDEUIMessages.PluginSelectionDialog_title); |
625 |
dialog.setMessage(PDEUIMessages.PluginSelectionDialog_message); |
626 |
dialog.setMultipleSelection(true); |
627 |
if (dialog.open() == Window.OK) { |
628 |
Object[] models = dialog.getResult(); |
629 |
ArrayList pluginsToAdd = new ArrayList(); |
630 |
for (int i = 0; i < models.length; i++) { |
631 |
BundleDescription desc = ((BundleDescription) models[i]); |
632 |
pluginsToAdd.add(new BundleInfo(desc.getSymbolicName(), null, null, BundleInfo.NO_LEVEL, false)); |
633 |
} |
634 |
Set allDependencies = new HashSet(); |
635 |
allDependencies.addAll(pluginsToAdd); |
636 |
BundleInfo[] currentBundles = getTargetDefinition().getImplicitDependencies(); |
637 |
if (currentBundles != null) { |
638 |
allDependencies.addAll(Arrays.asList(currentBundles)); |
639 |
} |
640 |
getTargetDefinition().setImplicitDependencies((BundleInfo[]) allDependencies.toArray(new BundleInfo[allDependencies.size()])); |
641 |
fElementViewer.refresh(); |
642 |
// update target |
643 |
} |
644 |
} |
645 |
|
646 |
/** |
647 |
* Gets a list of all the bundles that can be added as implicit dependencies |
648 |
* @return list of possible dependencies |
649 |
*/ |
650 |
protected BundleDescription[] getValidBundles() { |
651 |
BundleInfo[] current = getTargetDefinition().getImplicitDependencies(); |
652 |
Set currentBundles = new HashSet(); |
653 |
if (current != null) { |
654 |
for (int i = 0; i < current.length; i++) { |
655 |
currentBundles.add(current[i].getSymbolicName()); |
656 |
} |
657 |
} |
658 |
|
659 |
// TODO Do we want to get the possible models from the plugin registry? Would be better to get the bundles from the editor's target definition? |
660 |
IPluginModelBase[] models = PluginRegistry.getActiveModels(false); |
661 |
Set result = new HashSet(); |
662 |
for (int i = 0; i < models.length; i++) { |
663 |
BundleDescription desc = models[i].getBundleDescription(); |
664 |
if (desc != null) { |
665 |
if (!currentBundles.contains(desc.getSymbolicName())) |
666 |
result.add(desc); |
667 |
} |
668 |
} |
669 |
|
670 |
return (BundleDescription[]) result.toArray((new BundleDescription[result.size()])); |
671 |
} |
672 |
|
673 |
private void handleRemove() { |
674 |
LinkedList bundles = new LinkedList(); |
675 |
bundles.addAll(Arrays.asList(getTargetDefinition().getImplicitDependencies())); |
676 |
Object[] removeBundles = ((IStructuredSelection) fElementViewer.getSelection()).toArray(); |
677 |
if (removeBundles.length > 0) { |
678 |
for (int i = 0; i < removeBundles.length; i++) { |
679 |
if (removeBundles[i] instanceof BundleInfo) { |
680 |
bundles.remove(removeBundles[i]); |
681 |
} |
682 |
} |
683 |
getTargetDefinition().setImplicitDependencies((BundleInfo[]) bundles.toArray((new BundleInfo[bundles.size()]))); |
684 |
fElementViewer.refresh(); |
685 |
} |
686 |
} |
687 |
|
688 |
private void handleRemoveAll() { |
689 |
getTargetDefinition().setImplicitDependencies(null); |
690 |
fElementViewer.refresh(); |
691 |
} |
692 |
|
693 |
private void updateImpButtons() { |
694 |
boolean empty = fElementViewer.getSelection().isEmpty(); |
695 |
fRemoveButton.setEnabled(!empty); |
696 |
boolean hasElements = fElementViewer.getTable().getItemCount() > 0; |
697 |
fRemoveAllButton.setEnabled(hasElements); |
698 |
} |
699 |
} |