summaryrefslogtreecommitdiffstats
path: root/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/importProject/ImportYoctoProjectWizard.java
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/importProject/ImportYoctoProjectWizard.java')
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/importProject/ImportYoctoProjectWizard.java166
1 files changed, 166 insertions, 0 deletions
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..b1fc841
--- /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) 2011 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 *******************************************************************************/
11package org.yocto.bc.ui.wizards.importProject;
12
13import java.io.IOException;
14import java.io.Writer;
15import java.util.Hashtable;
16import java.util.Map;
17
18import org.eclipse.core.runtime.IStatus;
19import org.eclipse.core.runtime.Status;
20import org.eclipse.jface.viewers.IStructuredSelection;
21import org.eclipse.ui.IImportWizard;
22import org.eclipse.ui.IWorkbench;
23import org.eclipse.ui.IWorkbenchPage;
24import org.eclipse.ui.IWorkbenchWindow;
25import org.eclipse.ui.PlatformUI;
26import org.eclipse.ui.console.ConsolePlugin;
27import org.eclipse.ui.console.IConsole;
28import org.eclipse.ui.console.IConsoleConstants;
29import org.eclipse.ui.console.IConsoleManager;
30import org.eclipse.ui.console.IConsoleView;
31import org.eclipse.ui.console.MessageConsole;
32
33import org.yocto.bc.ui.Activator;
34import org.yocto.bc.ui.model.ProjectInfo;
35import org.yocto.bc.ui.wizards.FiniteStateWizard;
36
37import org.yocto.bc.ui.wizards.newproject.BBConfigurationInitializeOperation;
38import org.yocto.bc.ui.wizards.newproject.CreateBBCProjectOperation;
39
40public 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.setLocation((String) 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.getRootPath(), 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}