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