|
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 |
|
17 |
|
18 package com.symbian.smt.gui.smtwidgets; |
|
19 |
|
20 import java.util.ArrayList; |
|
21 import java.util.Iterator; |
|
22 |
|
23 import org.eclipse.jface.viewers.ILabelProvider; |
|
24 import org.eclipse.jface.viewers.ILabelProviderListener; |
|
25 import org.eclipse.jface.viewers.IStructuredContentProvider; |
|
26 import org.eclipse.jface.viewers.IStructuredSelection; |
|
27 import org.eclipse.jface.viewers.ListViewer; |
|
28 import org.eclipse.jface.viewers.StructuredSelection; |
|
29 import org.eclipse.jface.viewers.Viewer; |
|
30 import org.eclipse.jface.window.Window; |
|
31 import org.eclipse.swt.SWT; |
|
32 import org.eclipse.swt.events.SelectionAdapter; |
|
33 import org.eclipse.swt.events.SelectionEvent; |
|
34 import org.eclipse.swt.graphics.Image; |
|
35 import org.eclipse.swt.layout.FillLayout; |
|
36 import org.eclipse.swt.layout.GridData; |
|
37 import org.eclipse.swt.layout.GridLayout; |
|
38 import org.eclipse.swt.layout.RowData; |
|
39 import org.eclipse.swt.layout.RowLayout; |
|
40 import org.eclipse.swt.widgets.Button; |
|
41 import org.eclipse.swt.widgets.Composite; |
|
42 import org.eclipse.swt.widgets.Label; |
|
43 import org.eclipse.swt.widgets.List; |
|
44 import org.eclipse.ui.actions.SelectionProviderAction; |
|
45 |
|
46 import com.symbian.smt.gui.Helper; |
|
47 |
|
48 /** |
|
49 * This widget contains all the functionality to handle assignment of generic |
|
50 * command line parameters. |
|
51 * <p> |
|
52 * It allows to add, remove and edit command line options, as well as changing |
|
53 * their order. |
|
54 * </p> |
|
55 * NB: This class is in need of refactoring using the common classes that are |
|
56 * also being utilised in the ResourcesWidget class. |
|
57 * |
|
58 * @author barbararosi-schwartz |
|
59 */ |
|
60 public class AdvancedOptionsWidget extends Composite { |
|
61 |
|
62 /** |
|
63 * This is the parent of all actions that act on the command line options |
|
64 * from the list of assigned options. |
|
65 * <p> |
|
66 * It caches the Button that is the presentation proxy for the action and |
|
67 * manages the enabled state of the Button to be consistent with its own |
|
68 * enablement state. |
|
69 * </p> |
|
70 * |
|
71 * @author barbararosi-schwartz |
|
72 * |
|
73 */ |
|
74 private abstract class AbstractOptionAction extends SelectionProviderAction { |
|
75 protected Button actionProxy; |
|
76 |
|
77 /** |
|
78 * The constructor sets the text on the Button that is the visual proxy |
|
79 * of this action and caches the button for later usage. |
|
80 * |
|
81 * @param text |
|
82 * the text that represents both the name of the action and |
|
83 * the label on the corresponding Button |
|
84 * @param button |
|
85 * the Button that acts as the visual proxy of this action. |
|
86 */ |
|
87 private AbstractOptionAction(String text, Button button) { |
|
88 super(viewer, text); |
|
89 |
|
90 this.actionProxy = button; |
|
91 actionProxy.setText(text); |
|
92 } |
|
93 |
|
94 /** |
|
95 * The default implementation of this method does nothing. |
|
96 */ |
|
97 @Override |
|
98 public void dispose() { |
|
99 super.dispose(); |
|
100 } |
|
101 |
|
102 /** |
|
103 * The default implementation of this method does nothing. |
|
104 */ |
|
105 @Override |
|
106 public void run() { |
|
107 super.run(); |
|
108 }; |
|
109 |
|
110 /** |
|
111 * The default implementation of this method does nothing. |
|
112 */ |
|
113 @Override |
|
114 public void selectionChanged(IStructuredSelection selection) { |
|
115 super.selectionChanged(selection); |
|
116 } |
|
117 |
|
118 /** |
|
119 * Sets the enablement state of the proxy Button to be the same as the |
|
120 * enablement state of the action, the latter being managed by a call to |
|
121 * super.setEnabled(). |
|
122 */ |
|
123 @Override |
|
124 public final void setEnabled(boolean enabled) { |
|
125 actionProxy.setEnabled(enabled); |
|
126 super.setEnabled(enabled); |
|
127 } |
|
128 } |
|
129 |
|
130 /** |
|
131 * This is the action that adds a new command line option to the list of |
|
132 * assigned options. |
|
133 * |
|
134 * @author barbararosi-schwartz |
|
135 * |
|
136 */ |
|
137 private class AddOptionAction extends AbstractOptionAction { |
|
138 |
|
139 /** |
|
140 * The option that has been entered by the user or null if the user |
|
141 * cancelled the operation. |
|
142 */ |
|
143 private String newOption = null; |
|
144 |
|
145 private AddOptionAction(Button button) { |
|
146 super("Add...", button); |
|
147 setEnabled(true); |
|
148 } |
|
149 |
|
150 /** |
|
151 * Returns the option that was entered by the user. |
|
152 * |
|
153 * @return the option that was entered by the user (or null if the user |
|
154 * cancelled the operation) |
|
155 */ |
|
156 String getNewOption() { |
|
157 return newOption; |
|
158 } |
|
159 |
|
160 /** |
|
161 * Creates and displays an InputDialogWithWarning that collects the new |
|
162 * option entered by the user. The dialog is equipped with a |
|
163 * DialogInputValidator object that automatically performs validation on |
|
164 * the user's input. |
|
165 * <p> |
|
166 * When the dialog is dismissed, the action changes the model to reflect |
|
167 * the new addition. |
|
168 * </p> |
|
169 */ |
|
170 @Override |
|
171 public void run() { |
|
172 InputDialogWithWarning dialog = new InputDialogWithWarning(viewer |
|
173 .getControl().getShell(), "Add Option", |
|
174 "Please enter the required command-line option", "", |
|
175 new DialogInputValidator()); |
|
176 |
|
177 int result = dialog.open(); |
|
178 |
|
179 if (result == Window.CANCEL) { |
|
180 newOption = null; |
|
181 return; |
|
182 } else { |
|
183 newOption = dialog.getValue().trim(); |
|
184 |
|
185 java.util.List<String> model = Helper |
|
186 .toListOfStrings((String[]) viewer.getInput()); |
|
187 model.add(newOption); |
|
188 setAdvancedOptions(Helper.toArrayOfStrings(model)); |
|
189 } |
|
190 } |
|
191 |
|
192 /** |
|
193 * This action is always enabled. |
|
194 */ |
|
195 @Override |
|
196 public void selectionChanged(IStructuredSelection selection) { |
|
197 } |
|
198 } |
|
199 |
|
200 /** |
|
201 * This is the content provider for the list of assigned command line |
|
202 * options. |
|
203 * |
|
204 * @author barbararosi-schwartz |
|
205 */ |
|
206 private class AdvancedOptionsContentProvider implements |
|
207 IStructuredContentProvider { |
|
208 |
|
209 public void dispose() { |
|
210 } |
|
211 |
|
212 /* (non-Javadoc) |
|
213 * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) |
|
214 */ |
|
215 public Object[] getElements(Object inputElement) { |
|
216 if (! (inputElement instanceof String[])) { |
|
217 throw new IllegalArgumentException("Argument is not of type String[]."); |
|
218 } |
|
219 |
|
220 String[] items = (String[]) inputElement; |
|
221 |
|
222 return items; |
|
223 } |
|
224 |
|
225 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { |
|
226 } |
|
227 } |
|
228 |
|
229 /** |
|
230 * This is the label provider for the list of assigned command line options. |
|
231 * |
|
232 * @author barbararosi-schwartz |
|
233 */ |
|
234 private class AdvancedOptionsLabelProvider implements ILabelProvider { |
|
235 |
|
236 public void addListener(ILabelProviderListener listener) { |
|
237 } |
|
238 |
|
239 public void dispose() { |
|
240 } |
|
241 |
|
242 public Image getImage(Object element) { |
|
243 return null; |
|
244 } |
|
245 |
|
246 public String getText(Object element) { |
|
247 return element.toString(); |
|
248 } |
|
249 |
|
250 public boolean isLabelProperty(Object element, String property) { |
|
251 return false; |
|
252 } |
|
253 |
|
254 public void removeListener(ILabelProviderListener listener) { |
|
255 } |
|
256 |
|
257 } |
|
258 |
|
259 /** |
|
260 * This is the validator that is utilised by the InputDialogWithWarning |
|
261 * presented by the AddOptionAction. |
|
262 * |
|
263 * @author barbararosi-schwartz |
|
264 * |
|
265 */ |
|
266 private class DialogInputValidator implements IInputValidatorWithWarning { |
|
267 |
|
268 private java.util.List<String> listElements = new ArrayList<String>(); |
|
269 |
|
270 private DialogInputValidator() { |
|
271 listElements = Helper.toListOfStrings((String[]) viewer.getInput()); |
|
272 } |
|
273 |
|
274 /** |
|
275 * User input is invalid if: |
|
276 * <ol> |
|
277 * <li>input is not empty</li> |
|
278 * <li>input is already present in the list</li> |
|
279 * </ol> |
|
280 * |
|
281 * @see org.eclipse.jface.dialogs.IInputValidator#isValid(java.lang.String) |
|
282 */ |
|
283 public String isValid(String newText) { |
|
284 if (newText.trim().length() == 0) { |
|
285 return ""; |
|
286 } |
|
287 |
|
288 if (listElements.contains(newText.trim())) { |
|
289 return "Option [" + newText + "] is already in the list."; |
|
290 } |
|
291 |
|
292 return null; |
|
293 } |
|
294 |
|
295 /** |
|
296 * User input generates a warning if it is one of the options contained |
|
297 * in the dangerousOptions list. |
|
298 * |
|
299 * @see com.symbian.smt.gui.smtwidgets.IInputValidatorWithWarning#isWarning(java.lang.String) |
|
300 */ |
|
301 public String isWarning(String newText) { |
|
302 if (dangerousOptions.contains(newText)) { |
|
303 return "Warning: option [" + newText |
|
304 + "] may cause the model build process to fail."; |
|
305 } |
|
306 |
|
307 return null; |
|
308 } |
|
309 |
|
310 } |
|
311 |
|
312 /** |
|
313 * This is the action that edits a command line option that already exists |
|
314 * in the list of assigned options. |
|
315 * |
|
316 * @author barbararosi-schwartz |
|
317 */ |
|
318 private class EditOptionAction extends AbstractOptionAction { |
|
319 |
|
320 private EditOptionAction(Button button) { |
|
321 super("Edit...", button); |
|
322 setEnabled(false); |
|
323 } |
|
324 |
|
325 /** |
|
326 * Creates and displays an InputDialogWithWarning, initialised with the |
|
327 * currently selected option. The dialog is equipped with a |
|
328 * DialogInputValidator object that automatically performs validation on |
|
329 * the user's input. |
|
330 * <p> |
|
331 * When the dialog is dismissed, the action changes the model to reflect |
|
332 * the option modification. |
|
333 * </p> |
|
334 */ |
|
335 @Override |
|
336 public void run() { |
|
337 String initialValue = (String) ((StructuredSelection) getSelection()) |
|
338 .getFirstElement(); |
|
339 InputDialogWithWarning dialog = new InputDialogWithWarning(viewer |
|
340 .getControl().getShell(), "Add Option", |
|
341 "Please enter the required command-line option", |
|
342 initialValue, new DialogInputValidator()); |
|
343 |
|
344 int result = dialog.open(); |
|
345 String editedOption = null; |
|
346 |
|
347 if (result == Window.CANCEL) { |
|
348 return; |
|
349 } else { |
|
350 editedOption = dialog.getValue().trim(); |
|
351 |
|
352 java.util.List<String> model = Helper |
|
353 .toListOfStrings((String[]) viewer.getInput()); |
|
354 int index = model.indexOf(initialValue); |
|
355 model.set(index, editedOption); |
|
356 setAdvancedOptions(Helper.toArrayOfStrings(model)); |
|
357 } |
|
358 } |
|
359 |
|
360 /** |
|
361 * Enabled if we have exactly one selection in the list. |
|
362 */ |
|
363 @Override |
|
364 public void selectionChanged(IStructuredSelection selection) { |
|
365 if (selection.size() != 1) { |
|
366 setEnabled(false); |
|
367 return; |
|
368 } |
|
369 |
|
370 setEnabled(true); |
|
371 } |
|
372 } |
|
373 |
|
374 /** |
|
375 * This is the action that moves a command line option down by one position |
|
376 * in the list of assigned options. |
|
377 * |
|
378 * @author barbararosi-schwartz |
|
379 */ |
|
380 private class MoveOptionDownAction extends AbstractOptionAction { |
|
381 |
|
382 /** |
|
383 * The option that has been moved by the user |
|
384 */ |
|
385 private String movedOption = null; |
|
386 |
|
387 private MoveOptionDownAction(Button button) { |
|
388 super("Move Down", button); |
|
389 setEnabled(false); |
|
390 } |
|
391 |
|
392 /** |
|
393 * Returns the option that was moved by the user. |
|
394 * |
|
395 * @return the option that was moved by the user |
|
396 */ |
|
397 String getMovedOption() { |
|
398 return movedOption; |
|
399 } |
|
400 |
|
401 /** |
|
402 * Moves the selected option down by one position in the model. |
|
403 */ |
|
404 @Override |
|
405 public void run() { |
|
406 movedOption = (String) ((StructuredSelection) getSelection()) |
|
407 .getFirstElement(); |
|
408 java.util.List<String> model = Helper |
|
409 .toListOfStrings((String[]) viewer.getInput()); |
|
410 int oldIndex = model.indexOf(movedOption); |
|
411 model.remove(oldIndex); |
|
412 int newIndex = oldIndex + 1; |
|
413 model.add(newIndex, movedOption); |
|
414 setAdvancedOptions(Helper.toArrayOfStrings(model)); |
|
415 } |
|
416 |
|
417 /** |
|
418 * Enabled if the list has exactly one selection and if the selection is |
|
419 * not the last element in the list. |
|
420 */ |
|
421 @Override |
|
422 public void selectionChanged(IStructuredSelection selection) { |
|
423 if (selection.size() != 1) { |
|
424 setEnabled(false); |
|
425 return; |
|
426 } |
|
427 |
|
428 boolean enabled = true; |
|
429 String selectedElement = (String) selection.getFirstElement(); |
|
430 String lastElement = (String) viewer.getElementAt(viewer.getList() |
|
431 .getItemCount() - 1); |
|
432 |
|
433 if (lastElement != null && selectedElement.equals(lastElement)) { |
|
434 enabled = false; |
|
435 } |
|
436 |
|
437 setEnabled(enabled); |
|
438 } |
|
439 } |
|
440 |
|
441 /** |
|
442 * This is the action that moves a command line option up by one position in |
|
443 * the list of assigned options. |
|
444 * |
|
445 * @author barbararosi-schwartz |
|
446 */ |
|
447 private class MoveOptionUpAction extends AbstractOptionAction { |
|
448 |
|
449 /** |
|
450 * The option that has been moved by the user |
|
451 */ |
|
452 private String movedOption = null; |
|
453 |
|
454 private MoveOptionUpAction(Button button) { |
|
455 super("Move Up", button); |
|
456 setEnabled(false); |
|
457 } |
|
458 |
|
459 /** |
|
460 * Returns the option that was moved by the user. |
|
461 * |
|
462 * @return the option that was moved by the user |
|
463 */ |
|
464 String getMovedOption() { |
|
465 return movedOption; |
|
466 } |
|
467 |
|
468 /** |
|
469 * Moves the selected option down by one position in the model. |
|
470 */ |
|
471 @Override |
|
472 public void run() { |
|
473 movedOption = (String) ((StructuredSelection) getSelection()) |
|
474 .getFirstElement(); |
|
475 java.util.List<String> model = Helper |
|
476 .toListOfStrings((String[]) viewer.getInput()); |
|
477 int oldIndex = model.indexOf(movedOption); |
|
478 model.remove(oldIndex); |
|
479 int newIndex = oldIndex - 1; |
|
480 model.add(newIndex, movedOption); |
|
481 setAdvancedOptions(Helper.toArrayOfStrings(model)); |
|
482 } |
|
483 |
|
484 /** |
|
485 * Enabled if the list has exactly one selection and if the selection is |
|
486 * not the first element in the list. |
|
487 */ |
|
488 @Override |
|
489 public void selectionChanged(IStructuredSelection selection) { |
|
490 if (selection.size() != 1) { |
|
491 setEnabled(false); |
|
492 return; |
|
493 } |
|
494 |
|
495 boolean enabled = true; |
|
496 String selectedElement = (String) selection.getFirstElement(); |
|
497 String firstElement = (String) viewer.getElementAt(0); |
|
498 |
|
499 if (firstElement != null && selectedElement.equals(firstElement)) { |
|
500 enabled = false; |
|
501 } |
|
502 |
|
503 setEnabled(enabled); |
|
504 } |
|
505 } |
|
506 |
|
507 /** |
|
508 * This is the action that removes a command line option from the list of |
|
509 * assigned options. |
|
510 * |
|
511 * @author barbararosi-schwartz |
|
512 */ |
|
513 private class RemoveOptionAction extends AbstractOptionAction { |
|
514 |
|
515 private RemoveOptionAction(Button button) { |
|
516 super("Remove", button); |
|
517 setEnabled(false); |
|
518 } |
|
519 |
|
520 /** |
|
521 * Removes the selected options from the model. |
|
522 */ |
|
523 @Override |
|
524 public void run() { |
|
525 StructuredSelection ssel = (StructuredSelection) getSelection(); |
|
526 java.util.List<String> model = Helper |
|
527 .toListOfStrings((String[]) viewer.getInput()); |
|
528 |
|
529 @SuppressWarnings("unchecked") |
|
530 Iterator<String> iter = ssel.iterator(); |
|
531 |
|
532 while (iter.hasNext()) { |
|
533 String to_be_removed = (String) iter.next(); |
|
534 model.remove(to_be_removed); |
|
535 } |
|
536 |
|
537 setAdvancedOptions(Helper.toArrayOfStrings(model)); |
|
538 } |
|
539 |
|
540 /** |
|
541 * Enabled if we have at least one selection in the list. |
|
542 */ |
|
543 @Override |
|
544 public void selectionChanged(IStructuredSelection selection) { |
|
545 if (selection.isEmpty()) { |
|
546 setEnabled(false); |
|
547 return; |
|
548 } |
|
549 |
|
550 setEnabled(true); |
|
551 } |
|
552 } |
|
553 |
|
554 /** |
|
555 * The List of all command line options that may override values entered |
|
556 * elsewhere. |
|
557 */ |
|
558 private static final ArrayList<String> dangerousOptions = new ArrayList<String>(); |
|
559 |
|
560 static { |
|
561 dangerousOptions.add("clean"); |
|
562 dangerousOptions.add("compress"); |
|
563 dangerousOptions.add("log"); |
|
564 dangerousOptions.add("model"); |
|
565 dangerousOptions.add("output"); |
|
566 dangerousOptions.add("tempdir"); |
|
567 } |
|
568 |
|
569 /** |
|
570 * The viewer associated with the List widget. |
|
571 */ |
|
572 private ListViewer viewer; |
|
573 |
|
574 /** |
|
575 * Creates an AdvancedOptionsWidget composite object |
|
576 * |
|
577 * @return void |
|
578 */ |
|
579 public AdvancedOptionsWidget(final Composite parent, int style) { |
|
580 super(parent, style); |
|
581 |
|
582 this.setLayout(new FillLayout()); |
|
583 |
|
584 // The Composite that contains all widgets |
|
585 final Composite gridLayoutComposite = new Composite(this, SWT.NONE); |
|
586 final GridLayout gridLayout = new GridLayout(); |
|
587 gridLayout.numColumns = 2; |
|
588 gridLayoutComposite.setLayout(gridLayout); |
|
589 |
|
590 final Label label = new Label(gridLayoutComposite, SWT.NONE); |
|
591 GridData gd = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false, |
|
592 2, 1); |
|
593 |
|
594 label.setText("Additional Command-Line Parameters"); |
|
595 label.setLayoutData(gd); |
|
596 |
|
597 // The List that contains all assigned command line options |
|
598 final List list = new List(gridLayoutComposite, SWT.BORDER |
|
599 | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI); |
|
600 gd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1); |
|
601 gd.widthHint = 200; |
|
602 |
|
603 list.setLayoutData(gd); |
|
604 |
|
605 viewer = new ListViewer(list); |
|
606 |
|
607 viewer.setContentProvider(new AdvancedOptionsContentProvider()); |
|
608 viewer.setLabelProvider(new AdvancedOptionsLabelProvider()); |
|
609 |
|
610 // The Composite that contains all buttons in a vertical stack |
|
611 final Composite buttonsComposite = new Composite(gridLayoutComposite, |
|
612 SWT.NONE); |
|
613 final RowLayout rowLayout = new RowLayout(SWT.VERTICAL); |
|
614 rowLayout.spacing = 5; |
|
615 rowLayout.wrap = false; |
|
616 rowLayout.fill = true; |
|
617 |
|
618 buttonsComposite.setLayout(rowLayout); |
|
619 |
|
620 gd = new GridData(SWT.RIGHT, SWT.BEGINNING, false, true, 1, 1); |
|
621 buttonsComposite.setLayoutData(gd); |
|
622 |
|
623 // The "Add" button |
|
624 final Button addOptionButton = new Button(buttonsComposite, SWT.NONE); |
|
625 RowData rd = new RowData(); |
|
626 rd.width = 75; |
|
627 |
|
628 addOptionButton.setLayoutData(rd); |
|
629 |
|
630 // The action that backs the "Add" button |
|
631 final AddOptionAction addOptionAction = new AddOptionAction( |
|
632 addOptionButton); |
|
633 |
|
634 // When button is pressed, listener invokes the action's run() method, |
|
635 // then refresh |
|
636 // the List of assigned options and set the selection appropriately |
|
637 addOptionButton.addSelectionListener(new SelectionAdapter() { |
|
638 public void widgetSelected(final SelectionEvent e) { |
|
639 addOptionAction.run(); |
|
640 StructuredSelection oldSel = (StructuredSelection) viewer |
|
641 .getSelection(); |
|
642 viewer.refresh(); |
|
643 |
|
644 String newOption = addOptionAction.getNewOption(); |
|
645 StructuredSelection newSel = (newOption == null) ? oldSel |
|
646 : new StructuredSelection(newOption); |
|
647 |
|
648 viewer.setSelection(newSel); |
|
649 } |
|
650 }); |
|
651 |
|
652 // The "Edit" button |
|
653 final Button editOptionButton = new Button(buttonsComposite, SWT.NONE); |
|
654 rd = new RowData(); |
|
655 rd.width = 75; |
|
656 |
|
657 editOptionButton.setLayoutData(rd); |
|
658 |
|
659 // The action that backs the "Edit" button |
|
660 final EditOptionAction editOptionAction = new EditOptionAction( |
|
661 editOptionButton); |
|
662 |
|
663 // When button is pressed, listener invokes the action's run() method, |
|
664 // then refresh |
|
665 // the List of assigned options and set the selection appropriately |
|
666 editOptionButton.addSelectionListener(new SelectionAdapter() { |
|
667 public void widgetSelected(final SelectionEvent e) { |
|
668 editOptionAction.run(); |
|
669 StructuredSelection oldSel = (StructuredSelection) viewer |
|
670 .getSelection(); |
|
671 |
|
672 viewer.refresh(); |
|
673 viewer.setSelection(oldSel); |
|
674 } |
|
675 }); |
|
676 |
|
677 // The "Remove" button |
|
678 final Button removeOptionButton = new Button(buttonsComposite, SWT.NONE); |
|
679 rd = new RowData(); |
|
680 rd.width = 75; |
|
681 |
|
682 removeOptionButton.setLayoutData(rd); |
|
683 |
|
684 // The action that backs the "Remove" button |
|
685 final RemoveOptionAction removeOptionAction = new RemoveOptionAction( |
|
686 removeOptionButton); |
|
687 |
|
688 // When button is pressed, listener invokes the action's run() method, |
|
689 // then refreshes the List of assigned options and set the selection |
|
690 // appropriately |
|
691 removeOptionButton.addSelectionListener(new SelectionAdapter() { |
|
692 public void widgetSelected(SelectionEvent e) { |
|
693 removeOptionAction.run(); |
|
694 viewer.refresh(); |
|
695 |
|
696 // If the viewer has at least one element, we set the current |
|
697 // selection to that element. |
|
698 Object firstElement = viewer.getElementAt(0); |
|
699 StructuredSelection ssel = (firstElement == null) ? new StructuredSelection( |
|
700 StructuredSelection.EMPTY) |
|
701 : new StructuredSelection(firstElement); |
|
702 |
|
703 viewer.setSelection(ssel); |
|
704 } |
|
705 }); |
|
706 |
|
707 // The "Move Up" button |
|
708 final Button moveOptionUpButton = new Button(buttonsComposite, SWT.NONE); |
|
709 rd = new RowData(); |
|
710 rd.width = 75; |
|
711 |
|
712 moveOptionUpButton.setLayoutData(rd); |
|
713 |
|
714 // The action that backs the "Move Up" button |
|
715 final MoveOptionUpAction moveOptionUpAction = new MoveOptionUpAction( |
|
716 moveOptionUpButton); |
|
717 |
|
718 // When button is pressed, listener invokes the action's run() method, |
|
719 // then refreshes the List of assigned options and set the selection |
|
720 // appropriately |
|
721 moveOptionUpButton.addSelectionListener(new SelectionAdapter() { |
|
722 public void widgetSelected(final SelectionEvent e) { |
|
723 moveOptionUpAction.run(); |
|
724 viewer.refresh(); |
|
725 |
|
726 StructuredSelection newSel = new StructuredSelection( |
|
727 moveOptionUpAction.getMovedOption()); |
|
728 |
|
729 viewer.setSelection(newSel); |
|
730 } |
|
731 }); |
|
732 |
|
733 // The "Move Down" button |
|
734 final Button moveOptionDownButton = new Button(buttonsComposite, |
|
735 SWT.NONE); |
|
736 rd = new RowData(); |
|
737 rd.width = 75; |
|
738 |
|
739 moveOptionDownButton.setLayoutData(rd); |
|
740 |
|
741 // The action that backs the "Move Down" button |
|
742 final MoveOptionDownAction moveOptionDownAction = new MoveOptionDownAction( |
|
743 moveOptionDownButton); |
|
744 |
|
745 // When button is pressed, listener invokes the action's run() method, |
|
746 // then refreshes the List of assigned options and set the selection |
|
747 // appropriately |
|
748 moveOptionDownButton.addSelectionListener(new SelectionAdapter() { |
|
749 public void widgetSelected(final SelectionEvent e) { |
|
750 moveOptionDownAction.run(); |
|
751 viewer.refresh(); |
|
752 |
|
753 StructuredSelection newSel = new StructuredSelection( |
|
754 moveOptionDownAction.getMovedOption()); |
|
755 |
|
756 viewer.setSelection(newSel); |
|
757 } |
|
758 }); |
|
759 } |
|
760 |
|
761 /** |
|
762 * Returns the advanced options |
|
763 * |
|
764 * @return String[] |
|
765 */ |
|
766 public String[] getAdvancedOptions() { |
|
767 return (String[]) viewer.getInput(); |
|
768 } |
|
769 |
|
770 /** |
|
771 * Sets the advanced options |
|
772 * |
|
773 * @param options |
|
774 * A list containing advanced options. |
|
775 * @return void |
|
776 */ |
|
777 public void setAdvancedOptions(String[] options) { |
|
778 if (options != null) { |
|
779 viewer.setInput(options); |
|
780 } |
|
781 } |
|
782 |
|
783 } |