Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 87c1289253fe919e42e05376036650624e2823aa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/*******************************************************************************
 * Copyright (c) 2000, 2009 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jdt.internal.ui.macbundler;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

import org.eclipse.jface.dialogs.DialogPage;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.wizard.*;


public abstract class BundleWizardBasePage extends DialogPage implements IWizardPage, BundleAttributes, IPropertyChangeListener {
	
	/**
	 * The page that was shown right before this page became visible;
	 * <code>null</code> if none.
	 */
	private IWizardPage fPreviousPage;
	/**
	 * This page's message key.
	 */
	private String fKey;
	/**
	 * The wizard to which this page belongs; <code>null</code>
	 * if this page has yet to be added to a wizard.
	 */
	private IWizard fWizard;
	
	BundleDescription fBundleDescription;

	
	BundleWizardBasePage(String key, BundleDescription bd) {
		super(Util.getString(key + ".title")); //$NON-NLS-1$
		fKey= key;
		fBundleDescription= bd;
		//setMessage(Util.getString(fKey + ".message")); //$NON-NLS-1$
		setDescription(Util.getString(fKey + ".description")); //$NON-NLS-1$
		
		bd.addListener(this);
	}
	
	/* (non-Javadoc)
	 * Method declared in WizardPage
	 */
	public void setVisible(boolean visible) {
		if (visible)
			enterPage();
		else
			leavePage();
		super.setVisible(visible);
	}
	
	void enterPage() {
		//System.out.println("enterPage: " + getName());
	}

	void leavePage() {
		//System.out.println("leavePage: " + getName());
	}

    public Image getImage() {
        Image result = super.getImage();

        if (result == null && fWizard != null)
            return fWizard.getDefaultPageImage();

        return result;
    }

	/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
	 */
	final public void createControl(Composite parent) {
		
		Composite c= new Composite(parent, SWT.NULL);
		c.setLayout(new GridLayout(1, false));
		setControl(c);
		
		createContents(c);

		checkIfPageComplete();
	}
	
	abstract public void createContents(Composite parent);
	
	static void setHeightHint(Control control, int height) {
		GridData gd1= new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING);
		gd1.heightHint= height;
		control.setLayoutData(gd1);
	}

	static Label createLabel(Composite parent, String text, int align) {
		Label l= new Label(parent, SWT.NONE);
		l.setText(text);
		l.setLayoutData(new GridData(align));
		return l;
	}

	static Composite createComposite(Composite parent, int columns) {
		Composite c= new Composite(parent, SWT.NONE);
		c.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		GridLayout gl= new GridLayout(columns, false);
		gl.marginWidth= 0;
		c.setLayout(gl);
		return c;
	}

	Text createText(Composite parent, String key, int lines) {
		Text t= new Text(parent, SWT.BORDER);
		GridData gd= new GridData(GridData.FILL_HORIZONTAL);
		if (lines == 2)
			gd.heightHint= 30;
		t.setLayoutData(gd);	
		hookField(t, key);
		return t;
	}

	Combo createCombo(Composite parent, String key) {
		Combo c= new Combo(parent, SWT.BORDER);
		c.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		hookField(c, key);
		return c;
	}

	static Group createGroup(Composite parent, String text, int columns) {
		Group g= new Group(parent, SWT.NONE);
		g.setText(text);
		g.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		g.setLayout(new GridLayout(columns, false));
		return g;
	}

	Button createButton(Composite parent, int flags, String text) {
		Button b= new Button(parent, flags);
		if (text != null)
			b.setText(text);
		return b;
	}

	static Composite createHBox(Composite parent) {
		Composite c= new Composite(parent, SWT.NONE);
		c.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		GridLayout gl= new GridLayout(2, false);
		gl.marginWidth= gl.marginHeight= 0;
		c.setLayout(gl);
		return c;
	}
	
	void hookField(final Text tf, final String key) {
		tf.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent e) {
				fBundleDescription.setValue(key, tf.getText());
				checkIfPageComplete();
			}
		});
	}
		
	void hookField(final Combo tf, final String key) {
		tf.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent e) {
				fBundleDescription.setValue(key, tf.getText());
				checkIfPageComplete();
			}
		});
	}
	
	void hookButton(final Button b, final String key) {
		b.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				fBundleDescription.setValue(key, new Boolean(b.getSelection()));
				checkIfPageComplete();
			}
		});
	}
	
	final void checkIfPageComplete() {
		IWizardContainer c= (fWizard != null) ? fWizard.getContainer() : null;
		if (c != null && this == c.getCurrentPage())
			c.updateButtons();
	}

	/////////////////////////////////////////////////////////
	
	/* (non-Javadoc)
	 * @see org.eclipse.jface.wizard.IWizardPage#canFlipToNextPage()
	 */
	public boolean canFlipToNextPage() {
		return isPageComplete() && getNextPage() != null;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.wizard.IWizardPage#getName()
	 */
	public String getName() {
		return Util.getString(fKey + ".title"); //$NON-NLS-1$;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.wizard.IWizardPage#getNextPage()
	 */
	public IWizardPage getNextPage() {
		if (fWizard == null)
			return null;
		return fWizard.getNextPage(this);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.wizard.IWizardPage#getPreviousPage()
	 */
	public IWizardPage getPreviousPage() {
		if (fPreviousPage != null)
			return fPreviousPage;
		if (fWizard != null)
			return fWizard.getPreviousPage(this);
		return null;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.wizard.IWizardPage#getWizard()
	 */
	public IWizard getWizard() {
		return fWizard;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.wizard.IWizardPage#setPreviousPage(org.eclipse.jface.wizard.IWizardPage)
	 */
	public void setPreviousPage(IWizardPage page) {
		fPreviousPage= page;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.wizard.IWizardPage#setWizard(org.eclipse.jface.wizard.IWizard)
	 */
	public void setWizard(IWizard newWizard) {
		fWizard= newWizard;
	}
}

Back to the top