Skip to main content
summaryrefslogtreecommitdiffstats
blob: 68d25e62dfbbf684bdb5bdb214ee45785fb9d9f3 (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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
/*******************************************************************************
 *  Copyright (c) 2007, 2015 IBM Corporation and others.
 *
 *  This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License 2.0
 *  which accompanies this distribution, and is available at
 *  https://www.eclipse.org/legal/epl-2.0/
 *
 *  SPDX-License-Identifier: EPL-2.0
 *
 *  Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.managedbuilder.xlc.ui.wizards;

import org.eclipse.cdt.managedbuilder.ui.wizards.MBSCustomPage;
import org.eclipse.cdt.managedbuilder.ui.wizards.MBSCustomPageManager;
import org.eclipse.cdt.managedbuilder.xlc.ui.Messages;
import org.eclipse.cdt.managedbuilder.xlc.ui.XLCUIPlugin;
import org.eclipse.cdt.managedbuilder.xlc.ui.preferences.PreferenceConstants;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

/**
 * @author crecoskie
 *
 */
public class XLCSettingsWizardPage extends MBSCustomPage {

	public static final String PAGE_ID = "org.eclipse.cdt.managedbuilder.xlc.ui.XlcSettingsWizardPage"; //$NON-NLS-1$

	private final class BrowseButtonSelectionListener implements
			SelectionListener {
		private final Composite composite;

		private BrowseButtonSelectionListener(Composite composite) {
			this.composite = composite;
		}

		@Override
		public void widgetDefaultSelected(SelectionEvent e) {
			// meaningless for a button... do nothing

		}

		@Override
		public void widgetSelected(SelectionEvent e) {
			// open a browse dialog
			DirectoryDialog dirDialog = new DirectoryDialog(composite.getShell(), SWT.APPLICATION_MODAL);
			String browsedDirectory = dirDialog.open();
			if (browsedDirectory != null) {
				fDirTextBox.setText(browsedDirectory);
			}
		}
	}

	private Composite fComposite = null;

	private Text fDirTextBox;

	private Combo fVersionCombo;

	/**
	 * @param pageID
	 */
	public XLCSettingsWizardPage(String pageID) {
		super(pageID);
		setDefaultPreferences(pageID);
	}

	/**
	 *
	 */
	public XLCSettingsWizardPage() {
		super(PAGE_ID);
		setDefaultPreferences(PAGE_ID);
	}

	private void setDefaultPreferences(String pageID) {
		String compilerPath = XLCUIPlugin.getDefault().getPreferenceStore().getString(PreferenceConstants.P_XL_COMPILER_ROOT);
		MBSCustomPageManager.addPageProperty(pageID, PreferenceConstants.P_XL_COMPILER_ROOT, compilerPath);
		MBSCustomPageManager.addPageProperty(pageID, PreferenceConstants.P_XLC_COMPILER_VERSION, PreferenceConstants.P_XL_COMPILER_VERSION_8);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.cdt.managedbuilder.ui.wizards.MBSCustomPage#isCustomPageComplete()
	 */
	@Override
	protected boolean isCustomPageComplete() {
		return true;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.wizard.IWizardPage#getName()
	 */
	@Override
	public String getName() {
		String name = Messages.XLCSettingsWizardPage_0;
		return name;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
	 */
	@Override
	public void createControl(Composite parent) {
		// create a new composite
		fComposite = new Composite(parent, SWT.NONE);
		fComposite.setBounds(parent.getBounds());
		GridLayout layout = new GridLayout(3, false);
		fComposite.setLayout(layout);
		fComposite.setLayoutData(new GridData(GridData.FILL_BOTH));

		// create the first label
		Label label1 = new Label(fComposite, SWT.NONE);
		label1.setText(Messages.XLCSettingsWizardPage_1);
		label1.setVisible(true);

		// create the text box for the path
		GridData dirBoxGridData = new GridData();
		dirBoxGridData.grabExcessHorizontalSpace = true;
		dirBoxGridData.horizontalAlignment = SWT.FILL;
		fDirTextBox = new Text(fComposite, SWT.SINGLE | SWT.BORDER);
		fDirTextBox.setLayoutData(dirBoxGridData);
		fDirTextBox.setVisible(true);

		// set the default compiler location based on preferences
		IPreferenceStore prefStore = XLCUIPlugin.getDefault().getPreferenceStore();
		String compilerPath = prefStore.getString(PreferenceConstants.P_XL_COMPILER_ROOT);
		fDirTextBox.setText(compilerPath);

		// update the page manager with the setting
		MBSCustomPageManager.addPageProperty(pageID, PreferenceConstants.P_XL_COMPILER_ROOT, fDirTextBox.getText());

		fDirTextBox.addModifyListener(new ModifyListener() {

			@Override
			public void modifyText(ModifyEvent e) {
				// update the page manager with the setting
				MBSCustomPageManager.addPageProperty(pageID, PreferenceConstants.P_XL_COMPILER_ROOT, fDirTextBox.getText());

			}

		});

		// create the browse button
		//String selectedPath = null;
		GridData buttonData = new GridData();
		buttonData.horizontalAlignment = SWT.RIGHT;
		Button browseButton = new Button(fComposite, SWT.PUSH);
		browseButton.setAlignment(SWT.CENTER);
		browseButton.setText(Messages.XLCSettingsWizardPage_2);
		browseButton.addSelectionListener(new BrowseButtonSelectionListener(fComposite)
		);

		browseButton.setVisible(true);

		// create the second label
		Label label2 = new Label(fComposite, SWT.NONE);
		label2.setText(Messages.XLCSettingsWizardPage_3);

		label2.setVisible(true);

		// create the version dropdown
		GridData comboData = new GridData();
		comboData.grabExcessHorizontalSpace = true;
		comboData.horizontalAlignment = SWT.FILL;

		fVersionCombo = new Combo(fComposite, SWT.READ_ONLY);
		fVersionCombo.setLayoutData(comboData);

		// populate the combo
		fVersionCombo.add(PreferenceConstants.P_XL_COMPILER_VERSION_8_NAME);
		fVersionCombo.add(PreferenceConstants.P_XL_COMPILER_VERSION_9_NAME);
		fVersionCombo.add(PreferenceConstants.P_XL_COMPILER_VERSION_10_NAME);
		fVersionCombo.add(PreferenceConstants.P_XL_COMPILER_VERSION_11_NAME);

		// set the default based on the workbench preference
		String compilerVersion = prefStore.getString(PreferenceConstants.P_XLC_COMPILER_VERSION);
		fVersionCombo.setText(PreferenceConstants.getVersionLabel(compilerVersion));

		// update the page manager with the setting
		MBSCustomPageManager.addPageProperty(pageID, PreferenceConstants.P_XLC_COMPILER_VERSION, PreferenceConstants.getVersion(fVersionCombo.getText()));

		fVersionCombo.addModifyListener(new ModifyListener() {

			@Override
			public void modifyText(ModifyEvent e) {
				// update the page manager with the setting
				MBSCustomPageManager.addPageProperty(pageID, PreferenceConstants.P_XLC_COMPILER_VERSION, PreferenceConstants.getVersion(fVersionCombo.getText()));

			}

		});

		fVersionCombo.setVisible(true);

	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.IDialogPage#dispose()
	 */
	@Override
	public void dispose() {
		fComposite.dispose();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.IDialogPage#getControl()
	 */
	@Override
	public Control getControl() {
		return fComposite;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.IDialogPage#getDescription()
	 */
	@Override
	public String getDescription() {
		return Messages.XLCSettingsWizardPage_4;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.IDialogPage#getErrorMessage()
	 */
	@Override
	public String getErrorMessage() {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.IDialogPage#getImage()
	 */
	@Override
	public Image getImage() {
		return wizard.getDefaultPageImage();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.IDialogPage#getMessage()
	 */
	@Override
	public String getMessage() {
		return null;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.IDialogPage#getTitle()
	 */
	@Override
	public String getTitle() {
		return Messages.XLCSettingsWizardPage_5;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.IDialogPage#performHelp()
	 */
	@Override
	public void performHelp() {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.IDialogPage#setDescription(java.lang.String)
	 */
	@Override
	public void setDescription(String description) {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.IDialogPage#setImageDescriptor(org.eclipse.jface.resource.ImageDescriptor)
	 */
	@Override
	public void setImageDescriptor(ImageDescriptor image) {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.IDialogPage#setTitle(java.lang.String)
	 */
	@Override
	public void setTitle(String title) {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.IDialogPage#setVisible(boolean)
	 */
	@Override
	public void setVisible(boolean visible) {
		fComposite.setVisible(visible);
	}

}

Back to the top