KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > rcp > wizard > DynamicPathWizardDialog


1 /*
2  * Created on Jan 13, 2005
3  * by alex
4  *
5  */

6 package com.nightlabs.rcp.wizard;
7
8 import org.eclipse.jface.dialogs.IDialogConstants;
9 import org.eclipse.jface.window.Window;
10 import org.eclipse.jface.wizard.IWizardPage;
11 import org.eclipse.jface.wizard.WizardDialog;
12 import org.eclipse.swt.widgets.Button;
13 import org.eclipse.swt.widgets.Composite;
14 import org.eclipse.swt.widgets.Control;
15 import org.eclipse.swt.widgets.Shell;
16 import org.eclipse.ui.internal.Workbench;
17
18
19 /**
20  * @author Alexander Bieber <alex[AT]nightlabs[DOT]de>
21  *
22  */

23 public class DynamicPathWizardDialog extends WizardDialog {
24
25     private DynamicPathWizard dynamicWizard;
26
27     public DynamicPathWizardDialog(DynamicPathWizard wizard) {
28         this(Workbench.getInstance().getActiveWorkbenchWindow().getShell(),wizard);
29     }
30
31     public DynamicPathWizardDialog(Shell shell, DynamicPathWizard wizard) {
32         super(shell, wizard);
33         dynamicWizard = wizard;
34         dynamicWizard.setDynamicWizardDialog(this);
35     }
36     
37     /**
38      * Overrides and makes it public so the wizard can
39      * trigger the update of the dialog buttons.
40      *
41      * @see org.eclipse.jface.wizard.WizardDialog#update()
42      */

43     public void update() {
44         super.update();
45     }
46     
47     /**
48      * Overrides and makes it public.
49      *
50      * @see org.eclipse.jface.dialogs.Dialog#getButton(int)
51      */

52     public Button getButton(int id) {
53         // TODO Auto-generated method stub
54
return super.getButton(id);
55     }
56     
57     protected void backPressed() {
58         buttonBar.setFocus(); // to trigger all GUI-element-to-backend-object-store-methods
59
super.backPressed();
60         if (dynamicWizard.getPopulator() != null &&
61                 getCurrentPage() == dynamicWizard.getWizardEntryPage()) {
62             dynamicWizard.removeAllDynamicWizardPages();
63         }
64     }
65     
66     protected void nextPressed() {
67         buttonBar.setFocus(); // to trigger all GUI-element-to-backend-object-store-methods
68
if (getCurrentPage() == dynamicWizard.getWizardEntryPage()) {
69             if (dynamicWizard.getPopulator() != null)
70                 dynamicWizard.getPopulator().addDynamicWizardPages(dynamicWizard);
71         }
72         super.nextPressed();
73     }
74
75     /**
76      * @see org.eclipse.jface.wizard.WizardDialog#finishPressed()
77      */

78     protected void finishPressed()
79     {
80         buttonBar.setFocus(); // to trigger all GUI-element-to-backend-object-store-methods
81
super.finishPressed();
82     }
83
84     /**
85      * @see org.eclipse.jface.wizard.WizardDialog#cancelPressed()
86      */

87     protected void cancelPressed()
88     {
89         buttonBar.setFocus(); // to trigger all GUI-element-to-backend-object-store-methods
90
super.cancelPressed();
91     }
92     
93     
94
95     protected Control createContents(Composite parent) {
96         Control result = super.createContents(parent);
97         if (dynamicWizard.getWizardEntryPage() instanceof IDynamicPathWizardPage)
98             dynamicWizard.getWizardEntryPage().onShow();
99         return result;
100     }
101
102     protected void buttonPressed(int buttonId) {
103         if (buttonId == IDialogConstants.FINISH_ID) {
104             IWizardPage currPage = getCurrentPage();
105             if (currPage instanceof IDynamicPathWizardPage)
106                 ((IDynamicPathWizardPage)currPage).onHide();
107         }
108         super.buttonPressed(buttonId);
109         if (getReturnCode() != Window.OK) {
110             IWizardPage currPage = getCurrentPage();
111             if (currPage instanceof IDynamicPathWizardPage)
112                 ((IDynamicPathWizardPage)currPage).onShow();
113         }
114     }
115
116     /**
117      * @see org.eclipse.jface.wizard.WizardDialog#showPage(org.eclipse.jface.wizard.IWizardPage)
118      */

119     public void showPage(IWizardPage page)
120     {
121         IWizardPage currPage = getCurrentPage();
122
123         if (currPage == page)
124             return;
125
126         if (currPage instanceof IDynamicPathWizardPage)
127             ((IDynamicPathWizardPage)currPage).onHide();
128
129         super.showPage(page);
130
131         if (page instanceof IDynamicPathWizardPage)
132             ((IDynamicPathWizardPage)page).onShow();
133     }
134 }
135
Popular Tags