aboutsummaryrefslogtreecommitdiffstats
path: root/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/importProject/ConsolePage.java
blob: 86d58038e917c9331ac552751a8bad94607d3b14 (plain)
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
package org.openembedded.bc.ui.wizards.importProject;

import java.io.IOException;
import java.io.Writer;
import java.util.Map;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
import org.openembedded.bc.ui.Activator;
import org.openembedded.bc.ui.model.ProjectInfo;
import org.openembedded.bc.ui.wizards.FiniteStateWizardPage;
import org.openembedded.bc.ui.wizards.newproject.BBConfigurationInitializeOperation;


/**
 * Bitbake console view.
 * @author kgilmer
 *
 */
public class ConsolePage extends FiniteStateWizardPage {

	private boolean valid = false;
	
	public ConsolePage(Map model) {
		super("Bitbake Console Page", model);
		setTitle("Extracting BitBake Environment");
		setMessage("Output of 'bitbake -e' command, for verification purposes.");
	}

	private Text txtConsole;

	@Override
	public void createControl(Composite parent) {
		Composite top = new Composite(parent, SWT.NONE);
		top.setLayoutData(new GridData(GridData.FILL_BOTH));
		top.setLayout(new GridLayout());
		
		txtConsole = new Text(top, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
		txtConsole.setLayoutData(new GridData(GridData.FILL_BOTH));
		txtConsole.setEditable(false);
		txtConsole.setFont(JFaceResources.getFont(JFaceResources.TEXT_FONT));
		
		setControl(top);
	}

	@Override
	public void pageCleanup() {
		Activator.resetBBSession((String) model.get(ImportOEProjectWizard.KEY_LOCATION));
	}

	@Override
	public void pageDisplay() {
		ProjectInfo pinfo = new ProjectInfo();
		pinfo.setInitScriptPath((String) model.get(ImportOEProjectWizard.KEY_INITPATH));
		pinfo.setLocation((String) model.get(ImportOEProjectWizard.KEY_LOCATION));
		pinfo.setName((String) model.get(ImportOEProjectWizard.KEY_NAME));
		
		try {
			ConsoleWriter cw = new ConsoleWriter();
			this.getContainer().run(false, false, new BBConfigurationInitializeOperation(pinfo, cw));
			txtConsole.setText(cw.getContents());
		} catch (Exception e) {
			Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e));
			this.getContainer().getCurrentPage().setDescription("Failed to create project: " + e.getMessage());
			valid = false;
			setPageComplete(valid);
			return;
		} 
		valid = true;
		model.put(ImportOEProjectWizard.KEY_PINFO, pinfo);
		setPageComplete(valid);
	}

	@Override
	protected void updateModel() {
		
	}

	@Override
	protected boolean validatePage() {
		return valid;
	}
	
	private class ConsoleWriter extends Writer {

		private StringBuffer sb;

		public ConsoleWriter() {
			sb = new StringBuffer();
		}
		@Override
		public void close() throws IOException {			
		}
		
		public String getContents() {
			return sb.toString();
		}

		@Override
		public void flush() throws IOException {
		}

		@Override
		public void write(char[] cbuf, int off, int len) throws IOException {
			txtConsole.getText().concat(new String(cbuf));
		}
		
		@Override
		public void write(String str) throws IOException {
			sb.append(str);
		}
		
	}

}