summaryrefslogtreecommitdiffstats
path: root/org.rtems.cdt.toolchain2/org/rtems/cdt/wizards/BasicSetup.java
blob: 8846e6a1ff191ee333046d1794eae493978eb551 (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
/*
 * 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 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.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);
		mBasePath.setText( Storage.getPreference( Constants.BASE_PATH_KEY));
		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);
		mBSPPath.setText( Storage.getPreference( Constants.BSP_PATH_KEY));
		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) {
		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());
	}
}