KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > macbundler > BundleWizardBasePage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.ui.macbundler;
12
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.events.*;
15 import org.eclipse.swt.graphics.Image;
16 import org.eclipse.swt.layout.*;
17 import org.eclipse.swt.widgets.*;
18
19 import org.eclipse.jface.dialogs.DialogPage;
20 import org.eclipse.jface.util.IPropertyChangeListener;
21 import org.eclipse.jface.wizard.*;
22
23
24 public abstract class BundleWizardBasePage extends DialogPage implements IWizardPage, BundleAttributes, IPropertyChangeListener {
25     
26     /**
27      * The page that was shown right before this page became visible;
28      * <code>null</code> if none.
29      */

30     private IWizardPage fPreviousPage;
31     /**
32      * This page's message key.
33      */

34     private String JavaDoc fKey;
35     /**
36      * The wizard to which this page belongs; <code>null</code>
37      * if this page has yet to be added to a wizard.
38      */

39     private IWizard fWizard;
40     
41     BundleDescription fBundleDescription;
42
43     
44     BundleWizardBasePage(String JavaDoc key, BundleDescription bd) {
45         super(Util.getString(key + ".title")); //$NON-NLS-1$
46
fKey= key;
47         fBundleDescription= bd;
48         //setMessage(Util.getString(fKey + ".message")); //$NON-NLS-1$
49
setDescription(Util.getString(fKey + ".description")); //$NON-NLS-1$
50

51         bd.addListener(this);
52     }
53     
54     /* (non-Javadoc)
55      * Method declared in WizardPage
56      */

57     public void setVisible(boolean visible) {
58         if (visible)
59             enterPage();
60         else
61             leavePage();
62         super.setVisible(visible);
63     }
64     
65     void enterPage() {
66         //System.out.println("enterPage: " + getName());
67
}
68
69     void leavePage() {
70         //System.out.println("leavePage: " + getName());
71
}
72
73     public Image getImage() {
74         Image result = super.getImage();
75
76         if (result == null && fWizard != null)
77             return fWizard.getDefaultPageImage();
78
79         return result;
80     }
81
82     /* (non-Javadoc)
83      * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
84      */

85     final public void createControl(Composite parent) {
86         
87         Composite c= new Composite(parent, SWT.NULL);
88         c.setLayout(new GridLayout(1, false));
89         setControl(c);
90         
91         createContents(c);
92
93         checkIfPageComplete();
94     }
95     
96     abstract public void createContents(Composite parent);
97     
98     static void setHeightHint(Control control, int height) {
99         GridData gd1= new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING);
100         gd1.heightHint= height;
101         control.setLayoutData(gd1);
102     }
103
104     static Label createLabel(Composite parent, String JavaDoc text, int align) {
105         Label l= new Label(parent, SWT.NONE);
106         l.setText(text);
107         l.setLayoutData(new GridData(align));
108         return l;
109     }
110
111     static Composite createComposite(Composite parent, int columns) {
112         Composite c= new Composite(parent, SWT.NONE);
113         c.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
114         GridLayout gl= new GridLayout(columns, false);
115         gl.marginWidth= 0;
116         c.setLayout(gl);
117         return c;
118     }
119
120     Text createText(Composite parent, String JavaDoc key, int lines) {
121         Text t= new Text(parent, SWT.BORDER);
122         GridData gd= new GridData(GridData.FILL_HORIZONTAL);
123         if (lines == 2)
124             gd.heightHint= 30;
125         t.setLayoutData(gd);
126         hookField(t, key);
127         return t;
128     }
129
130     Combo createCombo(Composite parent, String JavaDoc key) {
131         Combo c= new Combo(parent, SWT.BORDER);
132         c.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
133         hookField(c, key);
134         return c;
135     }
136
137     static Group createGroup(Composite parent, String JavaDoc text, int columns) {
138         Group g= new Group(parent, SWT.NONE);
139         g.setText(text);
140         g.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
141         g.setLayout(new GridLayout(columns, false));
142         return g;
143     }
144
145     Button createButton(Composite parent, int flags, String JavaDoc text) {
146         Button b= new Button(parent, flags);
147         if (text != null)
148             b.setText(text);
149         return b;
150     }
151
152     static Composite createHBox(Composite parent) {
153         Composite c= new Composite(parent, SWT.NONE);
154         c.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
155         GridLayout gl= new GridLayout(2, false);
156         gl.marginWidth= gl.marginHeight= 0;
157         c.setLayout(gl);
158         return c;
159     }
160     
161     void hookField(final Text tf, final String JavaDoc key) {
162         tf.addModifyListener(new ModifyListener() {
163             public void modifyText(ModifyEvent e) {
164                 fBundleDescription.setValue(key, tf.getText());
165                 checkIfPageComplete();
166             }
167         });
168     }
169         
170     void hookField(final Combo tf, final String JavaDoc key) {
171         tf.addModifyListener(new ModifyListener() {
172             public void modifyText(ModifyEvent e) {
173                 fBundleDescription.setValue(key, tf.getText());
174                 checkIfPageComplete();
175             }
176         });
177     }
178     
179     void hookButton(final Button b, final String JavaDoc key) {
180         b.addSelectionListener(new SelectionAdapter() {
181             public void widgetSelected(SelectionEvent e) {
182                 fBundleDescription.setValue(key, new Boolean JavaDoc(b.getSelection()));
183                 checkIfPageComplete();
184             }
185         });
186     }
187     
188     final void checkIfPageComplete() {
189         IWizardContainer c= (fWizard != null) ? fWizard.getContainer() : null;
190         if (c != null && this == c.getCurrentPage())
191             c.updateButtons();
192     }
193
194     /////////////////////////////////////////////////////////
195

196     /* (non-Javadoc)
197      * @see org.eclipse.jface.wizard.IWizardPage#canFlipToNextPage()
198      */

199     public boolean canFlipToNextPage() {
200         return isPageComplete() && getNextPage() != null;
201     }
202
203     /* (non-Javadoc)
204      * @see org.eclipse.jface.wizard.IWizardPage#getName()
205      */

206     public String JavaDoc getName() {
207         return Util.getString(fKey + ".title"); //$NON-NLS-1$;
208
}
209
210     /* (non-Javadoc)
211      * @see org.eclipse.jface.wizard.IWizardPage#getNextPage()
212      */

213     public IWizardPage getNextPage() {
214         if (fWizard == null)
215             return null;
216         return fWizard.getNextPage(this);
217     }
218
219     /* (non-Javadoc)
220      * @see org.eclipse.jface.wizard.IWizardPage#getPreviousPage()
221      */

222     public IWizardPage getPreviousPage() {
223         if (fPreviousPage != null)
224             return fPreviousPage;
225         if (fWizard != null)
226             return fWizard.getPreviousPage(this);
227         return null;
228     }
229
230     /* (non-Javadoc)
231      * @see org.eclipse.jface.wizard.IWizardPage#getWizard()
232      */

233     public IWizard getWizard() {
234         return fWizard;
235     }
236
237     /* (non-Javadoc)
238      * @see org.eclipse.jface.wizard.IWizardPage#setPreviousPage(org.eclipse.jface.wizard.IWizardPage)
239      */

240     public void setPreviousPage(IWizardPage page) {
241         fPreviousPage= page;
242     }
243
244     /* (non-Javadoc)
245      * @see org.eclipse.jface.wizard.IWizardPage#setWizard(org.eclipse.jface.wizard.IWizard)
246      */

247     public void setWizard(IWizard newWizard) {
248         fWizard= newWizard;
249     }
250 }
251
Popular Tags