summaryrefslogtreecommitdiffstats
path: root/org.rtems.cdt/src/org/rtems/cdt/wizards/BasicSetup.java
blob: 769523ad5697b40fad80b99ab2ceb30e818a3107 (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
/*
 * Copyright (c) 2008 Embedded Brains GmbH and others.
 *
 *   Embedded Brains GmbH
 *   Obere Lagerstr. 30
 *   D-82178 Puchheim
 *   Germany
 *   rtems@embedded-brains.de
 *
 * All rights reserved.  This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License Version 1.0 ("EPL")
 * which accompanies this distribution and is available at
 *
 *   http://www.eclipse.org/legal/epl-v10.html
 *
 * For purposes of the EPL, "Program" will mean the Content.
 *
 * Contributors:
 *
 *   Sebastian Huber (Embedded Brains GmbH) - Initial API and implementation.
 */

package org.rtems.cdt.wizards;

import org.eclipse.cdt.managedbuilder.ui.wizards.MBSCustomPage;
import org.eclipse.cdt.managedbuilder.ui.wizards.MBSCustomPageManager;
import org.eclipse.cdt.ui.wizards.CDTCommonProjectWizard;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
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.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;
import org.eclipse.swt.SWT;
import org.rtems.cdt.Constants;
import org.rtems.cdt.Storage;

public class BasicSetup extends MBSCustomPage {
	public static final String PAGE_ID = "org.rtems.cdt.wizards.BasicSetup";

	public static final String BROWSE = " &Browse... ";

	private Composite mComposite;

	private Text mBasePath;

	private Text mBSPPath;

	public BasicSetup() {
		pageID = PAGE_ID;
	}

	public boolean canFlipToNextPage() {
		return MBSCustomPageManager.getNextPage(pageID) != null;
	}

	public String getName() {
		return "Basic Setup Page";
	}

	public void createControl(Composite parent) {
		// Create base widget
		mComposite = new Composite(parent, SWT.NONE);

		GridData gd = new GridData(GridData.FILL_BOTH);
		mComposite.setLayoutData(gd);

		GridLayout layout = new GridLayout();
		layout.numColumns = 3;
		mComposite.setLayout(layout);

		// Base path
		Label label = new Label(mComposite, SWT.LEFT);
		label.setText("Base path:");

		mBasePath = new Text(mComposite, SWT.LEFT | SWT.BORDER);
		gd = new GridData(GridData.FILL_HORIZONTAL);
		mBasePath.setLayoutData(gd);

		Button button = new Button(mComposite, SWT.PUSH);
		button.setText(BROWSE);
		button.addSelectionListener(
			new SelectionAdapter() {
				public void widgetSelected(SelectionEvent e) {
					browseForPath(mBasePath);
				}
			}
		);

		// BSP path
		label = new Label(mComposite, SWT.LEFT);
		label.setText("BSP path:");

		mBSPPath = new Text(mComposite, SWT.LEFT | SWT.BORDER);
		gd = new GridData(GridData.FILL_HORIZONTAL);
		mBSPPath.setLayoutData(gd);

		button = new Button(mComposite, SWT.PUSH);
		button.setText(BROWSE);
		button.addSelectionListener(
			new SelectionAdapter() {
				public void widgetSelected(SelectionEvent e) {
					browseForPath(mBSPPath);
				}
			}
		);

		// Connect user input
		mBasePath.addModifyListener(
			new ModifyListener() {
				public void modifyText(ModifyEvent e) {
					basePathChanged();
				}
			}
		);
		mBSPPath.addModifyListener(
			new ModifyListener() {
				public void modifyText(ModifyEvent e) {
					bspPathChanged();
				}
			}
		);

		// Trigger initial setup
		basePathChanged();
		bspPathChanged();
	}

	public void dispose() {
		mComposite.dispose();
	}

	public Control getControl() {
		return mComposite;
	}

	public String getDescription() {
		return "Select the RTEMS base installation path and the board support package (BSP) installation path.";
	}

	public String getErrorMessage() {
		return null;
	}

	public Image getImage() {
		return wizard.getDefaultPageImage();
	}

	public String getMessage() {
		return null;
	}

	public String getTitle() {
		return "RTEMS Setup";
	}

	public void performHelp() {
		// Do nothing
	}

	public void setDescription(String description) {
		// Do nothing
	}

	public void setImageDescriptor(ImageDescriptor image) {
		// Do nothing
	}

	public void setTitle(String title) {
		// Do nothing
	}

	public void setVisible(boolean visible) {
		// Get current project
		CDTCommonProjectWizard wizard = (CDTCommonProjectWizard) getWizard();
		IProject project = wizard.getLastProject();

		/*
		 *  Here we have to take care about the synchronization between the wizard
		 *  and the properties of the new project (advanced settings dialog).
		 */
		if (visible) {
			if (project != null) {
				// For already created projects use the properties
				mBasePath.setText(Storage.getProperty(project, Constants.BASE_PATH_KEY));
				mBSPPath.setText(Storage.getProperty(project, Constants.BSP_PATH_KEY));
			} else {
				// For not yet created projects use the preferences
				mBasePath.setText(Storage.getPreference(Constants.BASE_PATH_KEY));
				mBSPPath.setText(Storage.getPreference(Constants.BSP_PATH_KEY));
			}
		} else {
			if (project != null) {
				// Store the wizard values in the properties if the project exists already
				Storage.setProperty(project, Constants.BASE_PATH_KEY, mBasePath.getText());
				Storage.setProperty(project, Constants.BSP_PATH_KEY, mBSPPath.getText());
			}
		}

		mComposite.setVisible(visible);
	}

	protected boolean isCustomPageComplete() {
		return true;
	}

	private void browseForPath(Text text) {
		DirectoryDialog dialog = new DirectoryDialog(mComposite.getShell(), SWT.NONE);
		dialog.setFilterPath(text.getText());
		String path = dialog.open();
		if (path != null) {
			text.setText(path);
		}
	}

	private void basePathChanged() {
		MBSCustomPageManager.addPageProperty(pageID, Constants.BASE_PATH_KEY, mBasePath.getText());
	}

	private void bspPathChanged() {
		MBSCustomPageManager.addPageProperty(pageID, Constants.BSP_PATH_KEY, mBSPPath.getText());
	}
}