KickJava   Java API By Example, From Geeks To Geeks.

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


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

6 package com.nightlabs.rcp.wizard;
7
8 import org.eclipse.jface.resource.ImageDescriptor;
9 import org.eclipse.jface.wizard.WizardPage;
10 import org.eclipse.swt.widgets.Composite;
11 import org.eclipse.swt.widgets.Control;
12
13 /**
14  * Extends WizardPage and resolves its wickedness of NullPointerExceptions.
15  * Subclass this instead of WizardPage and simply implement
16  * {@link #createPageContents(Composite)}.
17  *
18  * @author Alexander Bieber <alex[AT]nightlabs[DOT]de>
19  *
20  */

21 public abstract class DynamicPathWizardPage
22 extends WizardPage
23 implements IDynamicPathWizardPage
24 {
25
26     /**
27      * @param pageName
28      */

29     public DynamicPathWizardPage(String JavaDoc pageName) {
30         super(pageName);
31     }
32
33     /**
34      * @param pageName
35      * @param title
36      */

37     public DynamicPathWizardPage(String JavaDoc pageName, String JavaDoc title) {
38         super(pageName);
39         setTitle(title);
40     }
41
42     /**
43      * @param pageName
44      * @param title
45      * @param titleImage
46      */

47     public DynamicPathWizardPage(String JavaDoc pageName, String JavaDoc title,
48             ImageDescriptor titleImage) {
49         super(pageName, title, titleImage);
50     }
51     
52     protected Control contents;
53
54     /**
55      * Overidden to prevent NullPointerExceptions.
56      *
57      * @see org.eclipse.jface.dialogs.IDialogPage#getControl()
58      */

59     public Control getControl() {
60         return contents;
61     }
62     
63     /**
64      * Calls createPageContents and then setContents() with the result.
65      * Additionally set the message to {@link #getDefaultPageMessage()} if
66      * overridden and does not return null.
67      *
68      * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
69      */

70     public void createControl(Composite parent) {
71         contents = createPageContents(parent);
72         setDefaultPageMessage();
73         setControl(contents);
74     }
75     
76     /**
77      * Create the WizardPage contents and return the topmost Control.
78      *
79      * @param parent
80      * @return
81      */

82     public abstract Control createPageContents(Composite parent);
83
84     /**
85      * The implementation of this method in <tt>DynamicPathWizardPage</tt> returns
86      * always <tt>true</tt>. If you want to forbid this page from being the
87      * last, you must overwrite it.
88      *
89      * @see com.nightlabs.rcp.wizard.IDynamicPathWizardPage#canBeLastPage()
90      */

91     public boolean canBeLastPage()
92     {
93         return true;
94     }
95     
96     /**
97      * This method is called by {@link #updateStatus(String)}.
98      * Override to set the message displayed initially and on
99      * page completition.
100      * Default implementation will return an empty string.
101      *
102      * @return null
103      */

104     protected String JavaDoc getDefaultPageMessage() {
105         return null;
106     }
107     
108     private void setDefaultPageMessage() {
109         String JavaDoc defaultMessage = getDefaultPageMessage();
110         if (defaultMessage != null)
111             setMessage(defaultMessage);
112     }
113     
114     /**
115      * Lets you control the status with an error-message.
116      * When null is passed the displayed message is set to
117      * {@link #getDefaultPageMessage()} and pageComplete
118      * will be set to true.
119      * Otherwise pageComplete will be false and the
120      * passed errMsg will be displayed.
121      *
122      * @param errMsg
123      */

124     protected void updateStatus(String JavaDoc errMsg) {
125         if (errMsg != null) {
126             setErrorMessage(errMsg);
127             setPageComplete(false);
128         }
129         else {
130             setErrorMessage(null);
131             setDefaultPageMessage();
132             setPageComplete(true);
133         }
134     }
135
136     /**
137      * @see com.nightlabs.rcp.wizard.IDynamicPathWizardPage#onShow()
138      */

139     public void onShow()
140     {
141     }
142
143     /**
144      * @see com.nightlabs.rcp.wizard.IDynamicPathWizardPage#onHide()
145      */

146     public void onHide()
147     {
148     }
149 }
150
Popular Tags