9
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 2007 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 * Teddy Walker <teddy.walker@googlemail.com>
|
|
11 * - Bug 188056 [Preferences] PreferencePages have to less indent in PreferenceDialog
|
|
12 * Port to the D programming language:
|
|
13 * Frank Benoit <benoit@tionex.de>
|
|
14 *******************************************************************************/
|
|
15 module dwtx.jface.preference.PreferenceDialog;
|
|
16
|
34
|
17 import dwtx.jface.preference.IPreferencePageContainer;
|
|
18 import dwtx.jface.preference.IPreferencePage;
|
|
19 import dwtx.jface.preference.IPreferenceNode;
|
|
20 import dwtx.jface.preference.IPreferenceStore;
|
|
21 import dwtx.jface.preference.IPersistentPreferenceStore;
|
|
22 import dwtx.jface.preference.PreferenceManager;
|
|
23 import dwtx.jface.preference.PreferencePage;
|
|
24 import dwtx.jface.preference.PreferenceLabelProvider;
|
|
25 import dwtx.jface.preference.PreferenceContentProvider;
|
9
|
26
|
|
27 import dwt.DWT;
|
|
28 import dwt.custom.BusyIndicator;
|
|
29 import dwt.custom.ScrolledComposite;
|
|
30 import dwt.events.ControlAdapter;
|
|
31 import dwt.events.ControlEvent;
|
|
32 import dwt.events.DisposeEvent;
|
|
33 import dwt.events.DisposeListener;
|
|
34 import dwt.events.HelpEvent;
|
|
35 import dwt.events.HelpListener;
|
|
36 import dwt.events.SelectionAdapter;
|
|
37 import dwt.events.SelectionEvent;
|
|
38 import dwt.events.ShellAdapter;
|
|
39 import dwt.events.ShellEvent;
|
|
40 import dwt.graphics.Font;
|
|
41 import dwt.graphics.Point;
|
|
42 import dwt.graphics.Rectangle;
|
|
43 import dwt.layout.FormAttachment;
|
|
44 import dwt.layout.FormData;
|
|
45 import dwt.layout.FormLayout;
|
|
46 import dwt.layout.GridData;
|
|
47 import dwt.layout.GridLayout;
|
|
48 import dwt.widgets.Button;
|
|
49 import dwt.widgets.Composite;
|
|
50 import dwt.widgets.Control;
|
|
51 import dwt.widgets.Event;
|
|
52 import dwt.widgets.Label;
|
|
53 import dwt.widgets.Layout;
|
|
54 import dwt.widgets.Listener;
|
|
55 import dwt.widgets.Sash;
|
|
56 import dwt.widgets.Shell;
|
|
57 import dwt.widgets.Tree;
|
|
58 import dwtx.core.runtime.Assert;
|
|
59 import dwtx.core.runtime.ISafeRunnable;
|
|
60 import dwtx.core.runtime.IStatus;
|
|
61 import dwtx.core.runtime.ListenerList;
|
|
62 import dwtx.core.runtime.SafeRunner;
|
|
63 import dwtx.core.runtime.Status;
|
|
64 import dwtx.jface.dialogs.DialogMessageArea;
|
|
65 import dwtx.jface.dialogs.IDialogConstants;
|
|
66 import dwtx.jface.dialogs.IMessageProvider;
|
|
67 import dwtx.jface.dialogs.IPageChangeProvider;
|
|
68 import dwtx.jface.dialogs.IPageChangedListener;
|
|
69 import dwtx.jface.dialogs.MessageDialog;
|
|
70 import dwtx.jface.dialogs.PageChangedEvent;
|
|
71 import dwtx.jface.dialogs.TrayDialog;
|
|
72 import dwtx.jface.resource.JFaceResources;
|
|
73 import dwtx.jface.util.IPropertyChangeListener;
|
|
74 import dwtx.jface.util.Policy;
|
|
75 import dwtx.jface.util.PropertyChangeEvent;
|
|
76 import dwtx.jface.util.SafeRunnable;
|
|
77 import dwtx.jface.viewers.ISelection;
|
|
78 import dwtx.jface.viewers.ISelectionChangedListener;
|
|
79 import dwtx.jface.viewers.IStructuredSelection;
|
|
80 import dwtx.jface.viewers.SelectionChangedEvent;
|
|
81 import dwtx.jface.viewers.StructuredSelection;
|
|
82 import dwtx.jface.viewers.TreeViewer;
|
|
83 import dwtx.jface.viewers.ViewerFilter;
|
|
84
|
34
|
85 import dwt.dwthelper.utils;
|
|
86 import dwt.dwthelper.Runnable;
|
|
87
|
9
|
88 /**
|
|
89 * A preference dialog is a hierarchical presentation of preference pages. Each
|
|
90 * page is represented by a node in the tree shown on the left hand side of the
|
|
91 * dialog; when a node is selected, the corresponding page is shown on the right
|
|
92 * hand side.
|
|
93 */
|
34
|
94 public class PreferenceDialog : TrayDialog, IPreferencePageContainer, IPageChangeProvider {
|
9
|
95 /**
|
|
96 * Layout for the page container.
|
|
97 *
|
|
98 */
|
34
|
99 private class PageLayout : Layout {
|
9
|
100 public Point computeSize(Composite composite, int wHint, int hHint, bool force) {
|
|
101 if (wHint !is DWT.DEFAULT && hHint !is DWT.DEFAULT) {
|
|
102 return new Point(wHint, hHint);
|
|
103 }
|
|
104 int x = minimumPageSize.x;
|
|
105 int y = minimumPageSize.y;
|
|
106 Control[] children = composite.getChildren();
|
|
107 for (int i = 0; i < children.length; i++) {
|
|
108 Point size = children[i].computeSize(DWT.DEFAULT, DWT.DEFAULT, force);
|
|
109 x = Math.max(x, size.x);
|
|
110 y = Math.max(y, size.y);
|
|
111 }
|
|
112
|
|
113 //As pages can implement thier own computeSize
|
|
114 //take it into account
|
|
115 if(currentPage !is null){
|
|
116 Point size = currentPage.computeSize();
|
|
117 x = Math.max(x, size.x);
|
|
118 y = Math.max(y, size.y);
|
|
119 }
|
|
120
|
|
121 if (wHint !is DWT.DEFAULT) {
|
|
122 x = wHint;
|
|
123 }
|
|
124 if (hHint !is DWT.DEFAULT) {
|
|
125 y = hHint;
|
|
126 }
|
|
127 return new Point(x, y);
|
|
128 }
|
|
129
|
|
130 public void layout(Composite composite, bool force) {
|
|
131 Rectangle rect = composite.getClientArea();
|
|
132 Control[] children = composite.getChildren();
|
|
133 for (int i = 0; i < children.length; i++) {
|
|
134 children[i].setSize(rect.width, rect.height);
|
|
135 }
|
|
136 }
|
|
137 }
|
|
138
|
|
139 //The id of the last page that was selected
|
|
140 private static String lastPreferenceId = null;
|
|
141
|
|
142 //The last known tree width
|
|
143 private static int lastTreeWidth = 180;
|
|
144
|
|
145 /**
|
|
146 * Indentifier for the error image
|
|
147 */
|
34
|
148 public static const String PREF_DLG_IMG_TITLE_ERROR = DLG_IMG_MESSAGE_ERROR;
|
9
|
149
|
|
150 /**
|
|
151 * Title area fields
|
|
152 */
|
34
|
153 public static const String PREF_DLG_TITLE_IMG = "preference_dialog_title_image"; //$NON-NLS-1$
|
9
|
154
|
|
155 /**
|
|
156 * Return code used when dialog failed
|
|
157 */
|
34
|
158 protected static const int FAILED = 2;
|
9
|
159
|
|
160 /**
|
|
161 * The current preference page, or <code>null</code> if there is none.
|
|
162 */
|
|
163 private IPreferencePage currentPage;
|
|
164
|
|
165 private DialogMessageArea messageArea;
|
|
166
|
|
167 private Point lastShellSize;
|
|
168
|
|
169 private IPreferenceNode lastSuccessfulNode;
|
|
170
|
|
171 /**
|
|
172 * The minimum page size; 400 by 400 by default.
|
|
173 *
|
|
174 * @see #setMinimumPageSize(Point)
|
|
175 */
|
34
|
176 private Point minimumPageSize;
|
9
|
177
|
|
178 /**
|
|
179 * The OK button.
|
|
180 */
|
|
181 private Button okButton;
|
|
182
|
|
183 /**
|
|
184 * The Composite in which a page is shown.
|
|
185 */
|
|
186 private Composite pageContainer;
|
|
187
|
|
188 /**
|
|
189 * The preference manager.
|
|
190 */
|
|
191 private PreferenceManager preferenceManager;
|
|
192
|
|
193 /**
|
|
194 * Flag for the presence of the error message.
|
|
195 */
|
|
196 private bool showingError = false;
|
|
197
|
|
198 /**
|
|
199 * Preference store, initially <code>null</code> meaning none.
|
|
200 *
|
|
201 * @see #setPreferenceStore
|
|
202 */
|
|
203 private IPreferenceStore preferenceStore;
|
|
204
|
|
205 private Composite titleArea;
|
|
206
|
|
207 /**
|
|
208 * The tree viewer.
|
|
209 */
|
|
210 private TreeViewer treeViewer;
|
|
211
|
34
|
212 private ListenerList pageChangedListeners;
|
9
|
213
|
|
214 /**
|
|
215 * Composite with a FormLayout to contain the title area
|
|
216 */
|
|
217 Composite formTitleComposite;
|
|
218
|
|
219 private ScrolledComposite scrolled;
|
|
220
|
|
221 /**
|
|
222 * Creates a new preference dialog under the control of the given preference
|
|
223 * manager.
|
|
224 *
|
|
225 * @param parentShell
|
|
226 * the parent shell
|
|
227 * @param manager
|
|
228 * the preference manager
|
|
229 */
|
34
|
230 public this(Shell parentShell, PreferenceManager manager) {
|
|
231 minimumPageSize = new Point(400, 400);
|
|
232 pageChangedListeners = new ListenerList();
|
9
|
233 super(parentShell);
|
|
234 setShellStyle(getShellStyle() | DWT.RESIZE | DWT.MAX);
|
|
235 preferenceManager = manager;
|
|
236 }
|
|
237
|
|
238 /*
|
|
239 * (non-Javadoc)
|
|
240 *
|
|
241 * @see dwtx.jface.dialogs.Dialog#buttonPressed(int)
|
|
242 */
|
|
243 protected void buttonPressed(int buttonId) {
|
|
244 switch (buttonId) {
|
|
245 case IDialogConstants.OK_ID: {
|
|
246 okPressed();
|
|
247 return;
|
|
248 }
|
|
249 case IDialogConstants.CANCEL_ID: {
|
|
250 cancelPressed();
|
|
251 return;
|
|
252 }
|
|
253 case IDialogConstants.HELP_ID: {
|
|
254 helpPressed();
|
|
255 return;
|
|
256 }
|
|
257 }
|
|
258 }
|
|
259
|
|
260 /*
|
|
261 * (non-Javadoc)
|
|
262 *
|
|
263 * @see dwtx.jface.dialogs.Dialog#cancelPressed()
|
|
264 */
|
|
265 protected void cancelPressed() {
|
|
266 // Inform all pages that we are cancelling
|
34
|
267 foreach( e; preferenceManager.getElements(PreferenceManager.PRE_ORDER)){
|
|
268 IPreferenceNode node = cast(IPreferenceNode) e;
|
9
|
269 if (getPage(node) !is null) {
|
34
|
270
|
|
271 // this_: strange workaround for compiler error with dmd 1.028 in run()
|
|
272 SafeRunnable.run(new class(this) SafeRunnable {
|
|
273 PreferenceDialog this_;
|
|
274 IPreferenceNode node_;
|
|
275 this(PreferenceDialog outer_){
|
|
276 node_=node;
|
|
277 this_=outer_;
|
|
278 auto p = this_.getPage( node );
|
|
279 }
|
9
|
280 public void run() {
|
34
|
281 if (!this_.getPage(node_).performCancel()) {
|
9
|
282 return;
|
|
283 }
|
|
284 }
|
|
285 });
|
|
286 }
|
|
287 }
|
|
288 setReturnCode(CANCEL);
|
|
289 close();
|
|
290 }
|
|
291
|
|
292 /**
|
|
293 * Clear the last selected node. This is so that we not chache the last
|
|
294 * selection in case of an error.
|
|
295 */
|
|
296 void clearSelectedNode() {
|
|
297 setSelectedNodePreference(null);
|
|
298 }
|
|
299
|
|
300 /*
|
|
301 * (non-Javadoc)
|
|
302 *
|
|
303 * @see dwtx.jface.window.Window#close()
|
|
304 */
|
|
305 public bool close() {
|
|
306
|
|
307 //Do this is in a SafeRunnable as it may run client code
|
34
|
308 SafeRunnable runnable = new class SafeRunnable{
|
9
|
309 /* (non-Javadoc)
|
|
310 * @see dwtx.core.runtime.ISafeRunnable#run()
|
|
311 */
|
34
|
312 public void run() {
|
|
313 auto nodes = preferenceManager.getElements(PreferenceManager.PRE_ORDER);
|
9
|
314 for (int i = 0; i < nodes.size(); i++) {
|
34
|
315 IPreferenceNode node = cast(IPreferenceNode) nodes.get(i);
|
9
|
316 node.disposeResources();
|
|
317 }
|
|
318
|
|
319 }
|
|
320
|
|
321 /* (non-Javadoc)
|
|
322 * @see dwtx.jface.util.SafeRunnable#handleException(java.lang.Throwable)
|
|
323 */
|
34
|
324 public void handleException(Exception e) {
|
9
|
325 super.handleException(e);
|
|
326 clearSelectedNode();//Do not cache a node with problems
|
|
327 }
|
|
328 };
|
|
329
|
|
330 SafeRunner.run(runnable);
|
|
331
|
|
332 return super.close();
|
|
333 }
|
|
334
|
|
335 /*
|
|
336 * (non-Javadoc)
|
|
337 *
|
|
338 * @see dwtx.jface.window.Window#configureShell(dwt.widgets.Shell)
|
|
339 */
|
|
340 protected void configureShell(Shell newShell) {
|
|
341 super.configureShell(newShell);
|
|
342 newShell.setText(JFaceResources.getString("PreferenceDialog.title")); //$NON-NLS-1$
|
34
|
343 newShell.addShellListener(new class ShellAdapter {
|
9
|
344 public void shellActivated(ShellEvent e) {
|
|
345 if (lastShellSize is null) {
|
|
346 lastShellSize = getShell().getSize();
|
|
347 }
|
|
348 }
|
|
349
|
|
350 });
|
|
351
|
|
352 }
|
|
353
|
|
354 /*
|
|
355 * (non-Javadoc)
|
|
356 *
|
|
357 * @see dwtx.jface.window.Window#constrainShellSize()
|
|
358 */
|
|
359 protected void constrainShellSize() {
|
|
360 super.constrainShellSize();
|
|
361 // record opening shell size
|
|
362 if (lastShellSize is null) {
|
|
363 lastShellSize = getShell().getSize();
|
|
364 }
|
|
365 }
|
|
366
|
|
367 /*
|
|
368 * (non-Javadoc)
|
|
369 *
|
|
370 * @see dwtx.jface.dialogs.Dialog#createButtonsForButtonBar(dwt.widgets.Composite)
|
|
371 */
|
|
372 protected void createButtonsForButtonBar(Composite parent) {
|
|
373 // create OK and Cancel buttons by default
|
|
374 okButton = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
|
|
375 getShell().setDefaultButton(okButton);
|
|
376 createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
|
|
377 }
|
|
378
|
|
379 /*
|
|
380 * (non-Javadoc)
|
|
381 *
|
|
382 * @see dwtx.jface.window.Window#createContents(dwt.widgets.Composite)
|
|
383 */
|
34
|
384 protected Control createContents(Composite parent) {
|
|
385 Control[1] control;
|
|
386 BusyIndicator.showWhile(getShell().getDisplay(), new class Runnable {
|
|
387 Composite parent_;
|
|
388 this(){
|
|
389 parent_=parent;
|
|
390 }
|
9
|
391 public void run() {
|
34
|
392 control[0] = callSuperCreateContents(parent);
|
9
|
393 // Add the first page
|
|
394 selectSavedItem();
|
|
395 }
|
|
396 });
|
|
397
|
|
398 return control[0];
|
|
399 }
|
34
|
400 private Control callSuperCreateContents( Composite c ){
|
|
401 return super.createContents( c );
|
|
402 }
|
9
|
403 /*
|
|
404 * (non-Javadoc)
|
|
405 *
|
|
406 * @see dwtx.jface.dialogs.Dialog#createDialogArea(dwt.widgets.Composite)
|
|
407 */
|
|
408 protected Control createDialogArea(Composite parent) {
|
34
|
409 final Composite composite = cast(Composite) super.createDialogArea(parent);
|
|
410 GridLayout parentLayout = (cast(GridLayout) composite.getLayout());
|
9
|
411 parentLayout.numColumns = 4;
|
|
412 parentLayout.marginHeight = 0;
|
|
413 parentLayout.marginWidth = 0;
|
|
414 parentLayout.verticalSpacing = 0;
|
|
415 parentLayout.horizontalSpacing = 0;
|
|
416
|
|
417 composite.setBackground(parent.getDisplay().getSystemColor(DWT.COLOR_LIST_BACKGROUND));
|
|
418
|
|
419 Control treeControl = createTreeAreaContents(composite);
|
|
420 createSash(composite,treeControl);
|
|
421
|
|
422 Label versep = new Label(composite, DWT.SEPARATOR | DWT.VERTICAL);
|
|
423 GridData verGd = new GridData(GridData.FILL_VERTICAL | GridData.GRAB_VERTICAL);
|
|
424
|
|
425 versep.setLayoutData(verGd);
|
|
426 versep.setLayoutData(new GridData(DWT.LEFT, DWT.FILL, false, true));
|
|
427
|
|
428 Composite pageAreaComposite = new Composite(composite, DWT.NONE);
|
|
429 pageAreaComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
|
|
430 GridLayout layout = new GridLayout(1, true);
|
|
431 layout.marginHeight = 0;
|
|
432 layout.marginWidth = 0;
|
|
433 layout.verticalSpacing = 0;
|
|
434 pageAreaComposite.setLayout(layout);
|
|
435
|
|
436 formTitleComposite = new Composite(pageAreaComposite, DWT.NONE);
|
|
437 FormLayout titleLayout = new FormLayout();
|
|
438 titleLayout.marginWidth = 0;
|
|
439 titleLayout.marginHeight = 0;
|
|
440 formTitleComposite.setLayout(titleLayout);
|
|
441
|
|
442 GridData titleGridData = new GridData(GridData.FILL_HORIZONTAL);
|
|
443 titleGridData.horizontalIndent = IDialogConstants.HORIZONTAL_MARGIN;
|
|
444 formTitleComposite.setLayoutData(titleGridData);
|
|
445
|
|
446 // Build the title area and separator line
|
|
447 Composite titleComposite = new Composite(formTitleComposite, DWT.NONE);
|
|
448 layout = new GridLayout();
|
|
449 layout.marginBottom = 5;
|
|
450 layout.marginHeight = 0;
|
|
451 layout.marginWidth = 0;
|
|
452 layout.horizontalSpacing = 0;
|
|
453 titleComposite.setLayout(layout);
|
|
454
|
|
455 FormData titleFormData = new FormData();
|
|
456 titleFormData.top = new FormAttachment(0,0);
|
|
457 titleFormData.left = new FormAttachment(0,0);
|
|
458 titleFormData.right = new FormAttachment(100,0);
|
|
459 titleFormData.bottom = new FormAttachment(100,0);
|
|
460
|
|
461 titleComposite.setLayoutData(titleFormData);
|
|
462 createTitleArea(titleComposite);
|
|
463
|
|
464 Label separator = new Label(pageAreaComposite, DWT.HORIZONTAL | DWT.SEPARATOR);
|
|
465
|
|
466 separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));
|
|
467
|
|
468
|
|
469 // Build the Page container
|
|
470 pageContainer = createPageContainer(pageAreaComposite);
|
|
471 GridData pageContainerData = new GridData(GridData.FILL_BOTH);
|
|
472 pageContainerData.horizontalIndent = IDialogConstants.HORIZONTAL_MARGIN;
|
|
473 pageContainer.setLayoutData(pageContainerData);
|
|
474 // Build the separator line
|
|
475 Label bottomSeparator = new Label(parent, DWT.HORIZONTAL | DWT.SEPARATOR);
|
|
476 bottomSeparator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));
|
|
477 return composite;
|
|
478 }
|
|
479
|
|
480 /**
|
|
481 * Create the sash with right control on the right. Note
|
|
482 * that this method assumes GridData for the layout data
|
|
483 * of the rightControl.
|
|
484 * @param composite
|
|
485 * @param rightControl
|
|
486 * @return Sash
|
|
487 *
|
|
488 * @since 3.1
|
|
489 */
|
34
|
490 protected Sash createSash(Composite composite, Control rightControl) {
|
|
491 Sash sash = new Sash(composite, DWT.VERTICAL);
|
9
|
492 sash.setLayoutData(new GridData(GridData.FILL_VERTICAL));
|
|
493 sash.setBackground(composite.getDisplay().getSystemColor(DWT.COLOR_LIST_BACKGROUND));
|
|
494 // the following listener resizes the tree control based on sash deltas.
|
|
495 // If necessary, it will also grow/shrink the dialog.
|
34
|
496 sash.addListener(DWT.Selection, new class Listener {
|
|
497 Composite composite_;
|
|
498 Control rightControl_;
|
|
499 Sash sash_;
|
|
500 this(){
|
|
501 composite_=composite;
|
|
502 rightControl_=rightControl;
|
|
503 sash_=sash;
|
|
504 }
|
9
|
505 /*
|
|
506 * (non-Javadoc)
|
|
507 *
|
|
508 * @see dwt.widgets.Listener#handleEvent(dwt.widgets.Event)
|
|
509 */
|
|
510 public void handleEvent(Event event) {
|
|
511 if (event.detail is DWT.DRAG) {
|
|
512 return;
|
|
513 }
|
34
|
514 int shift = event.x - sash_.getBounds().x;
|
|
515 GridData data = cast(GridData) rightControl_.getLayoutData();
|
9
|
516 int newWidthHint = data.widthHint + shift;
|
|
517 if (newWidthHint < 20) {
|
|
518 return;
|
|
519 }
|
|
520 Point computedSize = getShell().computeSize(DWT.DEFAULT, DWT.DEFAULT);
|
|
521 Point currentSize = getShell().getSize();
|
|
522 // if the dialog wasn't of a custom size we know we can shrink
|
|
523 // it if necessary based on sash movement.
|
34
|
524 bool customSize = !computedSize.opEquals(currentSize);
|
9
|
525 data.widthHint = newWidthHint;
|
|
526 setLastTreeWidth(newWidthHint);
|
34
|
527 composite_.layout(true);
|
9
|
528 // recompute based on new widget size
|
|
529 computedSize = getShell().computeSize(DWT.DEFAULT, DWT.DEFAULT);
|
|
530 // if the dialog was of a custom size then increase it only if
|
|
531 // necessary.
|
|
532 if (customSize) {
|
|
533 computedSize.x = Math.max(computedSize.x, currentSize.x);
|
|
534 }
|
|
535 computedSize.y = Math.max(computedSize.y, currentSize.y);
|
34
|
536 if (computedSize.opEquals(currentSize)) {
|
9
|
537 return;
|
|
538 }
|
|
539 setShellSize(computedSize.x, computedSize.y);
|
|
540 lastShellSize = getShell().getSize();
|
|
541 }
|
|
542 });
|
|
543 return sash;
|
|
544 }
|
|
545
|
|
546 /**
|
|
547 * Creates the inner page container.
|
|
548 *
|
|
549 * @param parent
|
|
550 * @return Composite
|
|
551 */
|
|
552 protected Composite createPageContainer(Composite parent) {
|
|
553
|
|
554 Composite outer = new Composite(parent, DWT.NONE);
|
|
555
|
|
556 GridData outerData = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL
|
|
557 | GridData.GRAB_VERTICAL);
|
|
558 outerData.horizontalIndent = IDialogConstants.HORIZONTAL_MARGIN;
|
|
559
|
|
560 outer.setLayout(new GridLayout());
|
|
561 outer.setLayoutData(outerData);
|
|
562
|
|
563 //Create an outer composite for spacing
|
|
564 scrolled = new ScrolledComposite(outer, DWT.V_SCROLL | DWT.H_SCROLL);
|
|
565
|
|
566 scrolled.setExpandHorizontal(true);
|
|
567 scrolled.setExpandVertical(true);
|
|
568
|
|
569 GridData scrolledData = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL
|
|
570 | GridData.GRAB_VERTICAL);
|
|
571
|
|
572 scrolled.setLayoutData(scrolledData);
|
|
573
|
|
574 Composite result = new Composite(scrolled, DWT.NONE);
|
|
575
|
|
576 GridData resultData = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL
|
|
577 | GridData.GRAB_VERTICAL);
|
|
578
|
|
579 result.setLayout(getPageLayout());
|
|
580 result.setLayoutData(resultData);
|
|
581
|
|
582 scrolled.setContent(result);
|
|
583
|
|
584 return result;
|
|
585 }
|
|
586
|
|
587 /**
|
|
588 * Return the layout for the composite that contains
|
|
589 * the pages.
|
|
590 * @return PageLayout
|
|
591 *
|
|
592 * @since 3.1
|
|
593 */
|
|
594 protected Layout getPageLayout() {
|
|
595 return new PageLayout();
|
|
596 }
|
|
597
|
|
598 /**
|
|
599 * Creates the wizard's title area.
|
|
600 *
|
|
601 * @param parent
|
|
602 * the DWT parent for the title area composite.
|
|
603 * @return the created title area composite.
|
|
604 */
|
|
605 protected Composite createTitleArea(Composite parent) {
|
|
606 // Create the title area which will contain
|
|
607 // a title, message, and image.
|
|
608 int margins = 2;
|
|
609 titleArea = new Composite(parent, DWT.NONE);
|
|
610 FormLayout layout = new FormLayout();
|
|
611 layout.marginHeight = 0;
|
|
612 layout.marginWidth = margins;
|
|
613 titleArea.setLayout(layout);
|
|
614
|
|
615
|
|
616 GridData layoutData = new GridData(GridData.FILL_HORIZONTAL);
|
|
617 layoutData.verticalAlignment = DWT.TOP;
|
|
618 titleArea.setLayoutData(layoutData);
|
|
619
|
|
620 // Message label
|
|
621 messageArea = new DialogMessageArea();
|
|
622 messageArea.createContents(titleArea);
|
|
623
|
34
|
624 titleArea.addControlListener(new class ControlAdapter {
|
9
|
625 /* (non-Javadoc)
|
|
626 * @see dwt.events.ControlAdapter#controlResized(dwt.events.ControlEvent)
|
|
627 */
|
|
628 public void controlResized(ControlEvent e) {
|
|
629 updateMessage();
|
|
630 }
|
|
631 });
|
|
632
|
34
|
633 final IPropertyChangeListener fontListener = new class IPropertyChangeListener {
|
9
|
634 public void propertyChange(PropertyChangeEvent event) {
|
|
635 if (JFaceResources.BANNER_FONT.equals(event.getProperty())) {
|
|
636 updateMessage();
|
|
637 }
|
|
638 if (JFaceResources.DIALOG_FONT.equals(event.getProperty())) {
|
|
639 updateMessage();
|
|
640 Font dialogFont = JFaceResources.getDialogFont();
|
|
641 updateTreeFont(dialogFont);
|
34
|
642 Control[] children = (cast(Composite) buttonBar).getChildren();
|
9
|
643 for (int i = 0; i < children.length; i++) {
|
|
644 children[i].setFont(dialogFont);
|
|
645 }
|
|
646 }
|
|
647 }
|
|
648 };
|
|
649
|
34
|
650 titleArea.addDisposeListener(new class DisposeListener {
|
9
|
651 public void widgetDisposed(DisposeEvent event) {
|
|
652 JFaceResources.getFontRegistry().removeListener(fontListener);
|
|
653 }
|
|
654 });
|
|
655 JFaceResources.getFontRegistry().addListener(fontListener);
|
|
656 messageArea.setTitleLayoutData(createMessageAreaData());
|
|
657 messageArea.setMessageLayoutData(createMessageAreaData());
|
|
658 return titleArea;
|
|
659 }
|
|
660
|
|
661 /**
|
|
662 * Create the layout data for the message area.
|
|
663 *
|
|
664 * @return FormData for the message area.
|
|
665 */
|
|
666 private FormData createMessageAreaData() {
|
|
667 FormData messageData = new FormData();
|
|
668 messageData.top = new FormAttachment(0);
|
|
669 messageData.bottom = new FormAttachment(100);
|
|
670 messageData.right = new FormAttachment(100);
|
|
671 messageData.left = new FormAttachment(0);
|
|
672 return messageData;
|
|
673 }
|
|
674
|
|
675 /**
|
|
676 * @param parent
|
|
677 * the DWT parent for the tree area controls.
|
|
678 * @return the new <code>Control</code>.
|
|
679 * @since 3.0
|
|
680 */
|
|
681 protected Control createTreeAreaContents(Composite parent) {
|
|
682 // Build the tree an put it into the composite.
|
|
683 treeViewer = createTreeViewer(parent);
|
|
684 treeViewer.setInput(getPreferenceManager());
|
|
685 updateTreeFont(JFaceResources.getDialogFont());
|
|
686 layoutTreeAreaControl(treeViewer.getControl());
|
|
687 return treeViewer.getControl();
|
|
688 }
|
|
689
|
|
690 /**
|
|
691 * Create a new <code>TreeViewer</code>.
|
|
692 *
|
|
693 * @param parent
|
|
694 * the parent <code>Composite</code>.
|
|
695 * @return the <code>TreeViewer</code>.
|
|
696 * @since 3.0
|
|
697 */
|
|
698 protected TreeViewer createTreeViewer(Composite parent) {
|
|
699 final TreeViewer viewer = new TreeViewer(parent, DWT.NONE);
|
|
700 addListeners(viewer);
|
|
701 viewer.setLabelProvider(new PreferenceLabelProvider());
|
|
702 viewer.setContentProvider(new PreferenceContentProvider());
|
|
703 return viewer;
|
|
704 }
|
|
705
|
|
706 /**
|
|
707 * Add the listeners to the tree viewer.
|
|
708 * @param viewer
|
|
709 *
|
|
710 * @since 3.1
|
|
711 */
|
34
|
712 protected void addListeners(TreeViewer viewer) {
|
|
713 viewer.addPostSelectionChangedListener(new class ISelectionChangedListener {
|
|
714 TreeViewer viewer_;
|
|
715 this(){
|
|
716 viewer_=viewer;
|
|
717 }
|
9
|
718 private void handleError() {
|
|
719 try {
|
|
720 // remove the listener temporarily so that the events caused
|
|
721 // by the error handling dont further cause error handling
|
|
722 // to occur.
|
34
|
723 viewer_.removePostSelectionChangedListener(this);
|
9
|
724 showPageFlippingAbortDialog();
|
|
725 selectCurrentPageAgain();
|
|
726 clearSelectedNode();
|
|
727 } finally {
|
34
|
728 viewer_.addPostSelectionChangedListener(this);
|
9
|
729 }
|
|
730 }
|
|
731
|
|
732 public void selectionChanged(SelectionChangedEvent event) {
|
34
|
733 Object selection = cast(Object) getSingleSelection(event.getSelection());
|
|
734 if (cast(IPreferenceNode)selection ) {
|
9
|
735 if (!isCurrentPageValid()) {
|
|
736 handleError();
|
34
|
737 } else if (!showPage(cast(IPreferenceNode) selection)) {
|
9
|
738 // Page flipping wasn't successful
|
|
739 handleError();
|
|
740 } else {
|
|
741 // Everything went well
|
34
|
742 lastSuccessfulNode = cast(IPreferenceNode) selection;
|
9
|
743 }
|
|
744 }
|
|
745 }
|
|
746 });
|
34
|
747 (cast(Tree) viewer.getControl()).addSelectionListener(new class SelectionAdapter {
|
|
748 TreeViewer viewer_;
|
|
749 this(){
|
|
750 viewer_=viewer;
|
|
751 }
|
|
752 public void widgetDefaultSelected(SelectionEvent event) {
|
|
753 ISelection selection = viewer_.getSelection();
|
9
|
754 if (selection.isEmpty()) {
|
|
755 return;
|
|
756 }
|
|
757 IPreferenceNode singleSelection = getSingleSelection(selection);
|
34
|
758 bool expanded = viewer_.getExpandedState(cast(Object)singleSelection);
|
|
759 viewer_.setExpandedState(cast(Object)singleSelection, !expanded);
|
9
|
760 }
|
|
761 });
|
|
762 //Register help listener on the tree to use context sensitive help
|
34
|
763 viewer.getControl().addHelpListener(new class HelpListener {
|
9
|
764 public void helpRequested(HelpEvent event) {
|
|
765 // call perform help on the current page
|
|
766 if (currentPage !is null) {
|
|
767 currentPage.performHelp();
|
|
768 }
|
|
769 }
|
|
770 });
|
|
771 }
|
|
772
|
|
773 /**
|
|
774 * Find the <code>IPreferenceNode</code> that has data the same id as the
|
|
775 * supplied value.
|
|
776 *
|
|
777 * @param nodeId
|
|
778 * the id to search for.
|
|
779 * @return <code>IPreferenceNode</code> or <code>null</code> if not
|
|
780 * found.
|
|
781 */
|
|
782 protected IPreferenceNode findNodeMatching(String nodeId) {
|
34
|
783 foreach( e; preferenceManager.getElements(PreferenceManager.POST_ORDER)){
|
|
784 IPreferenceNode node = cast(IPreferenceNode) e;
|
9
|
785 if (node.getId().equals(nodeId)) {
|
|
786 return node;
|
|
787 }
|
|
788 }
|
|
789 return null;
|
|
790 }
|
|
791
|
|
792 /**
|
|
793 * Get the last known right side width.
|
|
794 *
|
|
795 * @return the width.
|
|
796 */
|
|
797 protected int getLastRightWidth() {
|
|
798 return lastTreeWidth;
|
|
799 }
|
|
800
|
|
801 /**
|
|
802 * Returns the preference mananger used by this preference dialog.
|
|
803 *
|
|
804 * @return the preference mananger
|
|
805 */
|
|
806 public PreferenceManager getPreferenceManager() {
|
|
807 return preferenceManager;
|
|
808 }
|
|
809
|
|
810 /*
|
|
811 * (non-Javadoc)
|
|
812 *
|
|
813 * @see dwtx.jface.preference.IPreferencePageContainer#getPreferenceStore()
|
|
814 */
|
|
815 public IPreferenceStore getPreferenceStore() {
|
|
816 return preferenceStore;
|
|
817 }
|
|
818
|
|
819 /**
|
|
820 * Get the name of the selected item preference
|
|
821 *
|
|
822 * @return String
|
|
823 */
|
|
824 protected String getSelectedNodePreference() {
|
|
825 return lastPreferenceId;
|
|
826 }
|
|
827
|
|
828 /**
|
|
829 * @param selection
|
|
830 * the <code>ISelection</code> to examine.
|
|
831 * @return the first element, or null if empty.
|
|
832 */
|
|
833 protected IPreferenceNode getSingleSelection(ISelection selection) {
|
|
834 if (!selection.isEmpty()) {
|
34
|
835 IStructuredSelection structured = cast(IStructuredSelection) selection;
|
|
836 if (cast(IPreferenceNode)structured.getFirstElement() ) {
|
|
837 return cast(IPreferenceNode) structured.getFirstElement();
|
9
|
838 }
|
|
839 }
|
|
840 return null;
|
|
841 }
|
|
842
|
|
843 /**
|
|
844 * @return the <code>TreeViewer</code> for this dialog.
|
|
845 * @since 3.3
|
|
846 */
|
|
847 public TreeViewer getTreeViewer() {
|
|
848 return treeViewer;
|
|
849 }
|
|
850
|
|
851 /**
|
|
852 * Save the values specified in the pages.
|
|
853 * <p>
|
|
854 * The default implementation of this framework method saves all pages of
|
|
855 * type <code>PreferencePage</code> (if their store needs saving and is a
|
|
856 * <code>PreferenceStore</code>).
|
|
857 * </p>
|
|
858 * <p>
|
|
859 * Subclasses may override.
|
|
860 * </p>
|
|
861 */
|
|
862 protected void handleSave() {
|
34
|
863 foreach( e; preferenceManager.getElements(PreferenceManager.PRE_ORDER)){
|
|
864 IPreferenceNode node = cast(IPreferenceNode) e;
|
9
|
865 IPreferencePage page = node.getPage();
|
34
|
866 if (cast(PreferencePage)page ) {
|
9
|
867 // Save now in case tbe workbench does not shutdown cleanly
|
34
|
868 IPreferenceStore store = (cast(PreferencePage) page).getPreferenceStore();
|
9
|
869 if (store !is null && store.needsSaving()
|
34
|
870 && cast(IPersistentPreferenceStore)store ) {
|
9
|
871 try {
|
34
|
872 (cast(IPersistentPreferenceStore) store).save();
|
9
|
873 } catch (IOException e) {
|
|
874 MessageDialog
|
|
875 .openError(
|
|
876 getShell(),
|
|
877 JFaceResources.getString("PreferenceDialog.saveErrorTitle"), //$NON-NLS-1$
|
|
878 JFaceResources
|
|
879 .format(
|
34
|
880 "PreferenceDialog.saveErrorMessage", [ page.getTitle(), e.msg ])); //$NON-NLS-1$
|
9
|
881 }
|
|
882 }
|
|
883 }
|
|
884 }
|
|
885 }
|
|
886
|
|
887 /**
|
|
888 * Notifies that the window's close button was pressed, the close menu was
|
|
889 * selected, or the ESCAPE key pressed.
|
|
890 * <p>
|
|
891 * The default implementation of this framework method sets the window's
|
|
892 * return code to <code>CANCEL</code> and closes the window using
|
|
893 * <code>close</code>. Subclasses may extend or reimplement.
|
|
894 * </p>
|
|
895 */
|
|
896 protected void handleShellCloseEvent() {
|
|
897 // handle the same as pressing cancel
|
|
898 cancelPressed();
|
|
899 }
|
|
900
|
|
901 /**
|
|
902 * Notifies of the pressing of the Help button.
|
|
903 * <p>
|
|
904 * The default implementation of this framework method calls
|
|
905 * <code>performHelp</code> on the currently active page.
|
|
906 * </p>
|
|
907 */
|
|
908 protected void helpPressed() {
|
|
909 if (currentPage !is null) {
|
|
910 currentPage.performHelp();
|
|
911 }
|
|
912 }
|
|
913
|
|
914 /**
|
|
915 * Returns whether the current page is valid.
|
|
916 *
|
|
917 * @return <code>false</code> if the current page is not valid, or or
|
|
918 * <code>true</code> if the current page is valid or there is no
|
|
919 * current page
|
|
920 */
|
|
921 protected bool isCurrentPageValid() {
|
|
922 if (currentPage is null) {
|
|
923 return true;
|
|
924 }
|
|
925 return currentPage.isValid();
|
|
926 }
|
|
927
|
|
928 /**
|
|
929 * @param control
|
|
930 * the <code>Control</code> to lay out.
|
|
931 * @since 3.0
|
|
932 */
|
|
933 protected void layoutTreeAreaControl(Control control) {
|
|
934 GridData gd = new GridData(GridData.FILL_VERTICAL);
|
|
935 gd.widthHint = getLastRightWidth();
|
|
936 gd.verticalSpan = 1;
|
|
937 control.setLayoutData(gd);
|
|
938 }
|
|
939
|
|
940 /**
|
|
941 * The preference dialog implementation of this <code>Dialog</code>
|
|
942 * framework method sends <code>performOk</code> to all pages of the
|
|
943 * preference dialog, then calls <code>handleSave</code> on this dialog to
|
|
944 * save any state, and then calls <code>close</code> to close this dialog.
|
|
945 */
|
|
946 protected void okPressed() {
|
34
|
947 SafeRunnable.run(new class SafeRunnable {
|
9
|
948 private bool errorOccurred;
|
|
949
|
|
950 /*
|
|
951 * (non-Javadoc)
|
|
952 *
|
|
953 * @see dwtx.core.runtime.ISafeRunnable#run()
|
|
954 */
|
|
955 public void run() {
|
|
956 getButton(IDialogConstants.OK_ID).setEnabled(false);
|
|
957 errorOccurred = false;
|
|
958 bool hasFailedOK = false;
|
|
959 try {
|
|
960 // Notify all the pages and give them a chance to abort
|
34
|
961 foreach( e; preferenceManager.getElements(PreferenceManager.PRE_ORDER)){
|
|
962 IPreferenceNode node = cast(IPreferenceNode) e;
|
9
|
963 IPreferencePage page = node.getPage();
|
|
964 if (page !is null) {
|
|
965 if (!page.performOk()){
|
|
966 hasFailedOK = true;
|
|
967 return;
|
|
968 }
|
|
969 }
|
|
970 }
|
|
971 } catch (Exception e) {
|
|
972 handleException(e);
|
|
973 } finally {
|
|
974 //Don't bother closing if the OK failed
|
|
975 if(hasFailedOK){
|
|
976 setReturnCode(FAILED);
|
|
977 getButton(IDialogConstants.OK_ID).setEnabled(true);
|
34
|
978 //return;
|
9
|
979 }
|
34
|
980 else{
|
9
|
981
|
34
|
982 if (!errorOccurred) {
|
|
983 //Give subclasses the choice to save the state of the
|
|
984 //preference pages.
|
|
985 handleSave();
|
|
986 }
|
|
987 setReturnCode(OK);
|
|
988 close();
|
9
|
989 }
|
|
990 }
|
|
991 }
|
|
992
|
|
993 /*
|
|
994 * (non-Javadoc)
|
|
995 *
|
|
996 * @see dwtx.core.runtime.ISafeRunnable#handleException(java.lang.Throwable)
|
|
997 */
|
34
|
998 public void handleException(Exception e) {
|
9
|
999 errorOccurred = true;
|
|
1000
|
|
1001 Policy.getLog().log(new Status(IStatus.ERROR, Policy.JFACE, 0, e.toString(), e));
|
|
1002
|
|
1003 clearSelectedNode();
|
|
1004 String message = JFaceResources.getString("SafeRunnable.errorMessage"); //$NON-NLS-1$
|
|
1005 MessageDialog.openError(getShell(), JFaceResources.getString("Error"), message); //$NON-NLS-1$
|
|
1006
|
|
1007 }
|
|
1008 });
|
|
1009 }
|
|
1010
|
|
1011 /**
|
|
1012 * Selects the page determined by <code>lastSuccessfulNode</code> in the
|
|
1013 * page hierarchy.
|
|
1014 */
|
|
1015 void selectCurrentPageAgain() {
|
|
1016 if (lastSuccessfulNode is null) {
|
|
1017 return;
|
|
1018 }
|
34
|
1019 getTreeViewer().setSelection(new StructuredSelection(cast(Object)lastSuccessfulNode));
|
9
|
1020 currentPage.setVisible(true);
|
|
1021 }
|
|
1022
|
|
1023 /**
|
|
1024 * Selects the saved item in the tree of preference pages. If it cannot do
|
|
1025 * this it saves the first one.
|
|
1026 */
|
|
1027 protected void selectSavedItem() {
|
|
1028 IPreferenceNode node = findNodeMatching(getSelectedNodePreference());
|
|
1029 if (node is null) {
|
|
1030 IPreferenceNode[] nodes = preferenceManager.getRootSubNodes();
|
|
1031 ViewerFilter[] filters = getTreeViewer().getFilters();
|
|
1032 for (int i = 0; i < nodes.length; i++) {
|
|
1033 IPreferenceNode selectedNode = nodes[i];
|
|
1034 // See if it passes all filters
|
|
1035 for (int j = 0; j < filters.length; j++) {
|
34
|
1036 if (!filters[j].select(this.treeViewer, cast(Object)preferenceManager
|
|
1037 .getRoot_package(), cast(Object)selectedNode)) {
|
9
|
1038 selectedNode = null;
|
|
1039 break;
|
|
1040 }
|
|
1041 }
|
|
1042 // if it passes all filters select it
|
|
1043 if (selectedNode !is null) {
|
|
1044 node = selectedNode;
|
|
1045 break;
|
|
1046 }
|
|
1047 }
|
|
1048 }
|
|
1049 if (node !is null) {
|
34
|
1050 getTreeViewer().setSelection(new StructuredSelection(cast(Object)node), true);
|
9
|
1051 // Keep focus in tree. See bugs 2692, 2621, and 6775.
|
|
1052 getTreeViewer().getControl().setFocus();
|
|
1053 }
|
|
1054 }
|
|
1055
|
|
1056 /**
|
|
1057 * Display the given error message. The currently displayed message is saved
|
|
1058 * and will be redisplayed when the error message is set to
|
|
1059 * <code>null</code>.
|
|
1060 *
|
|
1061 * @param newErrorMessage
|
|
1062 * the errorMessage to display or <code>null</code>
|
|
1063 */
|
|
1064 public void setErrorMessage(String newErrorMessage) {
|
|
1065 if (newErrorMessage is null) {
|
|
1066 messageArea.clearErrorMessage();
|
|
1067 } else {
|
|
1068 messageArea.updateText(newErrorMessage, IMessageProvider.ERROR);
|
|
1069 }
|
|
1070 }
|
|
1071
|
|
1072 /**
|
|
1073 * Save the last known tree width.
|
|
1074 *
|
|
1075 * @param width
|
|
1076 * the width.
|
|
1077 */
|
|
1078 private void setLastTreeWidth(int width) {
|
|
1079 lastTreeWidth = width;
|
|
1080 }
|
|
1081
|
|
1082 /**
|
|
1083 * Set the message text. If the message line currently displays an error,
|
|
1084 * the message is stored and will be shown after a call to clearErrorMessage
|
|
1085 * <p>
|
|
1086 * Shortcut for <code>setMessage(newMessage, NONE)</code>
|
|
1087 * </p>
|
|
1088 *
|
|
1089 * @param newMessage
|
|
1090 * the message, or <code>null</code> to clear the message
|
|
1091 */
|
|
1092 public void setMessage(String newMessage) {
|
|
1093 setMessage(newMessage, IMessageProvider.NONE);
|
|
1094 }
|
|
1095
|
|
1096 /**
|
|
1097 * Sets the message for this dialog with an indication of what type of
|
|
1098 * message it is.
|
|
1099 * <p>
|
|
1100 * The valid message types are one of <code>NONE</code>,
|
|
1101 * <code>INFORMATION</code>,<code>WARNING</code>, or
|
|
1102 * <code>ERROR</code>.
|
|
1103 * </p>
|
|
1104 * <p>
|
|
1105 * Note that for backward compatibility, a message of type
|
|
1106 * <code>ERROR</code> is different than an error message (set using
|
|
1107 * <code>setErrorMessage</code>). An error message overrides the current
|
|
1108 * message until the error message is cleared. This method replaces the
|
|
1109 * current message and does not affect the error message.
|
|
1110 * </p>
|
|
1111 *
|
|
1112 * @param newMessage
|
|
1113 * the message, or <code>null</code> to clear the message
|
|
1114 * @param newType
|
|
1115 * the message type
|
|
1116 * @since 2.0
|
|
1117 */
|
|
1118 public void setMessage(String newMessage, int newType) {
|
|
1119 messageArea.updateText(newMessage, newType);
|
|
1120 }
|
|
1121
|
|
1122 /**
|
|
1123 * Sets the minimum page size.
|
|
1124 *
|
|
1125 * @param minWidth
|
|
1126 * the minimum page width
|
|
1127 * @param minHeight
|
|
1128 * the minimum page height
|
|
1129 * @see #setMinimumPageSize(Point)
|
|
1130 */
|
|
1131 public void setMinimumPageSize(int minWidth, int minHeight) {
|
|
1132 minimumPageSize.x = minWidth;
|
|
1133 minimumPageSize.y = minHeight;
|
|
1134 }
|
|
1135
|
|
1136 /**
|
|
1137 * Sets the minimum page size.
|
|
1138 *
|
|
1139 * @param size
|
|
1140 * the page size encoded as <code>new Point(width,height)</code>
|
|
1141 * @see #setMinimumPageSize(int,int)
|
|
1142 */
|
|
1143 public void setMinimumPageSize(Point size) {
|
|
1144 minimumPageSize.x = size.x;
|
|
1145 minimumPageSize.y = size.y;
|
|
1146 }
|
|
1147
|
|
1148 /**
|
|
1149 * Sets the preference store for this preference dialog.
|
|
1150 *
|
|
1151 * @param store
|
|
1152 * the preference store
|
|
1153 * @see #getPreferenceStore
|
|
1154 */
|
|
1155 public void setPreferenceStore(IPreferenceStore store) {
|
34
|
1156 Assert.isNotNull(cast(Object)store);
|
9
|
1157 preferenceStore = store;
|
|
1158 }
|
|
1159
|
|
1160 /**
|
|
1161 * Save the currently selected node.
|
|
1162 */
|
|
1163 private void setSelectedNode() {
|
|
1164 String storeValue = null;
|
34
|
1165 IStructuredSelection selection = cast(IStructuredSelection) getTreeViewer().getSelection();
|
9
|
1166 if (selection.size() is 1) {
|
34
|
1167 IPreferenceNode node = cast(IPreferenceNode) selection.getFirstElement();
|
9
|
1168 storeValue = node.getId();
|
|
1169 }
|
|
1170 setSelectedNodePreference(storeValue);
|
|
1171 }
|
|
1172
|
|
1173 /**
|
|
1174 * Sets the name of the selected item preference. Public equivalent to
|
|
1175 * <code>setSelectedNodePreference</code>.
|
|
1176 *
|
|
1177 * @param pageId
|
|
1178 * The identifier for the page
|
|
1179 * @since 3.0
|
|
1180 */
|
|
1181 public void setSelectedNode(String pageId) {
|
|
1182 setSelectedNodePreference(pageId);
|
|
1183 }
|
|
1184
|
|
1185 /**
|
|
1186 * Sets the name of the selected item preference.
|
|
1187 *
|
|
1188 * @param pageId
|
|
1189 * The identifier for the page
|
|
1190 */
|
|
1191 protected void setSelectedNodePreference(String pageId) {
|
|
1192 lastPreferenceId = pageId;
|
|
1193 }
|
|
1194
|
|
1195 /**
|
|
1196 * Changes the shell size to the given size, ensuring that it is no larger
|
|
1197 * than the display bounds.
|
|
1198 *
|
|
1199 * @param width
|
|
1200 * the shell width
|
|
1201 * @param height
|
|
1202 * the shell height
|
|
1203 */
|
|
1204 private void setShellSize(int width, int height) {
|
|
1205 Rectangle preferred = getShell().getBounds();
|
|
1206 preferred.width = width;
|
|
1207 preferred.height = height;
|
|
1208 getShell().setBounds(getConstrainedShellBounds(preferred));
|
|
1209 }
|
|
1210
|
|
1211 /**
|
|
1212 * Shows the preference page corresponding to the given preference node.
|
|
1213 * Does nothing if that page is already current.
|
|
1214 *
|
|
1215 * @param node
|
|
1216 * the preference node, or <code>null</code> if none
|
|
1217 * @return <code>true</code> if the page flip was successful, and
|
|
1218 * <code>false</code> is unsuccessful
|
|
1219 */
|
|
1220 protected bool showPage(IPreferenceNode node) {
|
|
1221 if (node is null) {
|
|
1222 return false;
|
|
1223 }
|
|
1224 // Create the page if nessessary
|
|
1225 if (node.getPage() is null) {
|
|
1226 createPage(node);
|
|
1227 }
|
|
1228 if (node.getPage() is null) {
|
|
1229 return false;
|
|
1230 }
|
|
1231 IPreferencePage newPage = getPage(node);
|
|
1232 if (newPage is currentPage) {
|
|
1233 return true;
|
|
1234 }
|
|
1235 if (currentPage !is null) {
|
|
1236 if (!currentPage.okToLeave()) {
|
|
1237 return false;
|
|
1238 }
|
|
1239 }
|
|
1240 IPreferencePage oldPage = currentPage;
|
|
1241 currentPage = newPage;
|
|
1242 // Set the new page's container
|
|
1243 currentPage.setContainer(this);
|
|
1244 // Ensure that the page control has been created
|
|
1245 // (this allows lazy page control creation)
|
|
1246 if (currentPage.getControl() is null) {
|
34
|
1247 bool[1] failed; failed[0] = false;
|
|
1248 SafeRunnable.run(new class ISafeRunnable {
|
|
1249 public void handleException(Exception e) {
|
9
|
1250 failed[0] = true;
|
|
1251 }
|
|
1252
|
|
1253 public void run() {
|
|
1254 createPageControl(currentPage, pageContainer);
|
|
1255 }
|
|
1256 });
|
|
1257 if (failed[0]) {
|
|
1258 return false;
|
|
1259 }
|
|
1260 // the page is responsible for ensuring the created control is
|
|
1261 // accessable
|
|
1262 // via getControl.
|
|
1263 Assert.isNotNull(currentPage.getControl());
|
|
1264 }
|
|
1265 // Force calculation of the page's description label because
|
|
1266 // label can be wrapped.
|
|
1267 final Point[] size = new Point[1];
|
|
1268 final Point failed = new Point(-1, -1);
|
34
|
1269 SafeRunnable.run(new class ISafeRunnable {
|
|
1270 public void handleException(Exception e) {
|
9
|
1271 size[0] = failed;
|
|
1272 }
|
|
1273
|
|
1274 public void run() {
|
|
1275 size[0] = currentPage.computeSize();
|
|
1276 }
|
|
1277 });
|
34
|
1278 if (size[0].opEquals(failed)) {
|
9
|
1279 return false;
|
|
1280 }
|
|
1281 Point contentSize = size[0];
|
|
1282 // Do we need resizing. Computation not needed if the
|
|
1283 // first page is inserted since computing the dialog's
|
|
1284 // size is done by calling dialog.open().
|
|
1285 // Also prevent auto resize if the user has manually resized
|
|
1286 Shell shell = getShell();
|
|
1287 Point shellSize = shell.getSize();
|
|
1288 if (oldPage !is null) {
|
|
1289 Rectangle rect = pageContainer.getClientArea();
|
|
1290 Point containerSize = new Point(rect.width, rect.height);
|
|
1291 int hdiff = contentSize.x - containerSize.x;
|
|
1292 int vdiff = contentSize.y - containerSize.y;
|
34
|
1293 if ((hdiff > 0 || vdiff > 0) && shellSize.opEquals(lastShellSize)) {
|
9
|
1294 hdiff = Math.max(0, hdiff);
|
|
1295 vdiff = Math.max(0, vdiff);
|
|
1296 setShellSize(shellSize.x + hdiff, shellSize.y + vdiff);
|
|
1297 lastShellSize = shell.getSize();
|
|
1298 if (currentPage.getControl().getSize().x is 0) {
|
|
1299 currentPage.getControl().setSize(containerSize);
|
|
1300 }
|
|
1301
|
|
1302 } else {
|
|
1303 currentPage.setSize(containerSize);
|
|
1304 }
|
|
1305 }
|
|
1306
|
|
1307 scrolled.setMinSize(contentSize);
|
|
1308 // Ensure that all other pages are invisible
|
|
1309 // (including ones that triggered an exception during
|
|
1310 // their creation).
|
|
1311 Control[] children = pageContainer.getChildren();
|
|
1312 Control currentControl = currentPage.getControl();
|
|
1313 for (int i = 0; i < children.length; i++) {
|
|
1314 if (children[i] !is currentControl) {
|
|
1315 children[i].setVisible(false);
|
|
1316 }
|
|
1317 }
|
|
1318 // Make the new page visible
|
|
1319 currentPage.setVisible(true);
|
|
1320 if (oldPage !is null) {
|
|
1321 oldPage.setVisible(false);
|
|
1322 }
|
|
1323 // update the dialog controls
|
|
1324 update();
|
|
1325 return true;
|
|
1326 }
|
|
1327
|
|
1328 /**
|
|
1329 * Create the page for the node.
|
|
1330 * @param node
|
|
1331 *
|
|
1332 * @since 3.1
|
|
1333 */
|
|
1334 protected void createPage(IPreferenceNode node) {
|
|
1335 node.createPage();
|
|
1336 }
|
|
1337
|
|
1338 /**
|
|
1339 * Get the page for the node.
|
|
1340 * @param node
|
|
1341 * @return IPreferencePage
|
|
1342 *
|
|
1343 * @since 3.1
|
|
1344 */
|
|
1345 protected IPreferencePage getPage(IPreferenceNode node) {
|
|
1346 return node.getPage();
|
|
1347 }
|
|
1348
|
|
1349 /**
|
|
1350 * Shows the "Page Flipping abort" dialog.
|
|
1351 */
|
|
1352 void showPageFlippingAbortDialog() {
|
|
1353 MessageDialog.openError(getShell(), JFaceResources
|
|
1354 .getString("AbortPageFlippingDialog.title"), //$NON-NLS-1$
|
|
1355 JFaceResources.getString("AbortPageFlippingDialog.message")); //$NON-NLS-1$
|
|
1356 }
|
|
1357
|
|
1358 /**
|
|
1359 * Updates this dialog's controls to reflect the current page.
|
|
1360 */
|
|
1361 protected void update() {
|
|
1362 // Update the title bar
|
|
1363 updateTitle();
|
|
1364 // Update the message line
|
|
1365 updateMessage();
|
|
1366 // Update the buttons
|
|
1367 updateButtons();
|
|
1368 //Saved the selected node in the preferences
|
|
1369 setSelectedNode();
|
34
|
1370 firePageChanged(new PageChangedEvent(this, cast(Object)getCurrentPage()));
|
9
|
1371 }
|
|
1372
|
|
1373 /*
|
|
1374 * (non-Javadoc)
|
|
1375 *
|
|
1376 * @see dwtx.jface.preference.IPreferencePageContainer#updateButtons()
|
|
1377 */
|
|
1378 public void updateButtons() {
|
|
1379 okButton.setEnabled(isCurrentPageValid());
|
|
1380 }
|
|
1381
|
|
1382 /*
|
|
1383 * (non-Javadoc)
|
|
1384 *
|
|
1385 * @see dwtx.jface.preference.IPreferencePageContainer#updateMessage()
|
|
1386 */
|
|
1387 public void updateMessage() {
|
|
1388 String message = null;
|
|
1389 String errorMessage = null;
|
|
1390 if(currentPage !is null){
|
|
1391 message = currentPage.getMessage();
|
|
1392 errorMessage = currentPage.getErrorMessage();
|
|
1393 }
|
|
1394 int messageType = IMessageProvider.NONE;
|
34
|
1395 if (message !is null && cast(IMessageProvider)currentPage ) {
|
|
1396 messageType = (cast(IMessageProvider) currentPage).getMessageType();
|
9
|
1397 }
|
|
1398
|
|
1399 if (errorMessage is null){
|
|
1400 if (showingError) {
|
|
1401 // we were previously showing an error
|
|
1402 showingError = false;
|
|
1403 }
|
|
1404 }
|
|
1405 else {
|
|
1406 message = errorMessage;
|
|
1407 messageType = IMessageProvider.ERROR;
|
|
1408 if (!showingError) {
|
|
1409 // we were not previously showing an error
|
|
1410 showingError = true;
|
|
1411 }
|
|
1412 }
|
|
1413 messageArea.updateText(message,messageType);
|
|
1414 }
|
|
1415
|
|
1416 /*
|
|
1417 * (non-Javadoc)
|
|
1418 *
|
|
1419 * @see dwtx.jface.preference.IPreferencePageContainer#updateTitle()
|
|
1420 */
|
|
1421 public void updateTitle() {
|
|
1422 if(currentPage is null) {
|
|
1423 return;
|
|
1424 }
|
|
1425 messageArea.showTitle(currentPage.getTitle(), currentPage.getImage());
|
|
1426 }
|
|
1427
|
|
1428 /**
|
|
1429 * Update the tree to use the specified <code>Font</code>.
|
|
1430 *
|
|
1431 * @param dialogFont
|
|
1432 * the <code>Font</code> to use.
|
|
1433 * @since 3.0
|
|
1434 */
|
|
1435 protected void updateTreeFont(Font dialogFont) {
|
|
1436 getTreeViewer().getControl().setFont(dialogFont);
|
|
1437 }
|
|
1438
|
|
1439 /**
|
|
1440 * Returns the currentPage.
|
|
1441 * @return IPreferencePage
|
|
1442 * @since 3.1
|
|
1443 */
|
|
1444 protected IPreferencePage getCurrentPage() {
|
|
1445 return currentPage;
|
|
1446 }
|
|
1447
|
|
1448 /**
|
|
1449 * Sets the current page.
|
|
1450 * @param currentPage
|
|
1451 *
|
|
1452 * @since 3.1
|
|
1453 */
|
|
1454 protected void setCurrentPage(IPreferencePage currentPage) {
|
|
1455 this.currentPage = currentPage;
|
|
1456 }
|
|
1457
|
|
1458 /**
|
|
1459 * Set the treeViewer.
|
|
1460 * @param treeViewer
|
|
1461 *
|
|
1462 * @since 3.1
|
|
1463 */
|
|
1464 protected void setTreeViewer(TreeViewer treeViewer) {
|
|
1465 this.treeViewer = treeViewer;
|
|
1466 }
|
|
1467
|
|
1468 /**
|
|
1469 * Get the composite that is showing the page.
|
|
1470 *
|
|
1471 * @return Composite.
|
|
1472 *
|
|
1473 * @since 3.1
|
|
1474 */
|
|
1475 protected Composite getPageContainer() {
|
|
1476 return this.pageContainer;
|
|
1477 }
|
|
1478
|
|
1479 /**
|
|
1480 * Set the composite that is showing the page.
|
|
1481 * @param pageContainer Composite
|
|
1482 *
|
|
1483 * @since 3.1
|
|
1484 */
|
|
1485 protected void setPageContainer(Composite pageContainer) {
|
|
1486 this.pageContainer = pageContainer;
|
|
1487 }
|
|
1488 /**
|
|
1489 * Create the page control for the supplied page.
|
|
1490 *
|
|
1491 * @param page - the preference page to be shown
|
|
1492 * @param parent - the composite to parent the page
|
|
1493 *
|
|
1494 * @since 3.1
|
|
1495 */
|
|
1496 protected void createPageControl(IPreferencePage page, Composite parent) {
|
|
1497 page.createControl(parent);
|
|
1498 }
|
|
1499
|
|
1500 /**
|
|
1501 * @see dwtx.jface.dialogs.IPageChangeProvider#getSelectedPage()
|
|
1502 *
|
|
1503 * @since 3.1
|
|
1504 */
|
|
1505 public Object getSelectedPage() {
|
34
|
1506 return cast(Object)getCurrentPage();
|
9
|
1507 }
|
|
1508
|
|
1509 /**
|
|
1510 * @see dwtx.jface.dialogs.IPageChangeProvider#addPageChangedListener(dwtx.jface.dialogs.IPageChangedListener)
|
|
1511 * @since 3.1
|
|
1512 */
|
|
1513 public void addPageChangedListener(IPageChangedListener listener) {
|
34
|
1514 pageChangedListeners.add(cast(Object)listener);
|
9
|
1515 }
|
|
1516
|
|
1517 /**
|
|
1518 * @see dwtx.jface.dialogs.IPageChangeProvider#removePageChangedListener(dwtx.jface.dialogs.IPageChangedListener)
|
|
1519 * @since 3.1
|
|
1520 */
|
|
1521 public void removePageChangedListener(IPageChangedListener listener) {
|
34
|
1522 pageChangedListeners.remove(cast(Object)listener);
|
9
|
1523
|
|
1524 }
|
|
1525
|
|
1526 /**
|
|
1527 * Notifies any selection changed listeners that the selected page
|
|
1528 * has changed.
|
|
1529 * Only listeners registered at the time this method is called are notified.
|
|
1530 *
|
|
1531 * @param event a selection changed event
|
|
1532 *
|
|
1533 * @see IPageChangedListener#pageChanged
|
|
1534 *
|
|
1535 * @since 3.1
|
|
1536 */
|
34
|
1537 protected void firePageChanged(PageChangedEvent event) {
|
9
|
1538 Object[] listeners = pageChangedListeners.getListeners();
|
|
1539 for (int i = 0; i < listeners.length; i++) {
|
34
|
1540 SafeRunnable.run(new class SafeRunnable {
|
|
1541 PageChangedEvent event_;
|
|
1542 IPageChangedListener l;
|
|
1543 this(){
|
|
1544 event_=event;
|
|
1545 l = cast(IPageChangedListener) listeners[i];
|
|
1546 }
|
9
|
1547 public void run() {
|
34
|
1548 l.pageChanged(event_);
|
9
|
1549 }
|
|
1550 });
|
|
1551 }
|
|
1552 }
|
|
1553 }
|