summaryrefslogtreecommitdiffstats
path: root/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/importProject/BBCProjectPage.java
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/importProject/BBCProjectPage.java')
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/importProject/BBCProjectPage.java236
1 files changed, 236 insertions, 0 deletions
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/importProject/BBCProjectPage.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/importProject/BBCProjectPage.java
new file mode 100644
index 0000000..71ea70c
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/importProject/BBCProjectPage.java
@@ -0,0 +1,236 @@
1/*****************************************************************************
2 * Copyright (c) 2009 Ken Gilmer
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Ken Gilmer - initial API and implementation
10 *******************************************************************************/
11package org.yocto.bc.ui.wizards.importProject;
12
13import java.io.File;
14import java.util.Map;
15
16import org.eclipse.core.resources.IProject;
17import org.eclipse.core.resources.IResource;
18import org.eclipse.core.resources.IWorkspaceRoot;
19import org.eclipse.core.resources.ResourcesPlugin;
20import org.eclipse.core.runtime.IStatus;
21import org.eclipse.swt.SWT;
22import org.eclipse.swt.events.SelectionAdapter;
23import org.eclipse.swt.events.SelectionEvent;
24import org.eclipse.swt.layout.GridData;
25import org.eclipse.swt.layout.GridLayout;
26import org.eclipse.swt.widgets.Button;
27import org.eclipse.swt.widgets.Composite;
28import org.eclipse.swt.widgets.DirectoryDialog;
29import org.eclipse.swt.widgets.FileDialog;
30import org.eclipse.swt.widgets.Label;
31import org.eclipse.swt.widgets.Text;
32import org.eclipse.ui.PlatformUI;
33
34import org.yocto.bc.ui.wizards.FiniteStateWizardPage;
35
36/**
37 * Main property page for new project wizard.
38 * @author kgilmer
39 *
40 */
41public class BBCProjectPage extends FiniteStateWizardPage {
42
43 private class FileOpenSelectionAdapter extends SelectionAdapter {
44 @Override
45 public void widgetSelected(SelectionEvent e) {
46 FileDialog fd = new FileDialog(PlatformUI.getWorkbench()
47 .getDisplay().getActiveShell(), SWT.OPEN);
48
49 fd.setText("Open Configuration Script");
50 fd.setFilterPath(txtProjectLocation.getText());
51
52 String selected = fd.open();
53
54 if (selected != null) {
55 txtInit.setText(selected);
56 updateModel();
57 }
58 }
59 }
60 public static final String PAGE_TITLE = "Yocto Project BitBake Commander Project";
61 private Text txtProjectLocation;
62
63 private Text txtInit;
64 private ValidationListener validationListener;
65 private Text txtProjectName;
66
67 public BBCProjectPage(Map model) {
68 super(PAGE_TITLE, model);
69 setTitle("Create new Yocto Project BitBake Commander project");
70 setMessage("Enter information to create a BitBake Commander project.");
71 }
72
73 public void createControl(Composite parent) {
74 GridData gdFillH = new GridData(GridData.FILL_HORIZONTAL);
75 GridData gdVU = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
76
77 Composite top = new Composite(parent, SWT.NONE);
78 top.setLayoutData(new GridData(GridData.FILL_BOTH));
79 top.setLayout(new GridLayout());
80
81 Composite projectNameComp = new Composite(top, SWT.NONE);
82 GridData gdProjName = new GridData(GridData.FILL_HORIZONTAL);
83 projectNameComp.setLayoutData(gdProjName);
84 projectNameComp.setLayout(new GridLayout(2, false));
85 Label lblProjectName = new Label(projectNameComp, SWT.NONE);
86 lblProjectName.setText("N&ame:");
87
88 txtProjectName = new Text(projectNameComp, SWT.BORDER);
89 txtProjectName.setLayoutData(gdFillH);
90 txtProjectName.setFocus();
91 validationListener = new ValidationListener();
92
93 txtProjectName.addModifyListener(validationListener);
94
95 Label lblProjectLocation = new Label(projectNameComp, SWT.None);
96 lblProjectLocation.setText("&Location:");
97
98 Composite locComposite = new Composite(projectNameComp, SWT.NONE);
99 GridData gd = new GridData(GridData.VERTICAL_ALIGN_END
100 | GridData.FILL_HORIZONTAL);
101 gd.horizontalIndent = 0;
102 locComposite.setLayoutData(gd);
103 GridLayout gl = new GridLayout(2, false);
104 gl.marginWidth = 0;
105 locComposite.setLayout(gl);
106
107 txtProjectLocation = new Text(locComposite, SWT.BORDER);
108 txtProjectLocation.setLayoutData(gdFillH);
109 txtProjectLocation.addModifyListener(validationListener);
110
111 Button button = new Button(locComposite, SWT.PUSH);
112 button.setText("Browse...");
113 button.addSelectionListener(new SelectionAdapter() {
114 @Override
115 public void widgetSelected(SelectionEvent e) {
116 handleBrowse();
117 }
118 });
119
120 Label lblInit = new Label(projectNameComp, SWT.NONE);
121 lblInit.setText("Init Script:");
122
123 Composite initComposite = new Composite(projectNameComp, SWT.NONE);
124 gd = new GridData(GridData.VERTICAL_ALIGN_END
125 | GridData.FILL_HORIZONTAL);
126 gd.horizontalIndent = 0;
127 initComposite.setLayoutData(gd);
128 gl = new GridLayout(2, false);
129 gl.marginWidth = 0;
130 initComposite.setLayout(gl);
131
132 txtInit = new Text(initComposite, SWT.BORDER);
133 GridData gdi = new GridData(GridData.FILL_HORIZONTAL);
134 txtInit.setLayoutData(gdi);
135 txtInit.addModifyListener(validationListener);
136
137 Button btnLoadInit = new Button(initComposite, SWT.PUSH);
138 btnLoadInit.setLayoutData(gdVU);
139 btnLoadInit.setText("Choose...");
140 btnLoadInit.addSelectionListener(new FileOpenSelectionAdapter());
141
142 if (System.getenv("OEROOT") != null) {
143 txtProjectLocation.setText(System.getenv("OEROOT"));
144 }
145
146 setControl(top);
147 }
148
149 private void handleBrowse() {
150 DirectoryDialog dialog = new DirectoryDialog(getShell(), SWT.None);
151 String dir = dialog.open();
152 if (dir != null) {
153 txtProjectLocation.setText(dir);
154 }
155 }
156
157 private String getFileSegment(String initScriptPath) {
158 //return the first segment of " " seperated array, or full string if no " " exists
159 return initScriptPath.split(" ")[0];
160 }
161
162 private boolean isValidProjectName(String projectName) {
163 if (projectName.indexOf('$') > -1) {
164 return false;
165 }
166
167 return true;
168 }
169
170
171 @Override
172 public void pageCleanup() {
173 // TODO Auto-generated method stub
174
175 }
176
177 @Override
178 public void pageDisplay() {
179 // TODO Auto-generated method stub
180
181 }
182
183 @Override
184 protected void updateModel() {
185 model.put(ImportYoctoProjectWizard.KEY_NAME, txtProjectName.getText());
186 model.put(ImportYoctoProjectWizard.KEY_LOCATION, txtProjectLocation.getText());
187 model.put(ImportYoctoProjectWizard.KEY_INITPATH, txtInit.getText());
188 }
189
190
191 @Override
192 protected boolean validatePage() {
193 IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot();
194
195 IStatus validate = ResourcesPlugin.getWorkspace().validateName(txtProjectName.getText(), IResource.PROJECT);
196
197 if (!validate.isOK() || !isValidProjectName(txtProjectName.getText())) {
198 setErrorMessage("Invalid project name: " + txtProjectName.getText());
199 return false;
200 }
201
202 IProject proj = wsroot.getProject(txtProjectName.getText());
203 if (proj.exists()) {
204 setErrorMessage("A project with the name " + txtProjectName.getText()
205 + " already exists");
206 return false;
207 }
208
209 if (txtProjectLocation.getText().trim().length() == 0) {
210 setErrorMessage("Set directory that contains Poky tree");
211 return false;
212 }
213
214 File f = new File(txtProjectLocation.getText());
215 if (!f.exists() || !f.isDirectory()) {
216 setErrorMessage("Invalid Directory");
217 return false;
218 }
219
220 if (txtInit.getText().length() == 0) {
221 setErrorMessage("Set configuration file before BitBake is launched.");
222 return false;
223 }
224
225 File f2 = new File(getFileSegment(txtInit.getText()));
226 if (!f2.exists() || f2.isDirectory()) {
227 setErrorMessage("The configuration file is invalid.");
228 return false;
229 }
230
231 setErrorMessage(null);
232 setMessage("All the entries are valid, press \"Finish\" to create the new yocto bitbake project,"+
233 "this will take a while. Please don't interrupt till there's output in the Yocto Console window...");
234 return true;
235 }
236}