|
Lines 1-233
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2005, 2009 IBM Corporation and others. |
2 |
* Copyright (c) 2005, 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.core.runtime.CoreException; |
13 |
import org.eclipse.core.runtime.CoreException; |
| 14 |
import org.eclipse.core.runtime.IConfigurationElement; |
14 |
import org.eclipse.core.runtime.IConfigurationElement; |
| 15 |
import org.eclipse.jface.dialogs.Dialog; |
15 |
import org.eclipse.jface.dialogs.Dialog; |
| 16 |
import org.eclipse.jface.wizard.IWizardPage; |
16 |
import org.eclipse.jface.wizard.IWizardPage; |
| 17 |
import org.eclipse.jface.wizard.WizardSelectionPage; |
17 |
import org.eclipse.jface.wizard.WizardSelectionPage; |
| 18 |
import org.eclipse.pde.internal.core.PDECore; |
18 |
import org.eclipse.pde.internal.core.PDECore; |
| 19 |
import org.eclipse.pde.internal.core.target.TargetPlatformService; |
19 |
import org.eclipse.pde.internal.core.target.TargetPlatformService; |
| 20 |
import org.eclipse.pde.internal.core.target.provisional.ITargetDefinition; |
20 |
import org.eclipse.pde.internal.core.target.provisional.ITargetDefinition; |
| 21 |
import org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService; |
21 |
import org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService; |
| 22 |
import org.eclipse.pde.internal.ui.PDEUIMessages; |
22 |
import org.eclipse.pde.internal.ui.*; |
| 23 |
import org.eclipse.pde.internal.ui.SWTFactory; |
23 |
import org.eclipse.swt.SWT; |
| 24 |
import org.eclipse.swt.SWT; |
24 |
import org.eclipse.swt.events.SelectionAdapter; |
| 25 |
import org.eclipse.swt.events.SelectionAdapter; |
25 |
import org.eclipse.swt.events.SelectionEvent; |
| 26 |
import org.eclipse.swt.events.SelectionEvent; |
26 |
import org.eclipse.swt.layout.GridData; |
| 27 |
import org.eclipse.swt.layout.GridData; |
27 |
import org.eclipse.swt.widgets.*; |
| 28 |
import org.eclipse.swt.widgets.*; |
28 |
import org.eclipse.ui.PlatformUI; |
| 29 |
|
29 |
|
| 30 |
/** |
30 |
/** |
| 31 |
* First wizard page used to create a target definition. Defines the location where |
31 |
* First wizard page used to create a target definition. Defines the location where |
| 32 |
* the definition will be created and how to seed the definition. |
32 |
* the definition will be created and how to seed the definition. |
| 33 |
*/ |
33 |
*/ |
| 34 |
public class TargetCreationPage extends WizardSelectionPage { |
34 |
public class TargetCreationPage extends WizardSelectionPage { |
| 35 |
|
35 |
|
| 36 |
protected static final int USE_EMPTY = 0; |
36 |
protected static final int USE_EMPTY = 0; |
| 37 |
protected static final int USE_DEFAULT = 1; |
37 |
protected static final int USE_DEFAULT = 1; |
| 38 |
protected static final int USE_CURRENT_TP = 2; |
38 |
protected static final int USE_CURRENT_TP = 2; |
| 39 |
protected static final int USE_EXISTING_TARGET = 3; |
39 |
protected static final int USE_EXISTING_TARGET = 3; |
| 40 |
|
40 |
|
| 41 |
private Button fEmptyButton; |
41 |
private Button fEmptyButton; |
| 42 |
private Button fDefaultButton; |
42 |
private Button fDefaultButton; |
| 43 |
private Button fCurrentTPButton; |
43 |
private Button fCurrentTPButton; |
| 44 |
private Button fExistingTargetButton; |
44 |
private Button fExistingTargetButton; |
| 45 |
private Combo fTargets; |
45 |
private Combo fTargets; |
| 46 |
private String[] fTargetIds; |
46 |
private String[] fTargetIds; |
| 47 |
private String templateTargetId; |
47 |
private String templateTargetId; |
| 48 |
private ITargetDefinition[] fTargetDefs = new ITargetDefinition[4]; |
48 |
private ITargetDefinition[] fTargetDefs = new ITargetDefinition[4]; |
| 49 |
|
49 |
|
| 50 |
public TargetCreationPage(String pageName) { |
50 |
public TargetCreationPage(String pageName) { |
| 51 |
super(pageName); |
51 |
super(pageName); |
| 52 |
setTitle(PDEUIMessages.TargetProfileWizardPage_title); |
52 |
setTitle(PDEUIMessages.TargetProfileWizardPage_title); |
| 53 |
setDescription(PDEUIMessages.TargetProfileWizardPage_description); |
53 |
setDescription(PDEUIMessages.TargetProfileWizardPage_description); |
| 54 |
} |
54 |
} |
| 55 |
|
55 |
|
| 56 |
/** |
56 |
/** |
| 57 |
* Returns the target service or <code>null</code> if none. |
57 |
* Returns the target service or <code>null</code> if none. |
| 58 |
* |
58 |
* |
| 59 |
* @return target service or <code>null</code> |
59 |
* @return target service or <code>null</code> |
| 60 |
*/ |
60 |
*/ |
| 61 |
protected ITargetPlatformService getTargetService() { |
61 |
protected ITargetPlatformService getTargetService() { |
| 62 |
return (ITargetPlatformService) PDECore.getDefault().acquireService(ITargetPlatformService.class.getName()); |
62 |
return (ITargetPlatformService) PDECore.getDefault().acquireService(ITargetPlatformService.class.getName()); |
| 63 |
} |
63 |
} |
| 64 |
|
64 |
|
| 65 |
/* (non-Javadoc) |
65 |
/* (non-Javadoc) |
| 66 |
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) |
66 |
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) |
| 67 |
*/ |
67 |
*/ |
| 68 |
public void createControl(Composite parent) { |
68 |
public void createControl(Composite parent) { |
| 69 |
Composite comp = SWTFactory.createComposite(parent, 2, 1, GridData.FILL_BOTH); |
69 |
Composite comp = SWTFactory.createComposite(parent, 2, 1, GridData.FILL_BOTH); |
| 70 |
SWTFactory.createLabel(comp, PDEUIMessages.TargetCreationPage_0, 3); |
70 |
SWTFactory.createLabel(comp, PDEUIMessages.TargetCreationPage_0, 3); |
| 71 |
|
71 |
|
| 72 |
fEmptyButton = SWTFactory.createRadioButton(comp, PDEUIMessages.TargetCreationPage_1, 2); |
72 |
fEmptyButton = SWTFactory.createRadioButton(comp, PDEUIMessages.TargetCreationPage_1, 2); |
| 73 |
fDefaultButton = SWTFactory.createRadioButton(comp, PDEUIMessages.TargetCreationPage_2, 2); |
73 |
fDefaultButton = SWTFactory.createRadioButton(comp, PDEUIMessages.TargetCreationPage_2, 2); |
| 74 |
fCurrentTPButton = SWTFactory.createRadioButton(comp, PDEUIMessages.TargetCreationPage_3, 2); |
74 |
fCurrentTPButton = SWTFactory.createRadioButton(comp, PDEUIMessages.TargetCreationPage_3, 2); |
| 75 |
fExistingTargetButton = SWTFactory.createRadioButton(comp, PDEUIMessages.TargetCreationPage_4, 1); |
75 |
fExistingTargetButton = SWTFactory.createRadioButton(comp, PDEUIMessages.TargetCreationPage_4, 1); |
| 76 |
fExistingTargetButton.addSelectionListener(new SelectionAdapter() { |
76 |
fExistingTargetButton.addSelectionListener(new SelectionAdapter() { |
| 77 |
public void widgetSelected(SelectionEvent e) { |
77 |
public void widgetSelected(SelectionEvent e) { |
| 78 |
boolean enabled = fExistingTargetButton.getSelection(); |
78 |
boolean enabled = fExistingTargetButton.getSelection(); |
| 79 |
fTargets.setEnabled(enabled); |
79 |
fTargets.setEnabled(enabled); |
| 80 |
} |
80 |
} |
| 81 |
}); |
81 |
}); |
| 82 |
|
82 |
|
| 83 |
fEmptyButton.setSelection(true); |
83 |
fEmptyButton.setSelection(true); |
| 84 |
|
84 |
|
| 85 |
fTargets = SWTFactory.createCombo(comp, SWT.SINGLE | SWT.READ_ONLY, 1, GridData.BEGINNING, null); |
85 |
fTargets = SWTFactory.createCombo(comp, SWT.SINGLE | SWT.READ_ONLY, 1, GridData.BEGINNING, null); |
| 86 |
fTargets.setEnabled(false); |
86 |
fTargets.setEnabled(false); |
| 87 |
initializeTargetCombo(); |
87 |
initializeTargetCombo(); |
| 88 |
fTargets.addSelectionListener(new SelectionAdapter() { |
88 |
fTargets.addSelectionListener(new SelectionAdapter() { |
| 89 |
|
89 |
|
| 90 |
public void widgetSelected(SelectionEvent e) { |
90 |
public void widgetSelected(SelectionEvent e) { |
| 91 |
templateTargetId = fTargetIds[fTargets.getSelectionIndex()]; |
91 |
templateTargetId = fTargetIds[fTargets.getSelectionIndex()]; |
| 92 |
|
92 |
|
| 93 |
} |
93 |
} |
| 94 |
}); |
94 |
}); |
| 95 |
|
95 |
|
| 96 |
Dialog.applyDialogFont(comp); |
96 |
PlatformUI.getWorkbench().getHelpSystem().setHelp(comp, IHelpContextIds.NEW_TARGET_WIZARD); |
| 97 |
setSelectedNode(new EditTargetNode()); |
97 |
|
| 98 |
setControl(comp); |
98 |
Dialog.applyDialogFont(comp); |
| 99 |
setPageComplete(true); |
99 |
setSelectedNode(new EditTargetNode()); |
| 100 |
} |
100 |
setControl(comp); |
| 101 |
|
101 |
setPageComplete(true); |
| 102 |
protected void initializeTargetCombo() { |
102 |
} |
| 103 |
IConfigurationElement[] elements = PDECore.getDefault().getTargetProfileManager().getSortedTargets(); |
103 |
|
| 104 |
fTargetIds = new String[elements.length]; |
104 |
protected void initializeTargetCombo() { |
| 105 |
for (int i = 0; i < elements.length; i++) { |
105 |
IConfigurationElement[] elements = PDECore.getDefault().getTargetProfileManager().getSortedTargets(); |
| 106 |
String name = elements[i].getAttribute("name"); //$NON-NLS-1$ |
106 |
fTargetIds = new String[elements.length]; |
| 107 |
if (fTargets.indexOf(name) == -1) |
107 |
for (int i = 0; i < elements.length; i++) { |
| 108 |
fTargets.add(name); |
108 |
String name = elements[i].getAttribute("name"); //$NON-NLS-1$ |
| 109 |
fTargetIds[i] = elements[i].getAttribute("id"); //$NON-NLS-1$ |
109 |
if (fTargets.indexOf(name) == -1) |
| 110 |
} |
110 |
fTargets.add(name); |
| 111 |
if (elements.length > 0) { |
111 |
fTargetIds[i] = elements[i].getAttribute("id"); //$NON-NLS-1$ |
| 112 |
fTargets.select(0); |
112 |
} |
| 113 |
setTargetId(fTargetIds[fTargets.getSelectionIndex()]); |
113 |
if (elements.length > 0) { |
| 114 |
} |
114 |
fTargets.select(0); |
| 115 |
} |
115 |
setTargetId(fTargetIds[fTargets.getSelectionIndex()]); |
| 116 |
|
116 |
} |
| 117 |
protected int getInitializationOption() { |
117 |
} |
| 118 |
if (fEmptyButton.getSelection()) |
118 |
|
| 119 |
return USE_EMPTY; |
119 |
protected int getInitializationOption() { |
| 120 |
if (fDefaultButton.getSelection()) |
120 |
if (fEmptyButton.getSelection()) |
| 121 |
return USE_DEFAULT; |
121 |
return USE_EMPTY; |
| 122 |
else if (fCurrentTPButton.getSelection()) |
122 |
if (fDefaultButton.getSelection()) |
| 123 |
return USE_CURRENT_TP; |
123 |
return USE_DEFAULT; |
| 124 |
return USE_EXISTING_TARGET; |
124 |
else if (fCurrentTPButton.getSelection()) |
| 125 |
} |
125 |
return USE_CURRENT_TP; |
| 126 |
|
126 |
return USE_EXISTING_TARGET; |
| 127 |
protected String getTargetId() { |
127 |
} |
| 128 |
return templateTargetId; |
128 |
|
| 129 |
} |
129 |
protected String getTargetId() { |
| 130 |
|
130 |
return templateTargetId; |
| 131 |
protected void setTargetId(String targetId) { |
131 |
} |
| 132 |
templateTargetId = targetId; |
132 |
|
| 133 |
} |
133 |
protected void setTargetId(String targetId) { |
| 134 |
|
134 |
templateTargetId = targetId; |
| 135 |
protected ITargetDefinition createTarget(int targetOption) { |
135 |
} |
| 136 |
ITargetPlatformService service = getTargetService(); |
136 |
|
| 137 |
if (service != null) { |
137 |
protected ITargetDefinition createTarget(int targetOption) { |
| 138 |
ITargetDefinition definition = service.newTarget(); |
138 |
ITargetPlatformService service = getTargetService(); |
| 139 |
switch (targetOption) { |
139 |
if (service != null) { |
| 140 |
case USE_EMPTY : |
140 |
ITargetDefinition definition = service.newTarget(); |
| 141 |
definition.setName(PDEUIMessages.TargetCreationPage_6); |
141 |
switch (targetOption) { |
| 142 |
break; |
142 |
case USE_EMPTY : |
| 143 |
case USE_DEFAULT : |
143 |
definition.setName(PDEUIMessages.TargetCreationPage_6); |
| 144 |
try { |
144 |
break; |
| 145 |
populateBasicTarget(definition); |
145 |
case USE_DEFAULT : |
| 146 |
} catch (CoreException e) { |
146 |
try { |
| 147 |
setErrorMessage(e.getMessage()); |
147 |
populateBasicTarget(definition); |
| 148 |
return null; |
148 |
} catch (CoreException e) { |
| 149 |
} |
149 |
setErrorMessage(e.getMessage()); |
| 150 |
break; |
150 |
return null; |
| 151 |
case USE_CURRENT_TP : |
151 |
} |
| 152 |
try { |
152 |
break; |
| 153 |
populateFromCurrentTargetPlatform(definition); |
153 |
case USE_CURRENT_TP : |
| 154 |
} catch (CoreException e) { |
154 |
try { |
| 155 |
setErrorMessage(e.getMessage()); |
155 |
populateFromCurrentTargetPlatform(definition); |
| 156 |
return null; |
156 |
} catch (CoreException e) { |
| 157 |
} |
157 |
setErrorMessage(e.getMessage()); |
| 158 |
break; |
158 |
return null; |
| 159 |
case USE_EXISTING_TARGET : |
159 |
} |
| 160 |
try { |
160 |
break; |
| 161 |
populateFromTemplate(definition, getTargetId()); |
161 |
case USE_EXISTING_TARGET : |
| 162 |
} catch (CoreException e) { |
162 |
try { |
| 163 |
setErrorMessage(e.getMessage()); |
163 |
populateFromTemplate(definition, getTargetId()); |
| 164 |
return null; |
164 |
} catch (CoreException e) { |
| 165 |
} |
165 |
setErrorMessage(e.getMessage()); |
| 166 |
break; |
166 |
return null; |
| 167 |
} |
167 |
} |
| 168 |
return definition; |
168 |
break; |
| 169 |
} |
169 |
} |
| 170 |
return null; |
170 |
return definition; |
| 171 |
} |
171 |
} |
| 172 |
|
172 |
return null; |
| 173 |
/** |
173 |
} |
| 174 |
* Applies basic target settings to the given target definition. |
174 |
|
| 175 |
* |
175 |
/** |
| 176 |
* @param definition |
176 |
* Applies basic target settings to the given target definition. |
| 177 |
* @throws CoreException |
177 |
* |
| 178 |
*/ |
178 |
* @param definition |
| 179 |
private void populateBasicTarget(ITargetDefinition definition) throws CoreException { |
179 |
* @throws CoreException |
| 180 |
ITargetPlatformService service = getTargetService(); |
180 |
*/ |
| 181 |
if (service instanceof TargetPlatformService) { |
181 |
private void populateBasicTarget(ITargetDefinition definition) throws CoreException { |
| 182 |
TargetPlatformService ts = (TargetPlatformService) service; |
182 |
ITargetPlatformService service = getTargetService(); |
| 183 |
ITargetDefinition def = ts.newDefaultTargetDefinition(); |
183 |
if (service instanceof TargetPlatformService) { |
| 184 |
ts.copyTargetDefinition(def, definition); |
184 |
TargetPlatformService ts = (TargetPlatformService) service; |
| 185 |
} |
185 |
ITargetDefinition def = ts.newDefaultTargetDefinition(); |
| 186 |
} |
186 |
ts.copyTargetDefinition(def, definition); |
| 187 |
|
187 |
} |
| 188 |
/** |
188 |
} |
| 189 |
* Populates the given definition from current target platform settings. |
189 |
|
| 190 |
* |
190 |
/** |
| 191 |
* @param definition |
191 |
* Populates the given definition from current target platform settings. |
| 192 |
* @throws CoreException |
192 |
* |
| 193 |
*/ |
193 |
* @param definition |
| 194 |
private void populateFromCurrentTargetPlatform(ITargetDefinition definition) throws CoreException { |
194 |
* @throws CoreException |
| 195 |
ITargetPlatformService service = getTargetService(); |
195 |
*/ |
| 196 |
if (service instanceof TargetPlatformService) { |
196 |
private void populateFromCurrentTargetPlatform(ITargetDefinition definition) throws CoreException { |
| 197 |
TargetPlatformService ts = (TargetPlatformService) service; |
197 |
ITargetPlatformService service = getTargetService(); |
| 198 |
ts.loadTargetDefinitionFromPreferences(definition); |
198 |
if (service instanceof TargetPlatformService) { |
| 199 |
} |
199 |
TargetPlatformService ts = (TargetPlatformService) service; |
| 200 |
} |
200 |
ts.loadTargetDefinitionFromPreferences(definition); |
| 201 |
|
201 |
} |
| 202 |
/** |
202 |
} |
| 203 |
* Populates the given definition from the specified target template. |
203 |
|
| 204 |
* |
204 |
/** |
| 205 |
* @param definition |
205 |
* Populates the given definition from the specified target template. |
| 206 |
* @param id target extension identifier |
206 |
* |
| 207 |
* @exception CoreException if unable to complete |
207 |
* @param definition |
| 208 |
*/ |
208 |
* @param id target extension identifier |
| 209 |
private void populateFromTemplate(ITargetDefinition definition, String id) throws CoreException { |
209 |
* @exception CoreException if unable to complete |
| 210 |
ITargetPlatformService service = getTargetService(); |
210 |
*/ |
| 211 |
if (service != null) { |
211 |
private void populateFromTemplate(ITargetDefinition definition, String id) throws CoreException { |
| 212 |
service.loadTargetDefinition(definition, id); |
212 |
ITargetPlatformService service = getTargetService(); |
| 213 |
} |
213 |
if (service != null) { |
| 214 |
} |
214 |
service.loadTargetDefinition(definition, id); |
| 215 |
|
215 |
} |
| 216 |
/* (non-Javadoc) |
216 |
} |
| 217 |
* @see org.eclipse.jface.wizard.WizardSelectionPage#getNextPage() |
217 |
|
| 218 |
*/ |
218 |
/* (non-Javadoc) |
| 219 |
public IWizardPage getNextPage() { |
219 |
* @see org.eclipse.jface.wizard.WizardSelectionPage#getNextPage() |
| 220 |
ITargetDefinition target = null; |
220 |
*/ |
| 221 |
int option = getInitializationOption(); |
221 |
public IWizardPage getNextPage() { |
| 222 |
if (fTargetDefs[option] == null) { |
222 |
ITargetDefinition target = null; |
| 223 |
fTargetDefs[option] = createTarget(option); |
223 |
int option = getInitializationOption(); |
| 224 |
} |
224 |
if (fTargetDefs[option] == null) { |
| 225 |
target = fTargetDefs[option]; |
225 |
fTargetDefs[option] = createTarget(option); |
| 226 |
if (target != null) { |
226 |
} |
| 227 |
((NewTargetDefinitionWizard2) getWizard()).setTargetDefinition(target); |
227 |
target = fTargetDefs[option]; |
| 228 |
((EditTargetNode) getSelectedNode()).setTargetDefinition(target); |
228 |
if (target != null) { |
| 229 |
return super.getNextPage(); |
229 |
((NewTargetDefinitionWizard2) getWizard()).setTargetDefinition(target); |
| 230 |
} |
230 |
((EditTargetNode) getSelectedNode()).setTargetDefinition(target); |
| 231 |
return null; |
231 |
return super.getNextPage(); |
| 232 |
} |
232 |
} |
| 233 |
} |
233 |
return null; |
|
|
234 |
} |
| 235 |
} |