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