comparison dwtx/jface/preference/PreferenceDialog.d @ 34:b3c8e32d406f

preference
author Frank Benoit <benoit@tionex.de>
date Sat, 05 Apr 2008 01:45:47 +0200
parents 6c14e54dfc11
children 644f1334b451
comparison
equal deleted inserted replaced
33:f25582573129 34:b3c8e32d406f
12 * Port to the D programming language: 12 * Port to the D programming language:
13 * Frank Benoit <benoit@tionex.de> 13 * Frank Benoit <benoit@tionex.de>
14 *******************************************************************************/ 14 *******************************************************************************/
15 module dwtx.jface.preference.PreferenceDialog; 15 module dwtx.jface.preference.PreferenceDialog;
16 16
17 import dwt.dwthelper.utils; 17 import dwtx.jface.preference.IPreferencePageContainer;
18 18 import dwtx.jface.preference.IPreferencePage;
19 pragma( msg, "FIXME dwtx.jface.preference.PreferenceDialog" ); 19 import dwtx.jface.preference.IPreferenceNode;
20 class PreferenceDialog{ 20 import dwtx.jface.preference.IPreferenceStore;
21 public static const String PREF_DLG_TITLE_IMG = "preference_dialog_title_image"; //$NON-NLS-1$ 21 import dwtx.jface.preference.IPersistentPreferenceStore;
22 } 22 import dwtx.jface.preference.PreferenceManager;
23 23 import dwtx.jface.preference.PreferencePage;
24 /++ 24 import dwtx.jface.preference.PreferenceLabelProvider;
25 import java.io.IOException; 25 import dwtx.jface.preference.PreferenceContentProvider;
26 import java.util.Iterator;
27 import java.util.List;
28 26
29 import dwt.DWT; 27 import dwt.DWT;
30 import dwt.custom.BusyIndicator; 28 import dwt.custom.BusyIndicator;
31 import dwt.custom.ScrolledComposite; 29 import dwt.custom.ScrolledComposite;
32 import dwt.events.ControlAdapter; 30 import dwt.events.ControlAdapter;
82 import dwtx.jface.viewers.SelectionChangedEvent; 80 import dwtx.jface.viewers.SelectionChangedEvent;
83 import dwtx.jface.viewers.StructuredSelection; 81 import dwtx.jface.viewers.StructuredSelection;
84 import dwtx.jface.viewers.TreeViewer; 82 import dwtx.jface.viewers.TreeViewer;
85 import dwtx.jface.viewers.ViewerFilter; 83 import dwtx.jface.viewers.ViewerFilter;
86 84
85 import dwt.dwthelper.utils;
86 import dwt.dwthelper.Runnable;
87
87 /** 88 /**
88 * A preference dialog is a hierarchical presentation of preference pages. Each 89 * A preference dialog is a hierarchical presentation of preference pages. Each
89 * page is represented by a node in the tree shown on the left hand side of the 90 * page is represented by a node in the tree shown on the left hand side of the
90 * dialog; when a node is selected, the corresponding page is shown on the right 91 * dialog; when a node is selected, the corresponding page is shown on the right
91 * hand side. 92 * hand side.
92 */ 93 */
93 public class PreferenceDialog extends TrayDialog implements IPreferencePageContainer, IPageChangeProvider { 94 public class PreferenceDialog : TrayDialog, IPreferencePageContainer, IPageChangeProvider {
94 /** 95 /**
95 * Layout for the page container. 96 * Layout for the page container.
96 * 97 *
97 */ 98 */
98 private class PageLayout extends Layout { 99 private class PageLayout : Layout {
99 public Point computeSize(Composite composite, int wHint, int hHint, bool force) { 100 public Point computeSize(Composite composite, int wHint, int hHint, bool force) {
100 if (wHint !is DWT.DEFAULT && hHint !is DWT.DEFAULT) { 101 if (wHint !is DWT.DEFAULT && hHint !is DWT.DEFAULT) {
101 return new Point(wHint, hHint); 102 return new Point(wHint, hHint);
102 } 103 }
103 int x = minimumPageSize.x; 104 int x = minimumPageSize.x;
142 private static int lastTreeWidth = 180; 143 private static int lastTreeWidth = 180;
143 144
144 /** 145 /**
145 * Indentifier for the error image 146 * Indentifier for the error image
146 */ 147 */
147 public static final String PREF_DLG_IMG_TITLE_ERROR = DLG_IMG_MESSAGE_ERROR; 148 public static const String PREF_DLG_IMG_TITLE_ERROR = DLG_IMG_MESSAGE_ERROR;
148 149
149 /** 150 /**
150 * Title area fields 151 * Title area fields
151 */ 152 */
152 public static final String PREF_DLG_TITLE_IMG = "preference_dialog_title_image"; //$NON-NLS-1$ 153 public static const String PREF_DLG_TITLE_IMG = "preference_dialog_title_image"; //$NON-NLS-1$
153 154
154 /** 155 /**
155 * Return code used when dialog failed 156 * Return code used when dialog failed
156 */ 157 */
157 protected static final int FAILED = 2; 158 protected static const int FAILED = 2;
158 159
159 /** 160 /**
160 * The current preference page, or <code>null</code> if there is none. 161 * The current preference page, or <code>null</code> if there is none.
161 */ 162 */
162 private IPreferencePage currentPage; 163 private IPreferencePage currentPage;
170 /** 171 /**
171 * The minimum page size; 400 by 400 by default. 172 * The minimum page size; 400 by 400 by default.
172 * 173 *
173 * @see #setMinimumPageSize(Point) 174 * @see #setMinimumPageSize(Point)
174 */ 175 */
175 private Point minimumPageSize = new Point(400, 400); 176 private Point minimumPageSize;
176 177
177 /** 178 /**
178 * The OK button. 179 * The OK button.
179 */ 180 */
180 private Button okButton; 181 private Button okButton;
206 /** 207 /**
207 * The tree viewer. 208 * The tree viewer.
208 */ 209 */
209 private TreeViewer treeViewer; 210 private TreeViewer treeViewer;
210 211
211 private ListenerList pageChangedListeners = new ListenerList(); 212 private ListenerList pageChangedListeners;
212 213
213 /** 214 /**
214 * Composite with a FormLayout to contain the title area 215 * Composite with a FormLayout to contain the title area
215 */ 216 */
216 Composite formTitleComposite; 217 Composite formTitleComposite;
224 * @param parentShell 225 * @param parentShell
225 * the parent shell 226 * the parent shell
226 * @param manager 227 * @param manager
227 * the preference manager 228 * the preference manager
228 */ 229 */
229 public PreferenceDialog(Shell parentShell, PreferenceManager manager) { 230 public this(Shell parentShell, PreferenceManager manager) {
231 minimumPageSize = new Point(400, 400);
232 pageChangedListeners = new ListenerList();
230 super(parentShell); 233 super(parentShell);
231 setShellStyle(getShellStyle() | DWT.RESIZE | DWT.MAX); 234 setShellStyle(getShellStyle() | DWT.RESIZE | DWT.MAX);
232 preferenceManager = manager; 235 preferenceManager = manager;
233 } 236 }
234 237
259 * 262 *
260 * @see dwtx.jface.dialogs.Dialog#cancelPressed() 263 * @see dwtx.jface.dialogs.Dialog#cancelPressed()
261 */ 264 */
262 protected void cancelPressed() { 265 protected void cancelPressed() {
263 // Inform all pages that we are cancelling 266 // Inform all pages that we are cancelling
264 Iterator nodes = preferenceManager.getElements(PreferenceManager.PRE_ORDER).iterator(); 267 foreach( e; preferenceManager.getElements(PreferenceManager.PRE_ORDER)){
265 while (nodes.hasNext()) { 268 IPreferenceNode node = cast(IPreferenceNode) e;
266 final IPreferenceNode node = (IPreferenceNode) nodes.next();
267 if (getPage(node) !is null) { 269 if (getPage(node) !is null) {
268 SafeRunnable.run(new SafeRunnable() { 270
271 // this_: strange workaround for compiler error with dmd 1.028 in run()
272 SafeRunnable.run(new class(this) SafeRunnable {
273 PreferenceDialog this_;
274 IPreferenceNode node_;
275 this(PreferenceDialog outer_){
276 node_=node;
277 this_=outer_;
278 auto p = this_.getPage( node );
279 }
269 public void run() { 280 public void run() {
270 if (!getPage(node).performCancel()) { 281 if (!this_.getPage(node_).performCancel()) {
271 return; 282 return;
272 } 283 }
273 } 284 }
274 }); 285 });
275 } 286 }
292 * @see dwtx.jface.window.Window#close() 303 * @see dwtx.jface.window.Window#close()
293 */ 304 */
294 public bool close() { 305 public bool close() {
295 306
296 //Do this is in a SafeRunnable as it may run client code 307 //Do this is in a SafeRunnable as it may run client code
297 SafeRunnable runnable = new SafeRunnable(){ 308 SafeRunnable runnable = new class SafeRunnable{
298 /* (non-Javadoc) 309 /* (non-Javadoc)
299 * @see dwtx.core.runtime.ISafeRunnable#run() 310 * @see dwtx.core.runtime.ISafeRunnable#run()
300 */ 311 */
301 public void run() throws Exception { 312 public void run() {
302 List nodes = preferenceManager.getElements(PreferenceManager.PRE_ORDER); 313 auto nodes = preferenceManager.getElements(PreferenceManager.PRE_ORDER);
303 for (int i = 0; i < nodes.size(); i++) { 314 for (int i = 0; i < nodes.size(); i++) {
304 IPreferenceNode node = (IPreferenceNode) nodes.get(i); 315 IPreferenceNode node = cast(IPreferenceNode) nodes.get(i);
305 node.disposeResources(); 316 node.disposeResources();
306 } 317 }
307 318
308 } 319 }
309 320
310 /* (non-Javadoc) 321 /* (non-Javadoc)
311 * @see dwtx.jface.util.SafeRunnable#handleException(java.lang.Throwable) 322 * @see dwtx.jface.util.SafeRunnable#handleException(java.lang.Throwable)
312 */ 323 */
313 public void handleException(Throwable e) { 324 public void handleException(Exception e) {
314 super.handleException(e); 325 super.handleException(e);
315 clearSelectedNode();//Do not cache a node with problems 326 clearSelectedNode();//Do not cache a node with problems
316 } 327 }
317 }; 328 };
318 329
327 * @see dwtx.jface.window.Window#configureShell(dwt.widgets.Shell) 338 * @see dwtx.jface.window.Window#configureShell(dwt.widgets.Shell)
328 */ 339 */
329 protected void configureShell(Shell newShell) { 340 protected void configureShell(Shell newShell) {
330 super.configureShell(newShell); 341 super.configureShell(newShell);
331 newShell.setText(JFaceResources.getString("PreferenceDialog.title")); //$NON-NLS-1$ 342 newShell.setText(JFaceResources.getString("PreferenceDialog.title")); //$NON-NLS-1$
332 newShell.addShellListener(new ShellAdapter() { 343 newShell.addShellListener(new class ShellAdapter {
333 public void shellActivated(ShellEvent e) { 344 public void shellActivated(ShellEvent e) {
334 if (lastShellSize is null) { 345 if (lastShellSize is null) {
335 lastShellSize = getShell().getSize(); 346 lastShellSize = getShell().getSize();
336 } 347 }
337 } 348 }
368 /* 379 /*
369 * (non-Javadoc) 380 * (non-Javadoc)
370 * 381 *
371 * @see dwtx.jface.window.Window#createContents(dwt.widgets.Composite) 382 * @see dwtx.jface.window.Window#createContents(dwt.widgets.Composite)
372 */ 383 */
373 protected Control createContents(final Composite parent) { 384 protected Control createContents(Composite parent) {
374 final Control[] control = new Control[1]; 385 Control[1] control;
375 BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() { 386 BusyIndicator.showWhile(getShell().getDisplay(), new class Runnable {
387 Composite parent_;
388 this(){
389 parent_=parent;
390 }
376 public void run() { 391 public void run() {
377 control[0] = PreferenceDialog.super.createContents(parent); 392 control[0] = callSuperCreateContents(parent);
378 // Add the first page 393 // Add the first page
379 selectSavedItem(); 394 selectSavedItem();
380 } 395 }
381 }); 396 });
382 397
383 return control[0]; 398 return control[0];
384 } 399 }
385 400 private Control callSuperCreateContents( Composite c ){
401 return super.createContents( c );
402 }
386 /* 403 /*
387 * (non-Javadoc) 404 * (non-Javadoc)
388 * 405 *
389 * @see dwtx.jface.dialogs.Dialog#createDialogArea(dwt.widgets.Composite) 406 * @see dwtx.jface.dialogs.Dialog#createDialogArea(dwt.widgets.Composite)
390 */ 407 */
391 protected Control createDialogArea(Composite parent) { 408 protected Control createDialogArea(Composite parent) {
392 final Composite composite = (Composite) super.createDialogArea(parent); 409 final Composite composite = cast(Composite) super.createDialogArea(parent);
393 GridLayout parentLayout = ((GridLayout) composite.getLayout()); 410 GridLayout parentLayout = (cast(GridLayout) composite.getLayout());
394 parentLayout.numColumns = 4; 411 parentLayout.numColumns = 4;
395 parentLayout.marginHeight = 0; 412 parentLayout.marginHeight = 0;
396 parentLayout.marginWidth = 0; 413 parentLayout.marginWidth = 0;
397 parentLayout.verticalSpacing = 0; 414 parentLayout.verticalSpacing = 0;
398 parentLayout.horizontalSpacing = 0; 415 parentLayout.horizontalSpacing = 0;
468 * @param rightControl 485 * @param rightControl
469 * @return Sash 486 * @return Sash
470 * 487 *
471 * @since 3.1 488 * @since 3.1
472 */ 489 */
473 protected Sash createSash(final Composite composite, final Control rightControl) { 490 protected Sash createSash(Composite composite, Control rightControl) {
474 final Sash sash = new Sash(composite, DWT.VERTICAL); 491 Sash sash = new Sash(composite, DWT.VERTICAL);
475 sash.setLayoutData(new GridData(GridData.FILL_VERTICAL)); 492 sash.setLayoutData(new GridData(GridData.FILL_VERTICAL));
476 sash.setBackground(composite.getDisplay().getSystemColor(DWT.COLOR_LIST_BACKGROUND)); 493 sash.setBackground(composite.getDisplay().getSystemColor(DWT.COLOR_LIST_BACKGROUND));
477 // the following listener resizes the tree control based on sash deltas. 494 // the following listener resizes the tree control based on sash deltas.
478 // If necessary, it will also grow/shrink the dialog. 495 // If necessary, it will also grow/shrink the dialog.
479 sash.addListener(DWT.Selection, new Listener() { 496 sash.addListener(DWT.Selection, new class Listener {
497 Composite composite_;
498 Control rightControl_;
499 Sash sash_;
500 this(){
501 composite_=composite;
502 rightControl_=rightControl;
503 sash_=sash;
504 }
480 /* 505 /*
481 * (non-Javadoc) 506 * (non-Javadoc)
482 * 507 *
483 * @see dwt.widgets.Listener#handleEvent(dwt.widgets.Event) 508 * @see dwt.widgets.Listener#handleEvent(dwt.widgets.Event)
484 */ 509 */
485 public void handleEvent(Event event) { 510 public void handleEvent(Event event) {
486 if (event.detail is DWT.DRAG) { 511 if (event.detail is DWT.DRAG) {
487 return; 512 return;
488 } 513 }
489 int shift = event.x - sash.getBounds().x; 514 int shift = event.x - sash_.getBounds().x;
490 GridData data = (GridData) rightControl.getLayoutData(); 515 GridData data = cast(GridData) rightControl_.getLayoutData();
491 int newWidthHint = data.widthHint + shift; 516 int newWidthHint = data.widthHint + shift;
492 if (newWidthHint < 20) { 517 if (newWidthHint < 20) {
493 return; 518 return;
494 } 519 }
495 Point computedSize = getShell().computeSize(DWT.DEFAULT, DWT.DEFAULT); 520 Point computedSize = getShell().computeSize(DWT.DEFAULT, DWT.DEFAULT);
496 Point currentSize = getShell().getSize(); 521 Point currentSize = getShell().getSize();
497 // if the dialog wasn't of a custom size we know we can shrink 522 // if the dialog wasn't of a custom size we know we can shrink
498 // it if necessary based on sash movement. 523 // it if necessary based on sash movement.
499 bool customSize = !computedSize.equals(currentSize); 524 bool customSize = !computedSize.opEquals(currentSize);
500 data.widthHint = newWidthHint; 525 data.widthHint = newWidthHint;
501 setLastTreeWidth(newWidthHint); 526 setLastTreeWidth(newWidthHint);
502 composite.layout(true); 527 composite_.layout(true);
503 // recompute based on new widget size 528 // recompute based on new widget size
504 computedSize = getShell().computeSize(DWT.DEFAULT, DWT.DEFAULT); 529 computedSize = getShell().computeSize(DWT.DEFAULT, DWT.DEFAULT);
505 // if the dialog was of a custom size then increase it only if 530 // if the dialog was of a custom size then increase it only if
506 // necessary. 531 // necessary.
507 if (customSize) { 532 if (customSize) {
508 computedSize.x = Math.max(computedSize.x, currentSize.x); 533 computedSize.x = Math.max(computedSize.x, currentSize.x);
509 } 534 }
510 computedSize.y = Math.max(computedSize.y, currentSize.y); 535 computedSize.y = Math.max(computedSize.y, currentSize.y);
511 if (computedSize.equals(currentSize)) { 536 if (computedSize.opEquals(currentSize)) {
512 return; 537 return;
513 } 538 }
514 setShellSize(computedSize.x, computedSize.y); 539 setShellSize(computedSize.x, computedSize.y);
515 lastShellSize = getShell().getSize(); 540 lastShellSize = getShell().getSize();
516 } 541 }
594 619
595 // Message label 620 // Message label
596 messageArea = new DialogMessageArea(); 621 messageArea = new DialogMessageArea();
597 messageArea.createContents(titleArea); 622 messageArea.createContents(titleArea);
598 623
599 titleArea.addControlListener(new ControlAdapter() { 624 titleArea.addControlListener(new class ControlAdapter {
600 /* (non-Javadoc) 625 /* (non-Javadoc)
601 * @see dwt.events.ControlAdapter#controlResized(dwt.events.ControlEvent) 626 * @see dwt.events.ControlAdapter#controlResized(dwt.events.ControlEvent)
602 */ 627 */
603 public void controlResized(ControlEvent e) { 628 public void controlResized(ControlEvent e) {
604 updateMessage(); 629 updateMessage();
605 } 630 }
606 }); 631 });
607 632
608 final IPropertyChangeListener fontListener = new IPropertyChangeListener() { 633 final IPropertyChangeListener fontListener = new class IPropertyChangeListener {
609 public void propertyChange(PropertyChangeEvent event) { 634 public void propertyChange(PropertyChangeEvent event) {
610 if (JFaceResources.BANNER_FONT.equals(event.getProperty())) { 635 if (JFaceResources.BANNER_FONT.equals(event.getProperty())) {
611 updateMessage(); 636 updateMessage();
612 } 637 }
613 if (JFaceResources.DIALOG_FONT.equals(event.getProperty())) { 638 if (JFaceResources.DIALOG_FONT.equals(event.getProperty())) {
614 updateMessage(); 639 updateMessage();
615 Font dialogFont = JFaceResources.getDialogFont(); 640 Font dialogFont = JFaceResources.getDialogFont();
616 updateTreeFont(dialogFont); 641 updateTreeFont(dialogFont);
617 Control[] children = ((Composite) buttonBar).getChildren(); 642 Control[] children = (cast(Composite) buttonBar).getChildren();
618 for (int i = 0; i < children.length; i++) { 643 for (int i = 0; i < children.length; i++) {
619 children[i].setFont(dialogFont); 644 children[i].setFont(dialogFont);
620 } 645 }
621 } 646 }
622 } 647 }
623 }; 648 };
624 649
625 titleArea.addDisposeListener(new DisposeListener() { 650 titleArea.addDisposeListener(new class DisposeListener {
626 public void widgetDisposed(DisposeEvent event) { 651 public void widgetDisposed(DisposeEvent event) {
627 JFaceResources.getFontRegistry().removeListener(fontListener); 652 JFaceResources.getFontRegistry().removeListener(fontListener);
628 } 653 }
629 }); 654 });
630 JFaceResources.getFontRegistry().addListener(fontListener); 655 JFaceResources.getFontRegistry().addListener(fontListener);
682 * Add the listeners to the tree viewer. 707 * Add the listeners to the tree viewer.
683 * @param viewer 708 * @param viewer
684 * 709 *
685 * @since 3.1 710 * @since 3.1
686 */ 711 */
687 protected void addListeners(final TreeViewer viewer) { 712 protected void addListeners(TreeViewer viewer) {
688 viewer.addPostSelectionChangedListener(new ISelectionChangedListener() { 713 viewer.addPostSelectionChangedListener(new class ISelectionChangedListener {
714 TreeViewer viewer_;
715 this(){
716 viewer_=viewer;
717 }
689 private void handleError() { 718 private void handleError() {
690 try { 719 try {
691 // remove the listener temporarily so that the events caused 720 // remove the listener temporarily so that the events caused
692 // by the error handling dont further cause error handling 721 // by the error handling dont further cause error handling
693 // to occur. 722 // to occur.
694 viewer.removePostSelectionChangedListener(this); 723 viewer_.removePostSelectionChangedListener(this);
695 showPageFlippingAbortDialog(); 724 showPageFlippingAbortDialog();
696 selectCurrentPageAgain(); 725 selectCurrentPageAgain();
697 clearSelectedNode(); 726 clearSelectedNode();
698 } finally { 727 } finally {
699 viewer.addPostSelectionChangedListener(this); 728 viewer_.addPostSelectionChangedListener(this);
700 } 729 }
701 } 730 }
702 731
703 public void selectionChanged(SelectionChangedEvent event) { 732 public void selectionChanged(SelectionChangedEvent event) {
704 Object selection = getSingleSelection(event.getSelection()); 733 Object selection = cast(Object) getSingleSelection(event.getSelection());
705 if (selection instanceof IPreferenceNode) { 734 if (cast(IPreferenceNode)selection ) {
706 if (!isCurrentPageValid()) { 735 if (!isCurrentPageValid()) {
707 handleError(); 736 handleError();
708 } else if (!showPage((IPreferenceNode) selection)) { 737 } else if (!showPage(cast(IPreferenceNode) selection)) {
709 // Page flipping wasn't successful 738 // Page flipping wasn't successful
710 handleError(); 739 handleError();
711 } else { 740 } else {
712 // Everything went well 741 // Everything went well
713 lastSuccessfulNode = (IPreferenceNode) selection; 742 lastSuccessfulNode = cast(IPreferenceNode) selection;
714 } 743 }
715 } 744 }
716 } 745 }
717 }); 746 });
718 ((Tree) viewer.getControl()).addSelectionListener(new SelectionAdapter() { 747 (cast(Tree) viewer.getControl()).addSelectionListener(new class SelectionAdapter {
719 public void widgetDefaultSelected(final SelectionEvent event) { 748 TreeViewer viewer_;
720 ISelection selection = viewer.getSelection(); 749 this(){
750 viewer_=viewer;
751 }
752 public void widgetDefaultSelected(SelectionEvent event) {
753 ISelection selection = viewer_.getSelection();
721 if (selection.isEmpty()) { 754 if (selection.isEmpty()) {
722 return; 755 return;
723 } 756 }
724 IPreferenceNode singleSelection = getSingleSelection(selection); 757 IPreferenceNode singleSelection = getSingleSelection(selection);
725 bool expanded = viewer.getExpandedState(singleSelection); 758 bool expanded = viewer_.getExpandedState(cast(Object)singleSelection);
726 viewer.setExpandedState(singleSelection, !expanded); 759 viewer_.setExpandedState(cast(Object)singleSelection, !expanded);
727 } 760 }
728 }); 761 });
729 //Register help listener on the tree to use context sensitive help 762 //Register help listener on the tree to use context sensitive help
730 viewer.getControl().addHelpListener(new HelpListener() { 763 viewer.getControl().addHelpListener(new class HelpListener {
731 public void helpRequested(HelpEvent event) { 764 public void helpRequested(HelpEvent event) {
732 // call perform help on the current page 765 // call perform help on the current page
733 if (currentPage !is null) { 766 if (currentPage !is null) {
734 currentPage.performHelp(); 767 currentPage.performHelp();
735 } 768 }
745 * the id to search for. 778 * the id to search for.
746 * @return <code>IPreferenceNode</code> or <code>null</code> if not 779 * @return <code>IPreferenceNode</code> or <code>null</code> if not
747 * found. 780 * found.
748 */ 781 */
749 protected IPreferenceNode findNodeMatching(String nodeId) { 782 protected IPreferenceNode findNodeMatching(String nodeId) {
750 List nodes = preferenceManager.getElements(PreferenceManager.POST_ORDER); 783 foreach( e; preferenceManager.getElements(PreferenceManager.POST_ORDER)){
751 for (Iterator i = nodes.iterator(); i.hasNext();) { 784 IPreferenceNode node = cast(IPreferenceNode) e;
752 IPreferenceNode node = (IPreferenceNode) i.next();
753 if (node.getId().equals(nodeId)) { 785 if (node.getId().equals(nodeId)) {
754 return node; 786 return node;
755 } 787 }
756 } 788 }
757 return null; 789 return null;
798 * the <code>ISelection</code> to examine. 830 * the <code>ISelection</code> to examine.
799 * @return the first element, or null if empty. 831 * @return the first element, or null if empty.
800 */ 832 */
801 protected IPreferenceNode getSingleSelection(ISelection selection) { 833 protected IPreferenceNode getSingleSelection(ISelection selection) {
802 if (!selection.isEmpty()) { 834 if (!selection.isEmpty()) {
803 IStructuredSelection structured = (IStructuredSelection) selection; 835 IStructuredSelection structured = cast(IStructuredSelection) selection;
804 if (structured.getFirstElement() instanceof IPreferenceNode) { 836 if (cast(IPreferenceNode)structured.getFirstElement() ) {
805 return (IPreferenceNode) structured.getFirstElement(); 837 return cast(IPreferenceNode) structured.getFirstElement();
806 } 838 }
807 } 839 }
808 return null; 840 return null;
809 } 841 }
810 842
826 * <p> 858 * <p>
827 * Subclasses may override. 859 * Subclasses may override.
828 * </p> 860 * </p>
829 */ 861 */
830 protected void handleSave() { 862 protected void handleSave() {
831 Iterator nodes = preferenceManager.getElements(PreferenceManager.PRE_ORDER).iterator(); 863 foreach( e; preferenceManager.getElements(PreferenceManager.PRE_ORDER)){
832 while (nodes.hasNext()) { 864 IPreferenceNode node = cast(IPreferenceNode) e;
833 IPreferenceNode node = (IPreferenceNode) nodes.next();
834 IPreferencePage page = node.getPage(); 865 IPreferencePage page = node.getPage();
835 if (page instanceof PreferencePage) { 866 if (cast(PreferencePage)page ) {
836 // Save now in case tbe workbench does not shutdown cleanly 867 // Save now in case tbe workbench does not shutdown cleanly
837 IPreferenceStore store = ((PreferencePage) page).getPreferenceStore(); 868 IPreferenceStore store = (cast(PreferencePage) page).getPreferenceStore();
838 if (store !is null && store.needsSaving() 869 if (store !is null && store.needsSaving()
839 && store instanceof IPersistentPreferenceStore) { 870 && cast(IPersistentPreferenceStore)store ) {
840 try { 871 try {
841 ((IPersistentPreferenceStore) store).save(); 872 (cast(IPersistentPreferenceStore) store).save();
842 } catch (IOException e) { 873 } catch (IOException e) {
843 MessageDialog 874 MessageDialog
844 .openError( 875 .openError(
845 getShell(), 876 getShell(),
846 JFaceResources.getString("PreferenceDialog.saveErrorTitle"), //$NON-NLS-1$ 877 JFaceResources.getString("PreferenceDialog.saveErrorTitle"), //$NON-NLS-1$
847 JFaceResources 878 JFaceResources
848 .format( 879 .format(
849 "PreferenceDialog.saveErrorMessage", new Object[] { page.getTitle(), e.getMessage() })); //$NON-NLS-1$ 880 "PreferenceDialog.saveErrorMessage", [ page.getTitle(), e.msg ])); //$NON-NLS-1$
850 } 881 }
851 } 882 }
852 } 883 }
853 } 884 }
854 } 885 }
911 * framework method sends <code>performOk</code> to all pages of the 942 * framework method sends <code>performOk</code> to all pages of the
912 * preference dialog, then calls <code>handleSave</code> on this dialog to 943 * preference dialog, then calls <code>handleSave</code> on this dialog to
913 * save any state, and then calls <code>close</code> to close this dialog. 944 * save any state, and then calls <code>close</code> to close this dialog.
914 */ 945 */
915 protected void okPressed() { 946 protected void okPressed() {
916 SafeRunnable.run(new SafeRunnable() { 947 SafeRunnable.run(new class SafeRunnable {
917 private bool errorOccurred; 948 private bool errorOccurred;
918 949
919 /* 950 /*
920 * (non-Javadoc) 951 * (non-Javadoc)
921 * 952 *
925 getButton(IDialogConstants.OK_ID).setEnabled(false); 956 getButton(IDialogConstants.OK_ID).setEnabled(false);
926 errorOccurred = false; 957 errorOccurred = false;
927 bool hasFailedOK = false; 958 bool hasFailedOK = false;
928 try { 959 try {
929 // Notify all the pages and give them a chance to abort 960 // Notify all the pages and give them a chance to abort
930 Iterator nodes = preferenceManager.getElements(PreferenceManager.PRE_ORDER) 961 foreach( e; preferenceManager.getElements(PreferenceManager.PRE_ORDER)){
931 .iterator(); 962 IPreferenceNode node = cast(IPreferenceNode) e;
932 while (nodes.hasNext()) {
933 IPreferenceNode node = (IPreferenceNode) nodes.next();
934 IPreferencePage page = node.getPage(); 963 IPreferencePage page = node.getPage();
935 if (page !is null) { 964 if (page !is null) {
936 if (!page.performOk()){ 965 if (!page.performOk()){
937 hasFailedOK = true; 966 hasFailedOK = true;
938 return; 967 return;
944 } finally { 973 } finally {
945 //Don't bother closing if the OK failed 974 //Don't bother closing if the OK failed
946 if(hasFailedOK){ 975 if(hasFailedOK){
947 setReturnCode(FAILED); 976 setReturnCode(FAILED);
948 getButton(IDialogConstants.OK_ID).setEnabled(true); 977 getButton(IDialogConstants.OK_ID).setEnabled(true);
949 return; 978 //return;
950 } 979 }
951 980 else{
952 if (!errorOccurred) { 981
953 //Give subclasses the choice to save the state of the 982 if (!errorOccurred) {
954 //preference pages. 983 //Give subclasses the choice to save the state of the
955 handleSave(); 984 //preference pages.
985 handleSave();
986 }
987 setReturnCode(OK);
988 close();
956 } 989 }
957 setReturnCode(OK);
958 close();
959 } 990 }
960 } 991 }
961 992
962 /* 993 /*
963 * (non-Javadoc) 994 * (non-Javadoc)
964 * 995 *
965 * @see dwtx.core.runtime.ISafeRunnable#handleException(java.lang.Throwable) 996 * @see dwtx.core.runtime.ISafeRunnable#handleException(java.lang.Throwable)
966 */ 997 */
967 public void handleException(Throwable e) { 998 public void handleException(Exception e) {
968 errorOccurred = true; 999 errorOccurred = true;
969 1000
970 Policy.getLog().log(new Status(IStatus.ERROR, Policy.JFACE, 0, e.toString(), e)); 1001 Policy.getLog().log(new Status(IStatus.ERROR, Policy.JFACE, 0, e.toString(), e));
971 1002
972 clearSelectedNode(); 1003 clearSelectedNode();
983 */ 1014 */
984 void selectCurrentPageAgain() { 1015 void selectCurrentPageAgain() {
985 if (lastSuccessfulNode is null) { 1016 if (lastSuccessfulNode is null) {
986 return; 1017 return;
987 } 1018 }
988 getTreeViewer().setSelection(new StructuredSelection(lastSuccessfulNode)); 1019 getTreeViewer().setSelection(new StructuredSelection(cast(Object)lastSuccessfulNode));
989 currentPage.setVisible(true); 1020 currentPage.setVisible(true);
990 } 1021 }
991 1022
992 /** 1023 /**
993 * Selects the saved item in the tree of preference pages. If it cannot do 1024 * Selects the saved item in the tree of preference pages. If it cannot do
1000 ViewerFilter[] filters = getTreeViewer().getFilters(); 1031 ViewerFilter[] filters = getTreeViewer().getFilters();
1001 for (int i = 0; i < nodes.length; i++) { 1032 for (int i = 0; i < nodes.length; i++) {
1002 IPreferenceNode selectedNode = nodes[i]; 1033 IPreferenceNode selectedNode = nodes[i];
1003 // See if it passes all filters 1034 // See if it passes all filters
1004 for (int j = 0; j < filters.length; j++) { 1035 for (int j = 0; j < filters.length; j++) {
1005 if (!filters[j].select(this.treeViewer, preferenceManager 1036 if (!filters[j].select(this.treeViewer, cast(Object)preferenceManager
1006 .getRoot(), selectedNode)) { 1037 .getRoot_package(), cast(Object)selectedNode)) {
1007 selectedNode = null; 1038 selectedNode = null;
1008 break; 1039 break;
1009 } 1040 }
1010 } 1041 }
1011 // if it passes all filters select it 1042 // if it passes all filters select it
1014 break; 1045 break;
1015 } 1046 }
1016 } 1047 }
1017 } 1048 }
1018 if (node !is null) { 1049 if (node !is null) {
1019 getTreeViewer().setSelection(new StructuredSelection(node), true); 1050 getTreeViewer().setSelection(new StructuredSelection(cast(Object)node), true);
1020 // Keep focus in tree. See bugs 2692, 2621, and 6775. 1051 // Keep focus in tree. See bugs 2692, 2621, and 6775.
1021 getTreeViewer().getControl().setFocus(); 1052 getTreeViewer().getControl().setFocus();
1022 } 1053 }
1023 } 1054 }
1024 1055
1120 * @param store 1151 * @param store
1121 * the preference store 1152 * the preference store
1122 * @see #getPreferenceStore 1153 * @see #getPreferenceStore
1123 */ 1154 */
1124 public void setPreferenceStore(IPreferenceStore store) { 1155 public void setPreferenceStore(IPreferenceStore store) {
1125 Assert.isNotNull(store); 1156 Assert.isNotNull(cast(Object)store);
1126 preferenceStore = store; 1157 preferenceStore = store;
1127 } 1158 }
1128 1159
1129 /** 1160 /**
1130 * Save the currently selected node. 1161 * Save the currently selected node.
1131 */ 1162 */
1132 private void setSelectedNode() { 1163 private void setSelectedNode() {
1133 String storeValue = null; 1164 String storeValue = null;
1134 IStructuredSelection selection = (IStructuredSelection) getTreeViewer().getSelection(); 1165 IStructuredSelection selection = cast(IStructuredSelection) getTreeViewer().getSelection();
1135 if (selection.size() is 1) { 1166 if (selection.size() is 1) {
1136 IPreferenceNode node = (IPreferenceNode) selection.getFirstElement(); 1167 IPreferenceNode node = cast(IPreferenceNode) selection.getFirstElement();
1137 storeValue = node.getId(); 1168 storeValue = node.getId();
1138 } 1169 }
1139 setSelectedNodePreference(storeValue); 1170 setSelectedNodePreference(storeValue);
1140 } 1171 }
1141 1172
1211 // Set the new page's container 1242 // Set the new page's container
1212 currentPage.setContainer(this); 1243 currentPage.setContainer(this);
1213 // Ensure that the page control has been created 1244 // Ensure that the page control has been created
1214 // (this allows lazy page control creation) 1245 // (this allows lazy page control creation)
1215 if (currentPage.getControl() is null) { 1246 if (currentPage.getControl() is null) {
1216 final bool[] failed = { false }; 1247 bool[1] failed; failed[0] = false;
1217 SafeRunnable.run(new ISafeRunnable() { 1248 SafeRunnable.run(new class ISafeRunnable {
1218 public void handleException(Throwable e) { 1249 public void handleException(Exception e) {
1219 failed[0] = true; 1250 failed[0] = true;
1220 } 1251 }
1221 1252
1222 public void run() { 1253 public void run() {
1223 createPageControl(currentPage, pageContainer); 1254 createPageControl(currentPage, pageContainer);
1233 } 1264 }
1234 // Force calculation of the page's description label because 1265 // Force calculation of the page's description label because
1235 // label can be wrapped. 1266 // label can be wrapped.
1236 final Point[] size = new Point[1]; 1267 final Point[] size = new Point[1];
1237 final Point failed = new Point(-1, -1); 1268 final Point failed = new Point(-1, -1);
1238 SafeRunnable.run(new ISafeRunnable() { 1269 SafeRunnable.run(new class ISafeRunnable {
1239 public void handleException(Throwable e) { 1270 public void handleException(Exception e) {
1240 size[0] = failed; 1271 size[0] = failed;
1241 } 1272 }
1242 1273
1243 public void run() { 1274 public void run() {
1244 size[0] = currentPage.computeSize(); 1275 size[0] = currentPage.computeSize();
1245 } 1276 }
1246 }); 1277 });
1247 if (size[0].equals(failed)) { 1278 if (size[0].opEquals(failed)) {
1248 return false; 1279 return false;
1249 } 1280 }
1250 Point contentSize = size[0]; 1281 Point contentSize = size[0];
1251 // Do we need resizing. Computation not needed if the 1282 // Do we need resizing. Computation not needed if the
1252 // first page is inserted since computing the dialog's 1283 // first page is inserted since computing the dialog's
1257 if (oldPage !is null) { 1288 if (oldPage !is null) {
1258 Rectangle rect = pageContainer.getClientArea(); 1289 Rectangle rect = pageContainer.getClientArea();
1259 Point containerSize = new Point(rect.width, rect.height); 1290 Point containerSize = new Point(rect.width, rect.height);
1260 int hdiff = contentSize.x - containerSize.x; 1291 int hdiff = contentSize.x - containerSize.x;
1261 int vdiff = contentSize.y - containerSize.y; 1292 int vdiff = contentSize.y - containerSize.y;
1262 if ((hdiff > 0 || vdiff > 0) && shellSize.equals(lastShellSize)) { 1293 if ((hdiff > 0 || vdiff > 0) && shellSize.opEquals(lastShellSize)) {
1263 hdiff = Math.max(0, hdiff); 1294 hdiff = Math.max(0, hdiff);
1264 vdiff = Math.max(0, vdiff); 1295 vdiff = Math.max(0, vdiff);
1265 setShellSize(shellSize.x + hdiff, shellSize.y + vdiff); 1296 setShellSize(shellSize.x + hdiff, shellSize.y + vdiff);
1266 lastShellSize = shell.getSize(); 1297 lastShellSize = shell.getSize();
1267 if (currentPage.getControl().getSize().x is 0) { 1298 if (currentPage.getControl().getSize().x is 0) {
1334 updateMessage(); 1365 updateMessage();
1335 // Update the buttons 1366 // Update the buttons
1336 updateButtons(); 1367 updateButtons();
1337 //Saved the selected node in the preferences 1368 //Saved the selected node in the preferences
1338 setSelectedNode(); 1369 setSelectedNode();
1339 firePageChanged(new PageChangedEvent(this, getCurrentPage())); 1370 firePageChanged(new PageChangedEvent(this, cast(Object)getCurrentPage()));
1340 } 1371 }
1341 1372
1342 /* 1373 /*
1343 * (non-Javadoc) 1374 * (non-Javadoc)
1344 * 1375 *
1359 if(currentPage !is null){ 1390 if(currentPage !is null){
1360 message = currentPage.getMessage(); 1391 message = currentPage.getMessage();
1361 errorMessage = currentPage.getErrorMessage(); 1392 errorMessage = currentPage.getErrorMessage();
1362 } 1393 }
1363 int messageType = IMessageProvider.NONE; 1394 int messageType = IMessageProvider.NONE;
1364 if (message !is null && currentPage instanceof IMessageProvider) { 1395 if (message !is null && cast(IMessageProvider)currentPage ) {
1365 messageType = ((IMessageProvider) currentPage).getMessageType(); 1396 messageType = (cast(IMessageProvider) currentPage).getMessageType();
1366 } 1397 }
1367 1398
1368 if (errorMessage is null){ 1399 if (errorMessage is null){
1369 if (showingError) { 1400 if (showingError) {
1370 // we were previously showing an error 1401 // we were previously showing an error
1470 * @see dwtx.jface.dialogs.IPageChangeProvider#getSelectedPage() 1501 * @see dwtx.jface.dialogs.IPageChangeProvider#getSelectedPage()
1471 * 1502 *
1472 * @since 3.1 1503 * @since 3.1
1473 */ 1504 */
1474 public Object getSelectedPage() { 1505 public Object getSelectedPage() {
1475 return getCurrentPage(); 1506 return cast(Object)getCurrentPage();
1476 } 1507 }
1477 1508
1478 /** 1509 /**
1479 * @see dwtx.jface.dialogs.IPageChangeProvider#addPageChangedListener(dwtx.jface.dialogs.IPageChangedListener) 1510 * @see dwtx.jface.dialogs.IPageChangeProvider#addPageChangedListener(dwtx.jface.dialogs.IPageChangedListener)
1480 * @since 3.1 1511 * @since 3.1
1481 */ 1512 */
1482 public void addPageChangedListener(IPageChangedListener listener) { 1513 public void addPageChangedListener(IPageChangedListener listener) {
1483 pageChangedListeners.add(listener); 1514 pageChangedListeners.add(cast(Object)listener);
1484 } 1515 }
1485 1516
1486 /** 1517 /**
1487 * @see dwtx.jface.dialogs.IPageChangeProvider#removePageChangedListener(dwtx.jface.dialogs.IPageChangedListener) 1518 * @see dwtx.jface.dialogs.IPageChangeProvider#removePageChangedListener(dwtx.jface.dialogs.IPageChangedListener)
1488 * @since 3.1 1519 * @since 3.1
1489 */ 1520 */
1490 public void removePageChangedListener(IPageChangedListener listener) { 1521 public void removePageChangedListener(IPageChangedListener listener) {
1491 pageChangedListeners.remove(listener); 1522 pageChangedListeners.remove(cast(Object)listener);
1492 1523
1493 } 1524 }
1494 1525
1495 /** 1526 /**
1496 * Notifies any selection changed listeners that the selected page 1527 * Notifies any selection changed listeners that the selected page
1501 * 1532 *
1502 * @see IPageChangedListener#pageChanged 1533 * @see IPageChangedListener#pageChanged
1503 * 1534 *
1504 * @since 3.1 1535 * @since 3.1
1505 */ 1536 */
1506 protected void firePageChanged(final PageChangedEvent event) { 1537 protected void firePageChanged(PageChangedEvent event) {
1507 Object[] listeners = pageChangedListeners.getListeners(); 1538 Object[] listeners = pageChangedListeners.getListeners();
1508 for (int i = 0; i < listeners.length; i++) { 1539 for (int i = 0; i < listeners.length; i++) {
1509 final IPageChangedListener l = (IPageChangedListener) listeners[i]; 1540 SafeRunnable.run(new class SafeRunnable {
1510 SafeRunnable.run(new SafeRunnable() { 1541 PageChangedEvent event_;
1542 IPageChangedListener l;
1543 this(){
1544 event_=event;
1545 l = cast(IPageChangedListener) listeners[i];
1546 }
1511 public void run() { 1547 public void run() {
1512 l.pageChanged(event); 1548 l.pageChanged(event_);
1513 } 1549 }
1514 }); 1550 });
1515 } 1551 }
1516 } 1552 }
1517 } 1553 }
1518 ++/