diff options
author | Adrian Dudau <adrian.dudau@enea.com> | 2013-12-12 13:36:50 +0100 |
---|---|---|
committer | Adrian Dudau <adrian.dudau@enea.com> | 2013-12-12 15:25:03 +0100 |
commit | 41ac47d732eed8392d60d0f6773e5a279d49b999 (patch) | |
tree | cf19d099db9cfdb8d73aa21c31e7aa1cc86ff860 /plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/OptionsPage.java | |
download | eclipse-poky-juno-41ac47d732eed8392d60d0f6773e5a279d49b999.tar.gz |
Migrated from the internal git server on the dora-enea branch
Signed-off-by: Adrian Dudau <adrian.dudau@enea.com>
Diffstat (limited to 'plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/OptionsPage.java')
-rw-r--r-- | plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/OptionsPage.java | 247 |
1 files changed, 247 insertions, 0 deletions
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/OptionsPage.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/OptionsPage.java new file mode 100644 index 0000000..2844fda --- /dev/null +++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/OptionsPage.java | |||
@@ -0,0 +1,247 @@ | |||
1 | package org.yocto.bc.ui.wizards.install; | ||
2 | |||
3 | import java.io.IOException; | ||
4 | import java.io.File; | ||
5 | import java.net.URI; | ||
6 | import java.util.ArrayList; | ||
7 | import java.util.Hashtable; | ||
8 | import java.util.Iterator; | ||
9 | import java.util.List; | ||
10 | import java.util.Map; | ||
11 | |||
12 | import org.eclipse.core.resources.IProject; | ||
13 | import org.eclipse.core.resources.IProjectDescription; | ||
14 | import org.eclipse.core.resources.IResource; | ||
15 | import org.eclipse.core.resources.IWorkspaceRoot; | ||
16 | import org.eclipse.core.resources.ResourcesPlugin; | ||
17 | import org.eclipse.core.runtime.CoreException; | ||
18 | import org.eclipse.core.runtime.IStatus; | ||
19 | import org.eclipse.swt.SWT; | ||
20 | import org.eclipse.swt.events.SelectionAdapter; | ||
21 | import org.eclipse.swt.events.SelectionEvent; | ||
22 | import org.eclipse.swt.layout.GridData; | ||
23 | import org.eclipse.swt.layout.GridLayout; | ||
24 | import org.eclipse.swt.widgets.Button; | ||
25 | import org.eclipse.swt.widgets.Composite; | ||
26 | import org.eclipse.swt.widgets.Control; | ||
27 | import org.eclipse.swt.widgets.DirectoryDialog; | ||
28 | import org.eclipse.swt.widgets.FileDialog; | ||
29 | import org.eclipse.swt.widgets.Label; | ||
30 | import org.eclipse.swt.widgets.Text; | ||
31 | import org.eclipse.ui.PlatformUI; | ||
32 | |||
33 | import org.yocto.bc.ui.wizards.FiniteStateWizard; | ||
34 | import org.yocto.bc.ui.wizards.FiniteStateWizardPage; | ||
35 | import org.yocto.bc.ui.wizards.FiniteStateWizardPage.ValidationListener; | ||
36 | |||
37 | /** | ||
38 | * Select which flavor of OE is to be installed. | ||
39 | * | ||
40 | * @author kgilmer | ||
41 | * | ||
42 | * Setting up the parameters for creating the new Yocto Bitbake project | ||
43 | * | ||
44 | * @modified jzhang | ||
45 | */ | ||
46 | public class OptionsPage extends FiniteStateWizardPage { | ||
47 | |||
48 | private Map vars; | ||
49 | private Composite c1; | ||
50 | private Composite top; | ||
51 | |||
52 | private List controlList; | ||
53 | private boolean controlsCreated = false; | ||
54 | |||
55 | private Text txtProjectLocation; | ||
56 | |||
57 | private Text txtInit; | ||
58 | private ValidationListener validationListener; | ||
59 | private Text txtProjectName; | ||
60 | private Button gitButton; | ||
61 | |||
62 | protected OptionsPage(Map model) { | ||
63 | super("Options", model); | ||
64 | //setTitle("Create new yocto bitbake project"); | ||
65 | setMessage("Enter these parameters to create new Yocto Project BitBake commander project"); | ||
66 | } | ||
67 | |||
68 | @Override | ||
69 | public void createControl(Composite parent) { | ||
70 | top = new Composite(parent, SWT.None); | ||
71 | top.setLayout(new GridLayout()); | ||
72 | top.setLayoutData(new GridData(GridData.FILL_BOTH)); | ||
73 | |||
74 | GridData gdFillH = new GridData(GridData.FILL_HORIZONTAL); | ||
75 | GridData gdVU = new GridData(GridData.VERTICAL_ALIGN_BEGINNING); | ||
76 | |||
77 | Composite projectNameComp = new Composite(top, SWT.NONE); | ||
78 | GridData gdProjName = new GridData(GridData.FILL_HORIZONTAL); | ||
79 | projectNameComp.setLayoutData(gdProjName); | ||
80 | projectNameComp.setLayout(new GridLayout(2, false)); | ||
81 | Label lblProjectName = new Label(projectNameComp, SWT.NONE); | ||
82 | lblProjectName.setText("Project N&ame:"); | ||
83 | |||
84 | txtProjectName = new Text(projectNameComp, SWT.BORDER); | ||
85 | txtProjectName.setLayoutData(gdFillH); | ||
86 | txtProjectName.setFocus(); | ||
87 | validationListener = new ValidationListener(); | ||
88 | |||
89 | txtProjectName.addModifyListener(validationListener); | ||
90 | |||
91 | Label lblProjectLocation = new Label(projectNameComp, SWT.None); | ||
92 | lblProjectLocation.setText("&Project Location:"); | ||
93 | |||
94 | Composite locComposite = new Composite(projectNameComp, SWT.NONE); | ||
95 | GridData gd = new GridData(GridData.VERTICAL_ALIGN_END | ||
96 | | GridData.FILL_HORIZONTAL); | ||
97 | gd.horizontalIndent = 0; | ||
98 | locComposite.setLayoutData(gd); | ||
99 | GridLayout gl = new GridLayout(2, false); | ||
100 | gl.marginWidth = 0; | ||
101 | locComposite.setLayout(gl); | ||
102 | |||
103 | txtProjectLocation = new Text(locComposite, SWT.BORDER); | ||
104 | txtProjectLocation.setLayoutData(gdFillH); | ||
105 | txtProjectLocation.addModifyListener(validationListener); | ||
106 | |||
107 | Button button = new Button(locComposite, SWT.PUSH); | ||
108 | button.setText("Browse..."); | ||
109 | button.addSelectionListener(new SelectionAdapter() { | ||
110 | @Override | ||
111 | public void widgetSelected(SelectionEvent e) { | ||
112 | handleBrowse(); | ||
113 | } | ||
114 | }); | ||
115 | |||
116 | //Label lblGit = new Label(projectNameComp, SWT.None); | ||
117 | //lblGit.setText("Clone from &Git Repository?"); | ||
118 | |||
119 | Composite gitComposite = new Composite(projectNameComp, SWT.NONE); | ||
120 | gd = new GridData(GridData.VERTICAL_ALIGN_END | ||
121 | | GridData.FILL_HORIZONTAL); | ||
122 | gd.horizontalIndent = 0; | ||
123 | gitComposite.setLayoutData(gd); | ||
124 | gl = new GridLayout(1, false); | ||
125 | gl.marginWidth = 0; | ||
126 | gitComposite.setLayout(gl); | ||
127 | |||
128 | gitButton = new Button(gitComposite, SWT.CHECK); | ||
129 | gitButton.setText("Clone from Yocto Project &Git Repository"); | ||
130 | gitButton.setEnabled(true); | ||
131 | gitButton.addSelectionListener(validationListener); | ||
132 | |||
133 | setControl(top); | ||
134 | } | ||
135 | |||
136 | private void handleBrowse() { | ||
137 | DirectoryDialog dialog = new DirectoryDialog(getShell(), SWT.None); | ||
138 | String dir = dialog.open(); | ||
139 | if (dir != null) { | ||
140 | txtProjectLocation.setText(dir); | ||
141 | } | ||
142 | } | ||
143 | |||
144 | @Override | ||
145 | public void pageCleanup() { | ||
146 | |||
147 | } | ||
148 | |||
149 | @Override | ||
150 | public void pageDisplay() { | ||
151 | } | ||
152 | |||
153 | @Override | ||
154 | |||
155 | protected void updateModel() { | ||
156 | model.put(InstallWizard.INSTALL_DIRECTORY, txtProjectLocation.getText()+File.separator+txtProjectName.getText()); | ||
157 | model.put(InstallWizard.PROJECT_NAME, txtProjectName.getText()); | ||
158 | model.put(InstallWizard.GIT_CLONE, new Boolean(gitButton.getSelection())); | ||
159 | } | ||
160 | |||
161 | private boolean isValidProjectName(String projectName) { | ||
162 | if (projectName.indexOf('$') > -1) { | ||
163 | return false; | ||
164 | } | ||
165 | |||
166 | return true; | ||
167 | } | ||
168 | @Override | ||
169 | protected boolean validatePage() { | ||
170 | IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot(); | ||
171 | |||
172 | IStatus validate = ResourcesPlugin.getWorkspace().validateName(txtProjectName.getText(), IResource.PROJECT); | ||
173 | |||
174 | if (!validate.isOK() || !isValidProjectName(txtProjectName.getText())) { | ||
175 | setErrorMessage("Invalid project name: " + txtProjectName.getText()); | ||
176 | return false; | ||
177 | } | ||
178 | |||
179 | IProject proj = wsroot.getProject(txtProjectName.getText()); | ||
180 | if (proj.exists()) { | ||
181 | setErrorMessage("A project with the name " + txtProjectName.getText() | ||
182 | + " already exists"); | ||
183 | return false; | ||
184 | } | ||
185 | |||
186 | String projectLoc = txtProjectLocation.getText(); | ||
187 | File checkProject_dir = new File(projectLoc); | ||
188 | if (!checkProject_dir.isDirectory()) { | ||
189 | setErrorMessage("The project location directory " + txtProjectLocation.getText() + " is not valid"); | ||
190 | return false; | ||
191 | } | ||
192 | |||
193 | String projectPath = projectLoc + File.separator+txtProjectName.getText(); | ||
194 | File git_dir=new File(projectPath); | ||
195 | if(!gitButton.getSelection()) { | ||
196 | if(!git_dir.isDirectory() || !git_dir.exists()) { | ||
197 | setErrorMessage("Directory " + txtProjectLocation.getText()+File.separator+txtProjectName.getText() + " does not exist, please select git clone."); | ||
198 | return false; | ||
199 | }else if(!new File(projectPath + File.separator + InstallWizard.VALIDATION_FILE).exists()) { | ||
200 | setErrorMessage("Directory " + txtProjectLocation.getText()+File.separator+txtProjectName.getText() + " seems invalid, please use other directory or project name."); | ||
201 | return false; | ||
202 | } | ||
203 | }else { | ||
204 | // git check | ||
205 | if(git_dir.exists()) { | ||
206 | setErrorMessage("Directory " + txtProjectLocation.getText()+File.separator+txtProjectName.getText() + " exists, please unselect git clone."); | ||
207 | return false; | ||
208 | } | ||
209 | } | ||
210 | |||
211 | try { | ||
212 | URI location = new URI("file://" + txtProjectLocation.getText()+File.separator+txtProjectName.getText()); | ||
213 | |||
214 | IStatus status = ResourcesPlugin.getWorkspace().validateProjectLocationURI(proj, location); | ||
215 | if (!status.isOK()) { | ||
216 | setErrorMessage(status.getMessage()); | ||
217 | return false; | ||
218 | } | ||
219 | } catch (Exception e) { | ||
220 | setErrorMessage("Run into error while trying to validate entries!"); | ||
221 | return false; | ||
222 | } | ||
223 | setErrorMessage(null); | ||
224 | setMessage("All the entries are valid, press \"Finish\" to start the process, "+ | ||
225 | "this will take a while. Please don't interrupt till there's output in the Yocto Console window..."); | ||
226 | return true; | ||
227 | } | ||
228 | |||
229 | private class FileOpenSelectionAdapter extends SelectionAdapter { | ||
230 | @Override | ||
231 | public void widgetSelected(SelectionEvent e) { | ||
232 | FileDialog fd = new FileDialog(PlatformUI.getWorkbench() | ||
233 | .getDisplay().getActiveShell(), SWT.OPEN); | ||
234 | |||
235 | fd.setText("Open Configuration Script"); | ||
236 | fd.setFilterPath(txtProjectLocation.getText()); | ||
237 | |||
238 | String selected = fd.open(); | ||
239 | |||
240 | if (selected != null) { | ||
241 | txtInit.setText(selected); | ||
242 | updateModel(); | ||
243 | } | ||
244 | } | ||
245 | } | ||
246 | |||
247 | } | ||