diff options
author | Adrian Dudau <adrian.dudau@enea.com> | 2014-06-26 13:23:09 +0200 |
---|---|---|
committer | Adrian Dudau <adrian.dudau@enea.com> | 2014-06-26 13:24:09 +0200 |
commit | c7da892cb23d50d4d85746c9a0b6b14bf570989d (patch) | |
tree | e7136073f386d6156f51766c498c52c30c8df85f /plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/importProject | |
download | eclipse-poky-kepler-daisy.tar.gz |
initial commit for Enea Linux 4.0daisy
Migrated from the internal git server on the daisy-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/importProject')
2 files changed, 402 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 | *******************************************************************************/ | ||
11 | package org.yocto.bc.ui.wizards.importProject; | ||
12 | |||
13 | import java.io.File; | ||
14 | import java.util.Map; | ||
15 | |||
16 | import org.eclipse.core.resources.IProject; | ||
17 | import org.eclipse.core.resources.IResource; | ||
18 | import org.eclipse.core.resources.IWorkspaceRoot; | ||
19 | import org.eclipse.core.resources.ResourcesPlugin; | ||
20 | import org.eclipse.core.runtime.IStatus; | ||
21 | import org.eclipse.swt.SWT; | ||
22 | import org.eclipse.swt.events.SelectionAdapter; | ||
23 | import org.eclipse.swt.events.SelectionEvent; | ||
24 | import org.eclipse.swt.layout.GridData; | ||
25 | import org.eclipse.swt.layout.GridLayout; | ||
26 | import org.eclipse.swt.widgets.Button; | ||
27 | import org.eclipse.swt.widgets.Composite; | ||
28 | import org.eclipse.swt.widgets.DirectoryDialog; | ||
29 | import org.eclipse.swt.widgets.FileDialog; | ||
30 | import org.eclipse.swt.widgets.Label; | ||
31 | import org.eclipse.swt.widgets.Text; | ||
32 | import org.eclipse.ui.PlatformUI; | ||
33 | |||
34 | import org.yocto.bc.ui.wizards.FiniteStateWizardPage; | ||
35 | |||
36 | /** | ||
37 | * Main property page for new project wizard. | ||
38 | * @author kgilmer | ||
39 | * | ||
40 | */ | ||
41 | public 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 | } | ||
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/importProject/ImportYoctoProjectWizard.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/importProject/ImportYoctoProjectWizard.java new file mode 100644 index 0000000..75f1763 --- /dev/null +++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/importProject/ImportYoctoProjectWizard.java | |||
@@ -0,0 +1,166 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2013 Intel Corporation. | ||
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 | * Intel - initial API and implementation | ||
10 | * Ioana Grigoropol (Intel) - adapt class for remote support | ||
11 | *******************************************************************************/ | ||
12 | package org.yocto.bc.ui.wizards.importProject; | ||
13 | |||
14 | import java.io.IOException; | ||
15 | import java.io.Writer; | ||
16 | import java.net.URI; | ||
17 | import java.util.Hashtable; | ||
18 | import java.util.Map; | ||
19 | |||
20 | import org.eclipse.core.runtime.IStatus; | ||
21 | import org.eclipse.core.runtime.Status; | ||
22 | import org.eclipse.jface.viewers.IStructuredSelection; | ||
23 | import org.eclipse.ui.IImportWizard; | ||
24 | import org.eclipse.ui.IWorkbench; | ||
25 | import org.eclipse.ui.IWorkbenchPage; | ||
26 | import org.eclipse.ui.IWorkbenchWindow; | ||
27 | import org.eclipse.ui.PlatformUI; | ||
28 | import org.eclipse.ui.console.ConsolePlugin; | ||
29 | import org.eclipse.ui.console.IConsole; | ||
30 | import org.eclipse.ui.console.IConsoleConstants; | ||
31 | import org.eclipse.ui.console.IConsoleManager; | ||
32 | import org.eclipse.ui.console.IConsoleView; | ||
33 | import org.eclipse.ui.console.MessageConsole; | ||
34 | import org.yocto.bc.ui.Activator; | ||
35 | import org.yocto.bc.ui.model.ProjectInfo; | ||
36 | import org.yocto.bc.ui.wizards.FiniteStateWizard; | ||
37 | import org.yocto.bc.ui.wizards.newproject.BBConfigurationInitializeOperation; | ||
38 | import org.yocto.bc.ui.wizards.newproject.CreateBBCProjectOperation; | ||
39 | |||
40 | public class ImportYoctoProjectWizard extends FiniteStateWizard implements IImportWizard { | ||
41 | protected final static String KEY_OEROOT = "OEROOT"; | ||
42 | public static final String KEY_NAME = "NAME"; | ||
43 | public static final String KEY_LOCATION = "LOCATION"; | ||
44 | public static final String KEY_INITPATH = "INITPATH"; | ||
45 | protected static final String KEY_PINFO = "PINFO"; | ||
46 | |||
47 | private Map projectModel; | ||
48 | private IWorkbench workbench; | ||
49 | private IStructuredSelection selection; | ||
50 | |||
51 | private MessageConsole myConsole; | ||
52 | |||
53 | public ImportYoctoProjectWizard() { | ||
54 | projectModel = new Hashtable(); | ||
55 | } | ||
56 | |||
57 | public Map getModel() { | ||
58 | return projectModel; | ||
59 | } | ||
60 | |||
61 | @Override | ||
62 | public void addPages() { | ||
63 | addPage(new BBCProjectPage(projectModel)); | ||
64 | //addPage(new ConsolePage(projectModel)); | ||
65 | } | ||
66 | |||
67 | |||
68 | public boolean performFinish() { | ||
69 | ProjectInfo pinfo = new ProjectInfo(); | ||
70 | pinfo.setInitScriptPath((String) projectModel.get(ImportYoctoProjectWizard.KEY_INITPATH)); | ||
71 | pinfo.setLocationURI((URI) projectModel.get(ImportYoctoProjectWizard.KEY_LOCATION)); | ||
72 | pinfo.setName((String) projectModel.get(ImportYoctoProjectWizard.KEY_NAME)); | ||
73 | |||
74 | try { | ||
75 | ConsoleWriter cw = new ConsoleWriter(); | ||
76 | this.getContainer().run(false, false, new BBConfigurationInitializeOperation(pinfo, cw)); | ||
77 | myConsole.newMessageStream().println(cw.getContents()); | ||
78 | } catch (Exception e) { | ||
79 | Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e)); | ||
80 | this.getContainer().getCurrentPage().setDescription("Failed to create project: " + e.getMessage()); | ||
81 | //valid = false; | ||
82 | //setPageComplete(valid); | ||
83 | return false; | ||
84 | } | ||
85 | |||
86 | //valid = true; | ||
87 | projectModel.put(ImportYoctoProjectWizard.KEY_PINFO, pinfo); | ||
88 | //setPageComplete(valid); | ||
89 | //ProjectInfo pinfo = (ProjectInfo) projectModel.get(KEY_PINFO); | ||
90 | Activator.putProjInfo(pinfo.getOEFSURI(), pinfo); | ||
91 | try { | ||
92 | getContainer().run(false, false, new CreateBBCProjectOperation(pinfo)); | ||
93 | } catch (Exception e) { | ||
94 | Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e)); | ||
95 | this.getContainer().getCurrentPage().setDescription("Failed to create project: " + e.getMessage()); | ||
96 | return false; | ||
97 | } | ||
98 | |||
99 | return true; | ||
100 | } | ||
101 | |||
102 | public void init(IWorkbench workbench, IStructuredSelection selection) { | ||
103 | this.workbench = workbench; | ||
104 | this.selection = selection; | ||
105 | this.setNeedsProgressMonitor(true); | ||
106 | setWindowTitle("BitBake Commander Project"); | ||
107 | |||
108 | myConsole = findConsole("Yocto Console"); | ||
109 | IWorkbench wb = PlatformUI.getWorkbench(); | ||
110 | IWorkbenchWindow win = wb.getActiveWorkbenchWindow(); | ||
111 | IWorkbenchPage page = win.getActivePage(); | ||
112 | String id = IConsoleConstants.ID_CONSOLE_VIEW; | ||
113 | try { | ||
114 | IConsoleView view = (IConsoleView) page.showView(id); | ||
115 | view.display(myConsole); | ||
116 | } catch (Exception e) { | ||
117 | e.printStackTrace(); | ||
118 | } | ||
119 | } | ||
120 | |||
121 | private MessageConsole findConsole(String name) { | ||
122 | ConsolePlugin plugin = ConsolePlugin.getDefault(); | ||
123 | IConsoleManager conMan = plugin.getConsoleManager(); | ||
124 | IConsole[] existing = conMan.getConsoles(); | ||
125 | for (int i = 0; i < existing.length; i++) | ||
126 | if (name.equals(existing[i].getName())) | ||
127 | return (MessageConsole) existing[i]; | ||
128 | // no console found, so create a new one | ||
129 | MessageConsole myConsole = new MessageConsole(name, null); | ||
130 | conMan.addConsoles(new IConsole[] { myConsole }); | ||
131 | return myConsole; | ||
132 | } | ||
133 | |||
134 | private class ConsoleWriter extends Writer { | ||
135 | |||
136 | private StringBuffer sb; | ||
137 | |||
138 | public ConsoleWriter() { | ||
139 | sb = new StringBuffer(); | ||
140 | } | ||
141 | @Override | ||
142 | public void close() throws IOException { | ||
143 | } | ||
144 | |||
145 | public String getContents() { | ||
146 | return sb.toString(); | ||
147 | } | ||
148 | |||
149 | @Override | ||
150 | public void flush() throws IOException { | ||
151 | } | ||
152 | |||
153 | @Override | ||
154 | public void write(char[] cbuf, int off, int len) throws IOException { | ||
155 | //txtConsole.getText().concat(new String(cbuf)); | ||
156 | sb.append(cbuf); | ||
157 | } | ||
158 | |||
159 | @Override | ||
160 | public void write(String str) throws IOException { | ||
161 | sb.append(str); | ||
162 | } | ||
163 | |||
164 | } | ||
165 | |||
166 | } | ||