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

Collapse All | Expand All

(-)src/org/eclipse/pde/internal/ui/editor/product/JRESection.java (-61 / +58 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
			IExecutionEnvironment env = (IExecutionEnvironment) element;
48
			IPath path = JavaRuntime.newJREContainerPath(env);
49
			IVMInstall install = JavaRuntime.getVMInstall(path);
50
			String eeItem;
51
			if (install != null) {
52
				eeItem = MessageFormat.format(PDEUIMessages.JRESection_eeBoundJRE, new String[] {env.getId(), install.getName()});
53
			} else {
54
				eeItem = MessageFormat.format(PDEUIMessages.JRESection_eeUnboundJRE, new String[] {env.getId()});
55
			}
56
			return eeItem;
57
		}
58
	}
59
60
	private final class JRELabelProvider extends LabelProvider {
61
		public String getText(Object element) {
62
			if (element instanceof IVMInstall) {
63
				IVMInstall vm = (IVMInstall) element;
64
				return vm.getName();
65
			}
66
			// else: null-object
67
			return ""; //$NON-NLS-1$
68
		}
69
	}
70
45
	private Button fJRERadioButton;
71
	private Button fJRERadioButton;
46
	private Button fEERadioButton;
72
	private Button fEERadioButton;
47
	private Button fInstalledJREsButton;
73
	private Button fInstalledJREsButton;
48
	private Button fExecutionEnvironmentsButton;
74
	private Button fExecutionEnvironmentsButton;
49
	private ComboPart fJREsCombo;
75
	private ComboViewerPart fJREsCombo;
50
	private ComboPart fEEsCombo;
76
	private ComboViewerPart fEEsCombo;
51
	private ArrayList fEEChoices;
52
	private boolean fBlockChanges;
77
	private boolean fBlockChanges;
53
78
54
	private static final String[] TAB_LABELS = {"linux", "macosx", "solaris", "win32"}; //$NON-NLS-1$  //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
79
	private static final String[] TAB_LABELS = {"linux", "macosx", "solaris", "win32"}; //$NON-NLS-1$  //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
Lines 98-117 Link Here
98
		fJRERadioButton.addSelectionListener(new SelectionAdapter() {
123
		fJRERadioButton.addSelectionListener(new SelectionAdapter() {
99
			public void widgetSelected(SelectionEvent e) {
124
			public void widgetSelected(SelectionEvent e) {
100
				updateWidgets();
125
				updateWidgets();
101
				setJRE(fJREsCombo.getSelection());
126
				setJRE((IVMInstall) fJREsCombo.getSelection());
102
			}
127
			}
103
		});
128
		});
104
129
105
		fJREsCombo = new ComboPart();
130
		fJREsCombo = new ComboViewerPart();
106
		fJREsCombo.createControl(client, toolkit, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY);
131
		fJREsCombo.createControl(client, toolkit, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY);
107
		fJREsCombo.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
132
		fJREsCombo.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
108
		String[] installs = VMHelper.getVMInstallNames();
133
		fJREsCombo.setItems(VMHelper.getAllVMInstances());
109
		fJREsCombo.setItems(installs);
134
		fJREsCombo.addItem(null, 0);
110
		fJREsCombo.add("", 0); //$NON-NLS-1$
135
		fJREsCombo.setLabelProvider(new JRELabelProvider());
111
		fJREsCombo.addSelectionListener(new SelectionAdapter() {
136
		fJREsCombo.addSelectionChangedListener(new ISelectionChangedListener() {
112
			public void widgetSelected(SelectionEvent e) {
137
			public void selectionChanged(SelectionChangedEvent event) {
113
				if (!fBlockChanges)
138
				if (!fBlockChanges)
114
					setJRE(fJREsCombo.getSelection());
139
					setJRE(fJREsCombo.getSelection() == ComboViewerPart.NULL_OBJECT ? null : (IVMInstall) fJREsCombo.getSelection());
115
			}
140
			}
116
		});
141
		});
117
142
Lines 128-145 Link Here
128
		fEERadioButton.addSelectionListener(new SelectionAdapter() {
153
		fEERadioButton.addSelectionListener(new SelectionAdapter() {
129
			public void widgetSelected(SelectionEvent e) {
154
			public void widgetSelected(SelectionEvent e) {
130
				updateWidgets();
155
				updateWidgets();
131
				setEE(fEEsCombo.getSelectionIndex());
156
				setEE((IExecutionEnvironment) fEEsCombo.getSelection());
132
			}
157
			}
133
		});
158
		});
134
159
135
		fEEsCombo = new ComboPart();
160
		fEEsCombo = new ComboViewerPart();
136
		fEEsCombo.createControl(client, toolkit, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY);
161
		fEEsCombo.createControl(client, toolkit, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY);
137
		fEEsCombo.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
162
		fEEsCombo.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
138
		initializeExecutionEnvironments();
163
		fEEsCombo.setLabelProvider(new EELabelProvider());
139
		fEEsCombo.addSelectionListener(new SelectionAdapter() {
164
		fEEsCombo.setComparator(new ViewerComparator());
140
			public void widgetSelected(SelectionEvent e) {
165
		fEEsCombo.setItems(VMHelper.getExecutionEnvironments());
166
		fEEsCombo.addSelectionChangedListener(new ISelectionChangedListener() {
167
			public void selectionChanged(SelectionChangedEvent event) {
141
				if (!fBlockChanges)
168
				if (!fBlockChanges)
142
					setEE(fEEsCombo.getSelectionIndex());
169
					setEE((IExecutionEnvironment) ((IStructuredSelection) event.getSelection()).getFirstElement());
143
			}
170
			}
144
		});
171
		});
145
172
Lines 159-208 Link Here
159
		getProductModel().addModelChangedListener(this);
186
		getProductModel().addModelChangedListener(this);
160
	}
187
	}
161
188
162
	private void setEE(int selectionIndex) {
189
	private void setEE(IExecutionEnvironment ee) {
163
		if (selectionIndex >= 0 && selectionIndex < fEEChoices.size()) {
190
		if (ee != null) {
164
			IExecutionEnvironment ee = (IExecutionEnvironment) fEEChoices.get(selectionIndex);
191
			IPath eePath = JavaRuntime.newJREContainerPath(ee);
165
			if (ee != null) {
192
			getJVMLocations().setJREContainerPath(getOS(fLastTab), eePath);
166
				IPath eePath = JavaRuntime.newJREContainerPath(ee);
167
				getJVMLocations().setJREContainerPath(getOS(fLastTab), eePath);
168
			}
169
		}
193
		}
170
	}
194
	}
171
195
172
	private void setJRE(String vmName) {
196
	private void setJRE(IVMInstall install) {
173
		IVMInstall install = VMHelper.getVMInstall(vmName);
174
		if (install != null) {
197
		if (install != null) {
175
			IPath jrePath = JavaRuntime.newJREContainerPath(install);
198
			IPath jrePath = JavaRuntime.newJREContainerPath(install);
176
			getJVMLocations().setJREContainerPath(getOS(fLastTab), jrePath);
199
			getJVMLocations().setJREContainerPath(getOS(fLastTab), jrePath);
177
		}
200
		}
178
	}
201
	}
179
202
180
	private void initializeExecutionEnvironments() {
181
		fEEChoices = new ArrayList();
182
		IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager();
183
		IExecutionEnvironment[] envs = manager.getExecutionEnvironments();
184
		for (int i = 0; i < envs.length; i++) {
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
	}
205
206
	private IProductModel getProductModel() {
203
	private IProductModel getProductModel() {
207
		return (IProductModel) getPage().getPDEEditor().getAggregateModel();
204
		return (IProductModel) getPage().getPDEEditor().getAggregateModel();
208
	}
205
	}
Lines 246-262 Link Here
246
			String eeID = JavaRuntime.getExecutionEnvironmentId(jrePath);
243
			String eeID = JavaRuntime.getExecutionEnvironmentId(jrePath);
247
			IExecutionEnvironment env = VMHelper.getExecutionEnvironment(eeID);
244
			IExecutionEnvironment env = VMHelper.getExecutionEnvironment(eeID);
248
			if (env != null) {
245
			if (env != null) {
249
				if (!fEEChoices.contains(env))
246
				if (!fEEsCombo.getItems().contains(env))
250
					addToEECombo(env);
247
					fEEsCombo.addItem(env);
251
				fEEsCombo.select(fEEsCombo.getItemCount() - 1);
248
				fEEsCombo.select(env);
252
				fEERadioButton.setSelection(true);
249
				fEERadioButton.setSelection(true);
253
				fJRERadioButton.setSelection(false);
250
				fJRERadioButton.setSelection(false);
254
			} else {
251
			} else {
255
				IVMInstall install = JavaRuntime.getVMInstall(jrePath);
252
				IVMInstall install = JavaRuntime.getVMInstall(jrePath);
256
				if (install != null) {
253
				if (install != null) {
257
					if (fJREsCombo.indexOf(install.getName()) < 0)
254
					if (!fJREsCombo.getItems().contains(install))
258
						fJREsCombo.add(install.getName());
255
						fJREsCombo.addItem(install);
259
					fJREsCombo.setText(install.getName());
256
					fJREsCombo.select(install);
260
					fJRERadioButton.setSelection(true);
257
					fJRERadioButton.setSelection(true);
261
					fEERadioButton.setSelection(false);
258
					fEERadioButton.setSelection(false);
262
				}
259
				}
(-)src/org/eclipse/pde/internal/ui/parts/ComboViewerPart.java (+109 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
	public static Object NULL_OBJECT = new Object();
28
29
	public ComboViewerPart() {
30
	}
31
32
	public void createControl(Composite parent, FormToolkit toolkit, int style) {
33
		if (toolkit.getBorderStyle() == SWT.BORDER) {
34
			fCombo = new Combo(parent, style | SWT.BORDER);
35
			fComboViewer = new ComboViewer((Combo) fCombo);
36
		} else {
37
			fCombo = new CCombo(parent, style | SWT.FLAT);
38
			fComboViewer = new ComboViewer((CCombo) fCombo);
39
		}
40
41
		fObjects = new ArrayList();
42
		fComboViewer.setLabelProvider(new LabelProvider());
43
		fComboViewer.setContentProvider(new ArrayContentProvider());
44
		fComboViewer.setInput(fObjects);
45
	}
46
47
	public Control getControl() {
48
		return fCombo;
49
	}
50
51
	public void setEnabled(boolean enabled) {
52
		fCombo.setEnabled(enabled);
53
	}
54
55
	public void refresh() {
56
		fComboViewer.refresh();
57
	}
58
59
	public void addItem(Object item) {
60
		fObjects.add((item == null) ? NULL_OBJECT : item);
61
		refresh();
62
	}
63
64
	public void addItem(Object item, int index) {
65
		fObjects.add(index, (item == null) ? NULL_OBJECT : item);
66
		refresh();
67
	}
68
69
	public Collection getItems() {
70
		return fObjects;
71
	}
72
73
	public void setItems(Object[] items) {
74
		fObjects.clear();
75
		for (int i = 0; i < items.length; i++)
76
			fObjects.add((items[i] == null) ? NULL_OBJECT : items[i]);
77
		refresh();
78
	}
79
80
	public void setItems(Collection items) {
81
		fObjects.clear();
82
		Iterator it = items.iterator();
83
		while (it.hasNext()) {
84
			Object o = it.next();
85
			fObjects.add((o == null) ? NULL_OBJECT : o);
86
		}
87
		refresh();
88
	}
89
90
	public void select(Object item) {
91
		fComboViewer.setSelection(new StructuredSelection(item));
92
	}
93
94
	public void setLabelProvider(IBaseLabelProvider labelProvider) {
95
		fComboViewer.setLabelProvider(labelProvider);
96
	}
97
98
	public void setComparator(ViewerComparator comparator) {
99
		fComboViewer.setComparator(comparator);
100
	}
101
102
	public void addSelectionChangedListener(ISelectionChangedListener listener) {
103
		fComboViewer.addSelectionChangedListener(listener);
104
	}
105
106
	public Object getSelection() {
107
		return ((IStructuredSelection) fComboViewer.getSelection()).getFirstElement();
108
	}
109
}

Return to bug 217908