summaryrefslogtreecommitdiffstats
path: root/org.rtems.cdt.toolchain2/org/rtems/cdt/wizards/BasicSetup.java
blob: 01abd88faac8035b1607e16f3459627c80539ee4 (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
/*
 * Copyright (c) 2008
 * Embedded Brains GmbH
 * Obere Lagerstr. 30
 * D-82178 Puchheim
 * Germany
 * rtems@embedded-brains.de
 *
 * The license and distribution terms for this file may be found in the file
 * LICENSE in this distribution or at http://www.rtems.com/license/LICENSE.
 */

package org.rtems.cdt.wizards;

import java.util.*;
import org.eclipse.cdt.managedbuilder.ui.wizards.MBSCustomPage;
import org.eclipse.cdt.managedbuilder.ui.wizards.MBSCustomPageManager;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.SWT;

public class BasicSetup extends MBSCustomPage {
	public static final String PAGE_ID = "org.rtems.cdt.wizards.basicsetup";
	
	private SortedMap<String, String> mTargetMap;
	
	private Composite mComposite;
	
	private Text mInstallationPath;
	
	private Text mVersion;
	
	private Combo mTarget;

	public BasicSetup() {
		pageID = PAGE_ID;
		
		mTargetMap = new TreeMap<String, String>();
		mTargetMap.put( new String( "PowerPC"), new String ("powerpc"));
		mTargetMap.put( new String( "ARM"), new String ("arm"));
		mTargetMap.put( new String( "SPARC"), new String ("sparc"));
		mTargetMap.put( new String( "Motorola 68k or Freescale ColdFire"), new String ("m68k"));
		mTargetMap.put( new String( "Intel i386"), new String ("i368"));
		mTargetMap.put( new String( "Intel i686"), new String ("i668"));
		mTargetMap.put( new String( "AVR"), new String ("avr"));
		mTargetMap.put( new String( "Blackfin"), new String ("bfin"));
		mTargetMap.put( new String( "Hitachi H8300"), new String ("h8300"));
		mTargetMap.put( new String( "MIPS"), new String ("mips"));
		mTargetMap.put( new String( "SuperH"), new String ("sh"));
		
		//IProject project = ((NewCProjectWizard) getWizard()).getNewProject();
		//MBSCustomPageManager.addPageProperty( PAGE_ID, "project", project);
	}

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

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

	public void createControl( Composite parent) {
		// Create UI elements
		mComposite = new Composite( parent, SWT.NULL);
		
		GridData gd = new GridData( GridData.FILL_BOTH);
		mComposite.setLayoutData( gd);
		
		GridLayout layout = new GridLayout();
		layout.numColumns = 3;
		mComposite.setLayout( layout);
		
		Label label = new Label( mComposite, SWT.LEFT);
		label.setText( "Installation path:");
		gd = new GridData( GridData.FILL_HORIZONTAL);
		gd.horizontalSpan = 3;
		label.setLayoutData( gd);
		
		mInstallationPath = new Text( mComposite, SWT.LEFT | SWT.BORDER);
		mInstallationPath.setText( "/opt/rtems-4.10");
		gd = new GridData( GridData.FILL_HORIZONTAL);
		gd.horizontalSpan = 2;
		mInstallationPath.setLayoutData( gd);
		
		Button button = new Button( mComposite, SWT.PUSH);
		button.setText( "Browse");
		button.addSelectionListener(
			new SelectionAdapter() {
				public void widgetSelected( SelectionEvent e) {
					browseForInstallationPath();
				}
			}
		);

		label = new Label( mComposite, SWT.LEFT);
		label.setText( "Version:");
		gd = new GridData( GridData.FILL_HORIZONTAL);
		gd.horizontalSpan = 3;
		label.setLayoutData( gd);

		mVersion = new Text( mComposite, SWT.RIGHT | SWT.BORDER);
		mVersion.setText( "4.10");
		gd = new GridData( GridData.FILL_HORIZONTAL);
		gd.horizontalSpan = 2;
		mVersion.setLayoutData( gd);
		
		new Label( mComposite, SWT.NONE);
		
		label = new Label( mComposite, SWT.LEFT);
		label.setText( "Target architecture:");
		gd = new GridData( GridData.FILL_HORIZONTAL);
		gd.horizontalSpan = 3;
		label.setLayoutData( gd);
		
		mTarget = new Combo( mComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
		Iterator<String> targets = mTargetMap.keySet().iterator();
		while (targets.hasNext()) {
			mTarget.add( (String) targets.next());
		}
		mTarget.select( mTarget.indexOf( "PowerPC"));
		gd = new GridData( GridData.FILL_HORIZONTAL);
		gd.horizontalSpan = 2;
		mTarget.setLayoutData( gd);
		
		new Label( mComposite, SWT.NONE);
		
		// Connect user input
		mInstallationPath.addModifyListener(
			new ModifyListener() {
				public void modifyText( ModifyEvent e) {
					installationPathChanged();
				}
			}
		);
		mVersion.addModifyListener(
			new ModifyListener() {
				public void modifyText( ModifyEvent e) {
					versionChanged();
				}
			}
		);
		mTarget.addSelectionListener(
			new SelectionAdapter() {
				public void widgetSelected( SelectionEvent e) {
					targetChanged();
				}
			}
		);
		
		// Trigger initial setup
		installationPathChanged();
		versionChanged();
		targetChanged();
	}

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

	public Control getControl() {
		return mComposite;
	}

	public String getDescription() {
		return "WARNING: This page is not useful.";
	}

	public String getErrorMessage() {
		return null;
	}

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

	public String getMessage() {
		return null;
	}

	public String getTitle() {
		return "Basic 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) {
		mComposite.setVisible( visible);
	}

	protected boolean isCustomPageComplete() {
		return true;
	}
	
	private void browseForInstallationPath() {
		DirectoryDialog dialog = new DirectoryDialog( mComposite.getShell(), SWT.NONE);
		dialog.setFilterPath( mInstallationPath.getText());
		String text = dialog.open();
		if (text != null) {
			mInstallationPath.setText( text);
		}
	}
	
	private void installationPathChanged() {
		MBSCustomPageManager.addPageProperty( pageID, "installationPath", mInstallationPath.getText());
	}
	
	private void versionChanged() {
		MBSCustomPageManager.addPageProperty( pageID, "version", mVersion.getText());
	}
	
	private void targetChanged() {
		MBSCustomPageManager.addPageProperty( pageID, "target", mTarget.getText());
	}
}