001: /*******************************************************************************
002: * Copyright (c) 2000, 2005 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.internal.ui.macbundler;
011:
012: import org.eclipse.swt.SWT;
013: import org.eclipse.swt.events.*;
014: import org.eclipse.swt.graphics.Image;
015: import org.eclipse.swt.layout.*;
016: import org.eclipse.swt.widgets.*;
017:
018: import org.eclipse.jface.dialogs.DialogPage;
019: import org.eclipse.jface.util.IPropertyChangeListener;
020: import org.eclipse.jface.wizard.*;
021:
022: public abstract class BundleWizardBasePage extends DialogPage implements
023: IWizardPage, BundleAttributes, IPropertyChangeListener {
024:
025: /**
026: * The page that was shown right before this page became visible;
027: * <code>null</code> if none.
028: */
029: private IWizardPage fPreviousPage;
030: /**
031: * This page's message key.
032: */
033: private String fKey;
034: /**
035: * The wizard to which this page belongs; <code>null</code>
036: * if this page has yet to be added to a wizard.
037: */
038: private IWizard fWizard;
039:
040: BundleDescription fBundleDescription;
041:
042: BundleWizardBasePage(String key, BundleDescription bd) {
043: super (Util.getString(key + ".title")); //$NON-NLS-1$
044: fKey = key;
045: fBundleDescription = bd;
046: //setMessage(Util.getString(fKey + ".message")); //$NON-NLS-1$
047: setDescription(Util.getString(fKey + ".description")); //$NON-NLS-1$
048:
049: bd.addListener(this );
050: }
051:
052: /* (non-Javadoc)
053: * Method declared in WizardPage
054: */
055: public void setVisible(boolean visible) {
056: if (visible)
057: enterPage();
058: else
059: leavePage();
060: super .setVisible(visible);
061: }
062:
063: void enterPage() {
064: //System.out.println("enterPage: " + getName());
065: }
066:
067: void leavePage() {
068: //System.out.println("leavePage: " + getName());
069: }
070:
071: public Image getImage() {
072: Image result = super .getImage();
073:
074: if (result == null && fWizard != null)
075: return fWizard.getDefaultPageImage();
076:
077: return result;
078: }
079:
080: /* (non-Javadoc)
081: * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
082: */
083: final public void createControl(Composite parent) {
084:
085: Composite c = new Composite(parent, SWT.NULL);
086: c.setLayout(new GridLayout(1, false));
087: setControl(c);
088:
089: createContents(c);
090:
091: checkIfPageComplete();
092: }
093:
094: abstract public void createContents(Composite parent);
095:
096: static void setHeightHint(Control control, int height) {
097: GridData gd1 = new GridData(GridData.FILL_HORIZONTAL
098: | GridData.VERTICAL_ALIGN_BEGINNING);
099: gd1.heightHint = height;
100: control.setLayoutData(gd1);
101: }
102:
103: static Label createLabel(Composite parent, String text, int align) {
104: Label l = new Label(parent, SWT.NONE);
105: l.setText(text);
106: l.setLayoutData(new GridData(align));
107: return l;
108: }
109:
110: static Composite createComposite(Composite parent, int columns) {
111: Composite c = new Composite(parent, SWT.NONE);
112: c.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
113: GridLayout gl = new GridLayout(columns, false);
114: gl.marginWidth = 0;
115: c.setLayout(gl);
116: return c;
117: }
118:
119: Text createText(Composite parent, String key, int lines) {
120: Text t = new Text(parent, SWT.BORDER);
121: GridData gd = new GridData(GridData.FILL_HORIZONTAL);
122: if (lines == 2)
123: gd.heightHint = 30;
124: t.setLayoutData(gd);
125: hookField(t, key);
126: return t;
127: }
128:
129: Combo createCombo(Composite parent, String key) {
130: Combo c = new Combo(parent, SWT.BORDER);
131: c.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
132: hookField(c, key);
133: return c;
134: }
135:
136: static Group createGroup(Composite parent, String text, int columns) {
137: Group g = new Group(parent, SWT.NONE);
138: g.setText(text);
139: g.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
140: g.setLayout(new GridLayout(columns, false));
141: return g;
142: }
143:
144: Button createButton(Composite parent, int flags, String text) {
145: Button b = new Button(parent, flags);
146: if (text != null)
147: b.setText(text);
148: return b;
149: }
150:
151: static Composite createHBox(Composite parent) {
152: Composite c = new Composite(parent, SWT.NONE);
153: c.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
154: GridLayout gl = new GridLayout(2, false);
155: gl.marginWidth = gl.marginHeight = 0;
156: c.setLayout(gl);
157: return c;
158: }
159:
160: void hookField(final Text tf, final String key) {
161: tf.addModifyListener(new ModifyListener() {
162: public void modifyText(ModifyEvent e) {
163: fBundleDescription.setValue(key, tf.getText());
164: checkIfPageComplete();
165: }
166: });
167: }
168:
169: void hookField(final Combo tf, final String key) {
170: tf.addModifyListener(new ModifyListener() {
171: public void modifyText(ModifyEvent e) {
172: fBundleDescription.setValue(key, tf.getText());
173: checkIfPageComplete();
174: }
175: });
176: }
177:
178: void hookButton(final Button b, final String key) {
179: b.addSelectionListener(new SelectionAdapter() {
180: public void widgetSelected(SelectionEvent e) {
181: fBundleDescription.setValue(key, new Boolean(b
182: .getSelection()));
183: checkIfPageComplete();
184: }
185: });
186: }
187:
188: final void checkIfPageComplete() {
189: IWizardContainer c = (fWizard != null) ? fWizard.getContainer()
190: : null;
191: if (c != null && this == c.getCurrentPage())
192: c.updateButtons();
193: }
194:
195: /////////////////////////////////////////////////////////
196:
197: /* (non-Javadoc)
198: * @see org.eclipse.jface.wizard.IWizardPage#canFlipToNextPage()
199: */
200: public boolean canFlipToNextPage() {
201: return isPageComplete() && getNextPage() != null;
202: }
203:
204: /* (non-Javadoc)
205: * @see org.eclipse.jface.wizard.IWizardPage#getName()
206: */
207: public String getName() {
208: return Util.getString(fKey + ".title"); //$NON-NLS-1$;
209: }
210:
211: /* (non-Javadoc)
212: * @see org.eclipse.jface.wizard.IWizardPage#getNextPage()
213: */
214: public IWizardPage getNextPage() {
215: if (fWizard == null)
216: return null;
217: return fWizard.getNextPage(this );
218: }
219:
220: /* (non-Javadoc)
221: * @see org.eclipse.jface.wizard.IWizardPage#getPreviousPage()
222: */
223: public IWizardPage getPreviousPage() {
224: if (fPreviousPage != null)
225: return fPreviousPage;
226: if (fWizard != null)
227: return fWizard.getPreviousPage(this );
228: return null;
229: }
230:
231: /* (non-Javadoc)
232: * @see org.eclipse.jface.wizard.IWizardPage#getWizard()
233: */
234: public IWizard getWizard() {
235: return fWizard;
236: }
237:
238: /* (non-Javadoc)
239: * @see org.eclipse.jface.wizard.IWizardPage#setPreviousPage(org.eclipse.jface.wizard.IWizardPage)
240: */
241: public void setPreviousPage(IWizardPage page) {
242: fPreviousPage = page;
243: }
244:
245: /* (non-Javadoc)
246: * @see org.eclipse.jface.wizard.IWizardPage#setWizard(org.eclipse.jface.wizard.IWizard)
247: */
248: public void setWizard(IWizard newWizard) {
249: fWizard = newWizard;
250: }
251: }
|