Lines 1-5
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2008 Intel Corporation and others. |
2 |
* Copyright (c) 2008, 2009 Intel Corporation, QNX Software Systems, 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 |
Lines 7-94
Link Here
|
7 |
* |
7 |
* |
8 |
* Contributors: |
8 |
* Contributors: |
9 |
* Intel Corporation - initial API and implementation |
9 |
* Intel Corporation - initial API and implementation |
|
|
10 |
* QNX Software Systems - [272416] Rework the config sets dialog |
10 |
*******************************************************************************/ |
11 |
*******************************************************************************/ |
11 |
/** |
|
|
12 |
* |
13 |
*/ |
14 |
package org.eclipse.cdt.ui.actions; |
12 |
package org.eclipse.cdt.ui.actions; |
15 |
|
13 |
|
16 |
import java.util.ArrayList; |
|
|
17 |
import java.util.LinkedHashMap; |
18 |
import java.util.Map; |
19 |
|
20 |
import org.eclipse.core.resources.IProject; |
21 |
import org.eclipse.core.resources.IncrementalProjectBuilder; |
22 |
import org.eclipse.core.resources.ResourcesPlugin; |
23 |
import org.eclipse.core.runtime.CoreException; |
24 |
import org.eclipse.core.runtime.IAdaptable; |
25 |
import org.eclipse.core.runtime.IProgressMonitor; |
26 |
import org.eclipse.core.runtime.IStatus; |
27 |
import org.eclipse.core.runtime.Status; |
28 |
import org.eclipse.core.runtime.jobs.Job; |
29 |
import org.eclipse.jface.action.IAction; |
14 |
import org.eclipse.jface.action.IAction; |
30 |
import org.eclipse.jface.dialogs.IDialogConstants; |
|
|
31 |
import org.eclipse.jface.dialogs.IInputValidator; |
32 |
import org.eclipse.jface.dialogs.InputDialog; |
33 |
import org.eclipse.jface.dialogs.TrayDialog; |
34 |
import org.eclipse.jface.util.IPropertyChangeListener; |
15 |
import org.eclipse.jface.util.IPropertyChangeListener; |
35 |
import org.eclipse.jface.util.PropertyChangeEvent; |
16 |
import org.eclipse.jface.util.PropertyChangeEvent; |
36 |
import org.eclipse.jface.viewers.ISelection; |
17 |
import org.eclipse.jface.viewers.ISelection; |
37 |
import org.eclipse.jface.window.Window; |
|
|
38 |
import org.eclipse.swt.SWT; |
39 |
import org.eclipse.swt.accessibility.AccessibleAdapter; |
40 |
import org.eclipse.swt.accessibility.AccessibleEvent; |
41 |
import org.eclipse.swt.custom.SashForm; |
42 |
import org.eclipse.swt.events.SelectionAdapter; |
43 |
import org.eclipse.swt.events.SelectionEvent; |
44 |
import org.eclipse.swt.events.SelectionListener; |
45 |
import org.eclipse.swt.events.TreeEvent; |
46 |
import org.eclipse.swt.events.TreeListener; |
47 |
import org.eclipse.swt.graphics.Image; |
48 |
import org.eclipse.swt.layout.GridData; |
49 |
import org.eclipse.swt.layout.GridLayout; |
50 |
import org.eclipse.swt.widgets.Button; |
51 |
import org.eclipse.swt.widgets.Composite; |
52 |
import org.eclipse.swt.widgets.Control; |
53 |
import org.eclipse.swt.widgets.Label; |
54 |
import org.eclipse.swt.widgets.List; |
55 |
import org.eclipse.swt.widgets.MessageBox; |
56 |
import org.eclipse.swt.widgets.Shell; |
57 |
import org.eclipse.swt.widgets.Tree; |
58 |
import org.eclipse.swt.widgets.TreeItem; |
59 |
import org.eclipse.ui.IWorkbenchWindow; |
18 |
import org.eclipse.ui.IWorkbenchWindow; |
60 |
import org.eclipse.ui.IWorkbenchWindowActionDelegate; |
19 |
import org.eclipse.ui.IWorkbenchWindowActionDelegate; |
61 |
import org.eclipse.ui.IWorkingSet; |
20 |
import org.eclipse.ui.IWorkingSet; |
62 |
import org.eclipse.ui.IWorkingSetManager; |
21 |
import org.eclipse.ui.IWorkingSetManager; |
63 |
import org.eclipse.ui.PlatformUI; |
|
|
64 |
|
22 |
|
65 |
import org.eclipse.cdt.core.model.CoreModel; |
|
|
66 |
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; |
67 |
import org.eclipse.cdt.core.settings.model.ICProjectDescription; |
68 |
import org.eclipse.cdt.ui.CUIPlugin; |
23 |
import org.eclipse.cdt.ui.CUIPlugin; |
69 |
import org.eclipse.cdt.ui.newui.CDTHelpContextIds; |
|
|
70 |
import org.eclipse.cdt.ui.newui.CDTPrefUtil; |
71 |
import org.eclipse.cdt.ui.newui.UIMessages; |
72 |
|
24 |
|
73 |
import org.eclipse.cdt.internal.ui.CPluginImages; |
25 |
import org.eclipse.cdt.internal.ui.workingsets.WorkingSetConfigurationDialog; |
74 |
|
26 |
|
75 |
/** |
27 |
/** |
76 |
*/ |
28 |
*/ |
77 |
public class WorkingSetConfigAction implements IWorkbenchWindowActionDelegate, IPropertyChangeListener { |
29 |
public class WorkingSetConfigAction implements IWorkbenchWindowActionDelegate, IPropertyChangeListener { |
78 |
private static final String DELIMITER = " "; //$NON-NLS-1$ |
|
|
79 |
private static final String EMPTY_STR = ""; //$NON-NLS-1$ |
80 |
private static final String CURRENT = UIMessages.getString("WorkingSetConfigAction.10"); //$NON-NLS-1$ |
81 |
public static final Image IMG_PROJ = CPluginImages.get(CPluginImages.IMG_OBJS_CFOLDER); |
82 |
public static final Image IMG_CONF = CPluginImages.get(CPluginImages.IMG_OBJS_CONFIG); |
83 |
private static final Shell sh = CUIPlugin.getDefault().getShell(); |
84 |
private static final IWorkingSetManager wsm = CUIPlugin.getDefault().getWorkbench().getWorkingSetManager(); |
30 |
private static final IWorkingSetManager wsm = CUIPlugin.getDefault().getWorkbench().getWorkingSetManager(); |
85 |
private LinkedHashMap<String, IWorkingSet> workingSetsMap; |
|
|
86 |
private LinkedHashMap<String, ConfigSet> configSetMap; |
87 |
private boolean enabled = true; |
31 |
private boolean enabled = true; |
88 |
|
32 |
|
|
|
33 |
private IWorkbenchWindow window; |
34 |
|
89 |
public void run(IAction action) { |
35 |
public void run(IAction action) { |
90 |
LocalDialog dlg = new LocalDialog(sh); |
36 |
new WorkingSetConfigurationDialog(window.getShell()).open(); |
91 |
dlg.open(); |
|
|
92 |
} |
37 |
} |
93 |
|
38 |
|
94 |
public void selectionChanged(IAction action, ISelection selection) { |
39 |
public void selectionChanged(IAction action, ISelection selection) { |
Lines 101-106
Link Here
|
101 |
|
46 |
|
102 |
} |
47 |
} |
103 |
public void init(IWorkbenchWindow window) { |
48 |
public void init(IWorkbenchWindow window) { |
|
|
49 |
this.window = window; |
104 |
wsm.addPropertyChangeListener(this); |
50 |
wsm.addPropertyChangeListener(this); |
105 |
checkWS(); |
51 |
checkWS(); |
106 |
} |
52 |
} |
Lines 112-627
Link Here
|
112 |
enabled = w.length > 0; |
58 |
enabled = w.length > 0; |
113 |
return w; |
59 |
return w; |
114 |
} |
60 |
} |
115 |
|
|
|
116 |
private String[] getWSnames() { |
117 |
IWorkingSet[] w = checkWS(); |
118 |
workingSetsMap = new LinkedHashMap<String, IWorkingSet>(w.length); |
119 |
for (IWorkingSet ws : w) |
120 |
workingSetsMap.put(ws.getLabel(), ws); |
121 |
return workingSetsMap.keySet().toArray(new String[w.length]); |
122 |
} |
123 |
|
61 |
|
124 |
public void propertyChange(PropertyChangeEvent event) { |
62 |
public void propertyChange(PropertyChangeEvent event) { |
125 |
checkWS(); |
63 |
checkWS(); |
126 |
} |
64 |
} |
127 |
|
|
|
128 |
private class LocalDialog extends TrayDialog { |
129 |
private List wsets; |
130 |
private List csets; |
131 |
private Tree tree; |
132 |
private Button b1, b2, b3, b4, bb; |
133 |
|
134 |
LocalDialog(Shell parentShell) { |
135 |
super(parentShell); |
136 |
setHelpAvailable(false); |
137 |
setShellStyle(getShellStyle()|SWT.RESIZE); |
138 |
} |
139 |
@Override |
140 |
protected void buttonPressed(int buttonId) { |
141 |
if (buttonId == IDialogConstants.OK_ID) { |
142 |
saveConfigSets(); |
143 |
saveActiveConfigs(); |
144 |
} else {} |
145 |
super.buttonPressed(buttonId); |
146 |
} |
147 |
|
148 |
private void saveConfigSets() { |
149 |
ArrayList<String> out = new ArrayList<String>(configSetMap.size()); |
150 |
for (ConfigSet cs : configSetMap.values()) |
151 |
if (cs.isValid() && !cs.name.equals(CURRENT)) |
152 |
out.add(cs.toString()); |
153 |
CDTPrefUtil.saveConfigSets(out); |
154 |
} |
155 |
|
156 |
private void saveActiveConfigs() { |
157 |
for (TreeItem ti : tree.getItems()) { |
158 |
ICProjectDescription pd = (ICProjectDescription)ti.getData(); |
159 |
for (TreeItem ti1: ti.getItems()) { |
160 |
if (!ti1.getChecked()) |
161 |
continue; |
162 |
((ICConfigurationDescription)ti1.getData()).setActive(); |
163 |
break; |
164 |
} |
165 |
try { |
166 |
CoreModel.getDefault().setProjectDescription(pd.getProject(), pd); |
167 |
} catch (CoreException e) { |
168 |
e.printStackTrace(); |
169 |
CUIPlugin.log(e); |
170 |
} |
171 |
} |
172 |
} |
173 |
|
174 |
@Override |
175 |
protected void configureShell(Shell shell) { |
176 |
super.configureShell(shell); |
177 |
shell.setText(UIMessages.getString("WorkingSetConfigAction.1")); //$NON-NLS-1$ |
178 |
} |
179 |
|
180 |
@Override |
181 |
protected Control createDialogArea(Composite parent) { |
182 |
PlatformUI.getWorkbench().getHelpSystem().setHelp( getShell(), CDTHelpContextIds.MAN_PROJ_BUILD_PROP); |
183 |
|
184 |
Composite comp = new Composite(parent, SWT.NULL); |
185 |
comp.setFont(parent.getFont()); |
186 |
comp.setLayout(new GridLayout(2, false)); |
187 |
comp.setLayoutData(new GridData(GridData.FILL_BOTH)); |
188 |
|
189 |
// Create the sash form |
190 |
SashForm sashForm = new SashForm(comp, SWT.NONE); |
191 |
sashForm.setOrientation(SWT.VERTICAL); |
192 |
GridData gd = new GridData(GridData.FILL_VERTICAL); |
193 |
gd.verticalSpan = 3; |
194 |
sashForm.setLayoutData(gd); |
195 |
|
196 |
Composite ws = new Composite(sashForm, SWT.NULL); |
197 |
ws.setLayoutData(new GridData(GridData.FILL_BOTH)); |
198 |
ws.setLayout(new GridLayout(1, false)); |
199 |
Label l1 = new Label(ws, SWT.NONE); |
200 |
l1.setText(UIMessages.getString("WorkingSetConfigAction.2")); //$NON-NLS-1$ |
201 |
l1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
202 |
wsets = new List(ws, SWT.SINGLE | SWT.BORDER); |
203 |
wsets.setLayoutData(new GridData(GridData.FILL_BOTH)); |
204 |
wsets.setItems(getWSnames()); |
205 |
|
206 |
wsets.addSelectionListener(new SelectionListener() { |
207 |
public void widgetDefaultSelected(SelectionEvent e) { |
208 |
workingSetChanged(); |
209 |
} |
210 |
public void widgetSelected(SelectionEvent e) { |
211 |
workingSetChanged(); |
212 |
}}); |
213 |
|
214 |
if (wsets.getItemCount() == 0) { |
215 |
wsets.add(UIMessages.getString("WorkingSetConfigAction.3")); //$NON-NLS-1$ |
216 |
wsets.setEnabled(false); |
217 |
} else { |
218 |
IWorkingSet[] w = wsm.getRecentWorkingSets(); |
219 |
if (w == null || w.length == 0) |
220 |
wsets.setSelection(0); |
221 |
else { |
222 |
String s = w[0].getLabel(); |
223 |
String[] ss = wsets.getItems(); |
224 |
for (int i=0; i<ss.length; i++) { |
225 |
if (ss[i].equals(s)) { |
226 |
wsets.setSelection(i); |
227 |
break; |
228 |
} |
229 |
} |
230 |
} |
231 |
} |
232 |
|
233 |
Composite cs = new Composite(sashForm, SWT.NULL); |
234 |
cs.setLayoutData(new GridData(GridData.FILL_BOTH)); |
235 |
cs.setLayout(new GridLayout(1, false)); |
236 |
l1 = new Label(cs, SWT.NONE); |
237 |
l1.setText(UIMessages.getString("WorkingSetConfigAction.4")); //$NON-NLS-1$ |
238 |
l1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
239 |
csets = new List(cs, SWT.SINGLE | SWT.BORDER); |
240 |
csets.setLayoutData(new GridData(GridData.FILL_BOTH)); |
241 |
csets.addSelectionListener(new SelectionListener() { |
242 |
public void widgetDefaultSelected(SelectionEvent e) { |
243 |
configSetChanged(); |
244 |
} |
245 |
public void widgetSelected(SelectionEvent e) { |
246 |
configSetChanged(); |
247 |
}}); |
248 |
|
249 |
sashForm.setWeights(new int[]{50, 50}); |
250 |
|
251 |
|
252 |
l1 = new Label(comp, SWT.NONE); |
253 |
l1.setText(UIMessages.getString("WorkingSetConfigAction.5")); //$NON-NLS-1$ |
254 |
gd = new GridData(GridData.FILL_HORIZONTAL); |
255 |
gd.verticalIndent = 5; |
256 |
l1.setLayoutData(gd); |
257 |
|
258 |
tree = new Tree(comp, SWT.SINGLE | SWT.CHECK | SWT.BORDER); |
259 |
gd = new GridData(GridData.FILL_BOTH); |
260 |
gd.heightHint = 200; |
261 |
gd.widthHint = 200; |
262 |
tree.setLayoutData(gd); |
263 |
tree.getAccessible().addAccessibleListener( |
264 |
new AccessibleAdapter() { |
265 |
@Override |
266 |
public void getName(AccessibleEvent e) { |
267 |
e.result = UIMessages.getString("WorkingSetConfigAction.17"); //$NON-NLS-1$ |
268 |
} |
269 |
} |
270 |
); |
271 |
tree.addSelectionListener(new SelectionAdapter() { |
272 |
@Override |
273 |
public void widgetSelected(SelectionEvent e) { |
274 |
if (((e.detail & SWT.CHECK) == SWT.CHECK) && |
275 |
(e.item != null && (e.item instanceof TreeItem))) { |
276 |
TreeItem sel = (TreeItem)e.item; |
277 |
if (sel.getData() instanceof ICProjectDescription) { |
278 |
sel.setChecked(false); // do not check projects ! |
279 |
} else { |
280 |
// If current item is checked, uncheck remaining ones. |
281 |
// If current item is unchecked, check the 1st instead. |
282 |
String txt = sel.getChecked() ? sel.getText() : EMPTY_STR; |
283 |
for (TreeItem obj : sel.getParentItem().getItems()) { |
284 |
if (txt == null) |
285 |
obj.setChecked(false); |
286 |
else if (txt == EMPTY_STR || txt.equals(obj.getText())) { |
287 |
obj.setChecked(true); |
288 |
txt = null; // do not perform further checks. |
289 |
} else |
290 |
obj.setChecked(false); |
291 |
} |
292 |
} |
293 |
} |
294 |
} |
295 |
}); |
296 |
|
297 |
tree.addTreeListener(new TreeListener() { |
298 |
public void treeCollapsed(TreeEvent e) { |
299 |
} |
300 |
public void treeExpanded(TreeEvent e) { |
301 |
}}); |
302 |
|
303 |
// Buttons pane |
304 |
Composite c = new Composite(comp, SWT.NONE); |
305 |
c.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); |
306 |
c.setLayout(new GridLayout(2, true)); |
307 |
|
308 |
b2 = new Button(c, SWT.PUSH); |
309 |
b2.setText(UIMessages.getString("WorkingSetConfigAction.7")); //$NON-NLS-1$ |
310 |
b2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); |
311 |
b2.addSelectionListener(new SelectionAdapter() { |
312 |
@Override |
313 |
public void widgetSelected(SelectionEvent e) { |
314 |
String newS = getString(UIMessages.getString("WorkingSetConfigAction.18"), null); //$NON-NLS-1$ |
315 |
if (newS == null) |
316 |
return; |
317 |
String key = wsets.getSelection()[0] + DELIMITER + newS; |
318 |
if (configSetMap.containsKey(key)) |
319 |
// error message |
320 |
return; |
321 |
ConfigSet cs = new ConfigSet(newS, wsets.getSelection()[0], tree); |
322 |
configSetMap.put(key, cs); |
323 |
csets.add(newS); |
324 |
csets.setSelection(csets.getItemCount() - 1); |
325 |
updateButtons(); |
326 |
}}); |
327 |
|
328 |
b1 = new Button(c, SWT.PUSH); |
329 |
b1.setText(UIMessages.getString("WorkingSetConfigAction.6")); //$NON-NLS-1$ |
330 |
b1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); |
331 |
b1.addSelectionListener(new SelectionAdapter() { |
332 |
@Override |
333 |
public void widgetSelected(SelectionEvent e) { |
334 |
String oldS = csets.getItem(csets.getSelectionIndex()); |
335 |
ConfigSet cs = new ConfigSet(oldS, wsets.getSelection()[0], tree); |
336 |
configSetMap.put(wsets.getSelection()[0] + DELIMITER + oldS, cs); // overwrite |
337 |
}}); |
338 |
|
339 |
b3 = new Button(c, SWT.PUSH); |
340 |
b3.setText(UIMessages.getString("WorkingSetConfigAction.8")); //$NON-NLS-1$ |
341 |
b3.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); |
342 |
b3.addSelectionListener(new SelectionAdapter() { |
343 |
@Override |
344 |
public void widgetSelected(SelectionEvent e) { |
345 |
int n = csets.getSelectionIndex(); |
346 |
if (n > 0) { |
347 |
String oldS = csets.getItem(n); |
348 |
String newS = getString(UIMessages.getString("WorkingSetConfigAction.19"), oldS); //$NON-NLS-1$ |
349 |
if (newS == null) |
350 |
return; |
351 |
if (oldS.equals(newS)) // nothing to do |
352 |
return; |
353 |
String key = wsets.getSelection()[0] + DELIMITER + newS; |
354 |
if (configSetMap.containsKey(key)) { |
355 |
ExistsMessage(newS); |
356 |
return; |
357 |
} |
358 |
ConfigSet cs = configSetMap.get(wsets.getSelection()[0] + DELIMITER + oldS); |
359 |
configSetMap.remove(cs); |
360 |
cs.name = newS; |
361 |
configSetMap.put(key, cs); |
362 |
csets.setItem(n, newS); |
363 |
} |
364 |
}}); |
365 |
|
366 |
b4 = new Button(c, SWT.PUSH); |
367 |
b4.setText(UIMessages.getString("WorkingSetConfigAction.9")); //$NON-NLS-1$ |
368 |
b4.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); |
369 |
b4.addSelectionListener(new SelectionAdapter() { |
370 |
@Override |
371 |
public void widgetSelected(SelectionEvent e) { |
372 |
String[] ss = csets.getSelection(); |
373 |
if (ss != null && ss.length > 0) { |
374 |
configSetMap.remove(wsets.getSelection()[0] + DELIMITER + ss[0]); |
375 |
csets.remove(ss[0]); |
376 |
csets.setSelection(0); |
377 |
updateButtons(); |
378 |
} |
379 |
}}); |
380 |
|
381 |
bb = new Button(c, SWT.PUSH); |
382 |
bb.setText(UIMessages.getString("WorkingSetConfigAction.20")); //$NON-NLS-1$ |
383 |
gd = new GridData(GridData.FILL_HORIZONTAL); |
384 |
gd.horizontalSpan = 2; |
385 |
bb.setLayoutData(gd); |
386 |
bb.addSelectionListener(new SelectionAdapter() { |
387 |
@Override |
388 |
public void widgetSelected(SelectionEvent e) { |
389 |
build(); |
390 |
LocalDialog.this.close(); |
391 |
}}); |
392 |
|
393 |
initData(); |
394 |
return comp; |
395 |
} |
396 |
|
397 |
private void initData() { |
398 |
configSetMap = new LinkedHashMap<String, ConfigSet>(); |
399 |
for (String s : CDTPrefUtil.readConfigSets()) { |
400 |
ConfigSet cs = new ConfigSet(s); |
401 |
if (cs.isValid()) |
402 |
configSetMap.put(cs.workingSetLabel + DELIMITER + cs.name, cs); |
403 |
} |
404 |
workingSetChanged(); |
405 |
} |
406 |
|
407 |
private void updateButtons() { |
408 |
Button ok = this.getButton(IDialogConstants.OK_ID); |
409 |
boolean en = csets.getSelectionIndex() > 0; |
410 |
if (! wsets.getEnabled()) { |
411 |
b2.setEnabled(false); // new |
412 |
if (ok != null) |
413 |
ok.setEnabled(false); // OK |
414 |
en = false; |
415 |
} |
416 |
b1.setEnabled(en); // update |
417 |
b3.setEnabled(en); // rename |
418 |
b4.setEnabled(en); // delete |
419 |
bb.setEnabled(wsets.getEnabled()); |
420 |
} |
421 |
private void workingSetChanged() { |
422 |
// tree.setRedraw(false); |
423 |
tree.removeAll(); |
424 |
String[] ss = wsets.getSelection(); |
425 |
if (ss == null || ss.length == 0) |
426 |
return; |
427 |
IWorkingSet ws = workingSetsMap.get(ss[0]); |
428 |
fillTree(ws); |
429 |
tree.setRedraw(true); |
430 |
// csets.setRedraw(false); |
431 |
csets.removeAll(); |
432 |
csets.add(CURRENT); |
433 |
csets.setSelection(0); |
434 |
|
435 |
configSetMap.remove(CURRENT); // previous default object, if any |
436 |
for (Map.Entry<String, ConfigSet> me : configSetMap.entrySet()) { |
437 |
if (me.getValue().workingSetLabel.equals(ws.getLabel())) |
438 |
csets.add(me.getValue().name); |
439 |
} |
440 |
configSetMap.put(CURRENT, new ConfigSet(CURRENT, ws.getLabel(), tree)); |
441 |
csets.setRedraw(true); |
442 |
updateButtons(); |
443 |
|
444 |
// calls from FillTree does not work... |
445 |
for (TreeItem ti : tree.getItems()) |
446 |
ti.setExpanded(true); |
447 |
} |
448 |
|
449 |
/** |
450 |
* Update projects tree for selected working set. |
451 |
* @param ws - working set selected. |
452 |
*/ |
453 |
private void fillTree(IWorkingSet ws) { |
454 |
if (ws == null) |
455 |
return; |
456 |
for (IAdaptable ad : ws.getElements()) { |
457 |
IProject p = (IProject)ad.getAdapter(IProject.class); |
458 |
if (p == null) |
459 |
continue; |
460 |
ICProjectDescription prjd = CoreModel.getDefault().getProjectDescription(p, true); |
461 |
if (prjd == null) |
462 |
continue; |
463 |
ICConfigurationDescription[] cfgs = prjd.getConfigurations(); |
464 |
if (cfgs == null || cfgs.length == 0) |
465 |
continue; |
466 |
TreeItem ti = new TreeItem(tree, SWT.NONE); |
467 |
ti.setText(prjd.getName()); |
468 |
ti.setImage(IMG_PROJ); |
469 |
ti.setData(prjd); |
470 |
for (ICConfigurationDescription c : cfgs) { |
471 |
TreeItem ti1 = new TreeItem(ti, SWT.NONE); |
472 |
ti1.setText(c.getName()); |
473 |
ti1.setImage(IMG_CONF); |
474 |
ti1.setChecked(c.isActive()); |
475 |
ti1.setData(c); |
476 |
} |
477 |
} |
478 |
} |
479 |
|
480 |
private void configSetChanged() { |
481 |
int i = csets.getSelectionIndex(); |
482 |
if (i >= 0) { |
483 |
String key = (i == 0) ? CURRENT : wsets.getSelection()[0] + DELIMITER + csets.getItem(i); |
484 |
ConfigSet cs = configSetMap.get(key); |
485 |
if (cs != null && cs.isValid()) { |
486 |
for (TreeItem ti : tree.getItems()) { |
487 |
ICProjectDescription prjd = (ICProjectDescription)ti.getData(); |
488 |
String cid = cs.data.get(prjd.getName()); |
489 |
if (cid == null) |
490 |
continue; // the project not in the list |
491 |
for (TreeItem ti1 : ti.getItems()) { |
492 |
ICConfigurationDescription cfg = (ICConfigurationDescription)ti1.getData(); |
493 |
ti1.setChecked(cid.equals(cfg.getId())); |
494 |
} |
495 |
} |
496 |
} |
497 |
} |
498 |
updateButtons(); |
499 |
} |
500 |
|
501 |
private String getString(String title, String value) { |
502 |
InputDialog d = new InputDialog(sh, title, |
503 |
UIMessages.getString("WorkingSetConfigAction.11"), //$NON-NLS-1$ |
504 |
value, new IInputValidator() { |
505 |
public String isValid(String newText) { |
506 |
if (newText.indexOf(CDTPrefUtil.CONFSETDEL) >= 0) |
507 |
return UIMessages.getString("WorkingSetConfigAction.0") + CDTPrefUtil.CONFSETDEL + UIMessages.getString("WorkingSetConfigAction.14"); //$NON-NLS-1$ //$NON-NLS-2$ |
508 |
if (configSetMap.containsKey(wsets.getSelection()[0] + DELIMITER + newText)) |
509 |
return UIMessages.getString("WorkingSetConfigAction.15") + newText + UIMessages.getString("WorkingSetConfigAction.16"); //$NON-NLS-1$ //$NON-NLS-2$ |
510 |
return null; |
511 |
}}); |
512 |
if (d.open() == Window.OK) |
513 |
return d.getValue().replace(' ', '_'); // space is delimiter. |
514 |
return null; |
515 |
} |
516 |
|
517 |
private void ExistsMessage(String s) { |
518 |
MessageBox box = new MessageBox(sh, SWT.ICON_ERROR); |
519 |
box.setMessage(UIMessages.getString("WorkingSetConfigAction.12") + s); //$NON-NLS-1$ |
520 |
box.open(); |
521 |
} |
522 |
|
523 |
private void build() { |
524 |
saveConfigSets(); |
525 |
saveActiveConfigs(); |
526 |
IProject[] ps = new IProject[tree.getItemCount()]; |
527 |
int cnt = 0; |
528 |
for (TreeItem ti : tree.getItems()) |
529 |
ps[cnt++] = ((ICProjectDescription)ti.getData()).getProject(); |
530 |
Job buildJob = new BuildJob(ps); |
531 |
buildJob.schedule(); |
532 |
} |
533 |
} |
534 |
|
535 |
private static final class BuildJob extends Job { |
536 |
IProject[] ps; |
537 |
|
538 |
BuildJob(IProject[] _ps) { |
539 |
super(UIMessages.getString("WorkingSetConfigAction.21")); //$NON-NLS-1$ |
540 |
ps = _ps; |
541 |
} |
542 |
|
543 |
/* (non-Javadoc) |
544 |
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) |
545 |
*/ |
546 |
@Override |
547 |
protected IStatus run(IProgressMonitor monitor) { |
548 |
for (IProject p:ps) |
549 |
try { |
550 |
setName(UIMessages.getString("WorkingSetConfigAction.21") + p.getName()); //$NON-NLS-1$ |
551 |
p.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor); |
552 |
} catch (CoreException e) { |
553 |
return new Status(IStatus.ERROR, UIMessages.getString("WorkingSetConfigAction.22"), e.getLocalizedMessage()); //$NON-NLS-1$ |
554 |
} |
555 |
if (monitor.isCanceled()) { |
556 |
return Status.CANCEL_STATUS; |
557 |
} |
558 |
monitor.done(); |
559 |
return Status.OK_STATUS; |
560 |
} |
561 |
|
562 |
@Override |
563 |
public boolean belongsTo(Object family) { |
564 |
return ResourcesPlugin.FAMILY_MANUAL_BUILD == family; |
565 |
} |
566 |
|
567 |
} |
568 |
|
569 |
private static class ConfigSet { |
570 |
String name; |
571 |
String workingSetLabel; |
572 |
LinkedHashMap<String, String> data; |
573 |
|
574 |
private ConfigSet(String s) { |
575 |
data = new LinkedHashMap<String, String>(); |
576 |
String[] ss = s.split(DELIMITER); |
577 |
if (ss == null || ss.length < 4 || ss.length %2 == 1) { |
578 |
CUIPlugin.getDefault().logErrorMessage(UIMessages.getString("WorkingSetConfigAction.13") + s); //$NON-NLS-1$ |
579 |
return; // not valid |
580 |
} |
581 |
name = ss[0]; |
582 |
workingSetLabel = ss[1]; |
583 |
int n = (ss.length - 2) / 2; |
584 |
for (int i=0; i<n; i++) |
585 |
data.put(ss[2 + i * 2], ss[3 + i * 2]); |
586 |
} |
587 |
|
588 |
private ConfigSet(String n, String w, Tree t) { |
589 |
data = new LinkedHashMap<String, String>(); |
590 |
name = n; |
591 |
workingSetLabel = w; |
592 |
for (TreeItem ti : t.getItems()) { |
593 |
ICProjectDescription prjd = (ICProjectDescription)ti.getData(); |
594 |
for (TreeItem ti1 : ti.getItems()) { |
595 |
if (ti1.getChecked()) { |
596 |
ICConfigurationDescription cfg = (ICConfigurationDescription)ti1.getData(); |
597 |
data.put(prjd.getName(), cfg.getId()); |
598 |
break; |
599 |
} |
600 |
} |
601 |
} |
602 |
|
603 |
} |
604 |
|
605 |
private boolean isValid() { |
606 |
return data.size() > 0; |
607 |
} |
608 |
|
609 |
@Override |
610 |
public String toString() { |
611 |
if (!isValid()) |
612 |
return EMPTY_STR; |
613 |
StringBuilder b = new StringBuilder(); |
614 |
b.append(name); |
615 |
b.append(DELIMITER); |
616 |
b.append(workingSetLabel); |
617 |
b.append(DELIMITER); |
618 |
for (Map.Entry<String, String> me : data.entrySet()) { |
619 |
b.append(me.getKey()); |
620 |
b.append(DELIMITER); |
621 |
b.append(me.getValue()); |
622 |
b.append(DELIMITER); |
623 |
} |
624 |
return b.toString().trim(); |
625 |
} |
626 |
} |
627 |
} |
65 |
} |