diff options
author | Ken Gilmer <kgilmer@gmail.com> | 2010-05-18 21:53:22 -0400 |
---|---|---|
committer | Ken Gilmer <kgilmer@gmail.com> | 2010-05-18 21:53:22 -0400 |
commit | a7e84830627e50adac5c81ae4dad69aa350933fb (patch) | |
tree | 219aa86f4d5f03b29d7bc56f8cdba2702d67082c /org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/importProject | |
parent | e27a6dcce13930bfa711a6e72992597a8d1d07c5 (diff) | |
download | eclipsetools-a7e84830627e50adac5c81ae4dad69aa350933fb.tar.gz |
org.openembedded.bc.ui: initial commit
Diffstat (limited to 'org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/importProject')
3 files changed, 418 insertions, 0 deletions
diff --git a/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/importProject/BBCProjectPage.java b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/importProject/BBCProjectPage.java new file mode 100644 index 0000000..44198aa --- /dev/null +++ b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/importProject/BBCProjectPage.java @@ -0,0 +1,234 @@ +/***************************************************************************** + * Copyright (c) 2009 Ken Gilmer + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ken Gilmer - initial API and implementation + *******************************************************************************/ +package org.openembedded.bc.ui.wizards.importProject; + +import java.io.File; +import java.util.Map; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.DirectoryDialog; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.PlatformUI; +import org.openembedded.bc.ui.wizards.FiniteStateWizardPage; + + +/** + * Main property page for new project wizard. + * @author kgilmer + * + */ +public class BBCProjectPage extends FiniteStateWizardPage { + + private class FileOpenSelectionAdapter extends SelectionAdapter { + @Override + public void widgetSelected(SelectionEvent e) { + FileDialog fd = new FileDialog(PlatformUI.getWorkbench() + .getDisplay().getActiveShell(), SWT.OPEN); + + fd.setText("Open Configuration Script"); + fd.setFilterPath(txtProjectLocation.getText()); + + String selected = fd.open(); + + if (selected != null) { + txtInit.setText(selected); + updateModel(); + } + } + } + public static final String PAGE_TITLE = "BitBake Commander Project"; + private Text txtProjectLocation; + + private Text txtInit; + private ValidationListener validationListener; + private Text txtProjectName; + + public BBCProjectPage(Map model) { + super(PAGE_TITLE, model); + setMessage("Enter information to create a BitBake Commander project."); + } + + public void createControl(Composite parent) { + GridData gdFillH = new GridData(GridData.FILL_HORIZONTAL); + GridData gdVU = new GridData(GridData.VERTICAL_ALIGN_BEGINNING); + + Composite top = new Composite(parent, SWT.NONE); + top.setLayoutData(new GridData(GridData.FILL_BOTH)); + top.setLayout(new GridLayout()); + + Composite projectNameComp = new Composite(top, SWT.NONE); + GridData gdProjName = new GridData(GridData.FILL_HORIZONTAL); + projectNameComp.setLayoutData(gdProjName); + projectNameComp.setLayout(new GridLayout(2, false)); + Label lblProjectName = new Label(projectNameComp, SWT.NONE); + lblProjectName.setText("N&ame:"); + + txtProjectName = new Text(projectNameComp, SWT.BORDER); + txtProjectName.setLayoutData(gdFillH); + txtProjectName.setFocus(); + validationListener = new ValidationListener(); + + txtProjectName.addModifyListener(validationListener); + + Label lblProjectLocation = new Label(projectNameComp, SWT.None); + lblProjectLocation.setText("&Location:"); + + Composite locComposite = new Composite(projectNameComp, SWT.NONE); + GridData gd = new GridData(GridData.VERTICAL_ALIGN_END + | GridData.FILL_HORIZONTAL); + gd.horizontalIndent = 0; + locComposite.setLayoutData(gd); + GridLayout gl = new GridLayout(2, false); + gl.marginWidth = 0; + locComposite.setLayout(gl); + + txtProjectLocation = new Text(locComposite, SWT.BORDER); + txtProjectLocation.setLayoutData(gdFillH); + txtProjectLocation.addModifyListener(validationListener); + + Button button = new Button(locComposite, SWT.PUSH); + button.setText("Browse..."); + button.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + handleBrowse(); + } + }); + + Label lblInit = new Label(projectNameComp, SWT.NONE); + lblInit.setText("Init Script:"); + + Composite initComposite = new Composite(projectNameComp, SWT.NONE); + gd = new GridData(GridData.VERTICAL_ALIGN_END + | GridData.FILL_HORIZONTAL); + gd.horizontalIndent = 0; + initComposite.setLayoutData(gd); + gl = new GridLayout(2, false); + gl.marginWidth = 0; + initComposite.setLayout(gl); + + txtInit = new Text(initComposite, SWT.BORDER); + GridData gdi = new GridData(GridData.FILL_HORIZONTAL); + txtInit.setLayoutData(gdi); + txtInit.addModifyListener(validationListener); + + Button btnLoadInit = new Button(initComposite, SWT.PUSH); + btnLoadInit.setLayoutData(gdVU); + btnLoadInit.setText("Choose..."); + btnLoadInit.addSelectionListener(new FileOpenSelectionAdapter()); + + if (System.getenv("OEROOT") != null) { + txtProjectLocation.setText(System.getenv("OEROOT")); + } + + setControl(top); + } + + private void handleBrowse() { + DirectoryDialog dialog = new DirectoryDialog(getShell(), SWT.None); + String dir = dialog.open(); + if (dir != null) { + txtProjectLocation.setText(dir); + } + } + + private String getFileSegment(String initScriptPath) { + //return the first segment of " " seperated array, or full string if no " " exists + return initScriptPath.split(" ")[0]; + } + + private boolean isValidProjectName(String projectName) { + if (projectName.indexOf('$') > -1) { + return false; + } + + return true; + } + + + @Override + public void pageCleanup() { + // TODO Auto-generated method stub + + } + + @Override + public void pageDisplay() { + // TODO Auto-generated method stub + + } + + @Override + protected void updateModel() { + model.put(ImportOEProjectWizard.KEY_NAME, txtProjectName.getText()); + model.put(ImportOEProjectWizard.KEY_LOCATION, txtProjectLocation.getText()); + model.put(ImportOEProjectWizard.KEY_INITPATH, txtInit.getText()); + } + + + @Override + protected boolean validatePage() { + IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot(); + + IStatus validate = ResourcesPlugin.getWorkspace().validateName(txtProjectName.getText(), IResource.PROJECT); + + if (!validate.isOK() || !isValidProjectName(txtProjectName.getText())) { + setErrorMessage("Invalid project name: " + txtProjectName.getText()); + return false; + } + + IProject proj = wsroot.getProject(txtProjectName.getText()); + if (proj.exists()) { + setErrorMessage("A project with the name " + txtProjectName.getText() + + " already exists"); + return false; + } + + if (txtProjectLocation.getText().trim().length() == 0) { + setErrorMessage("Set directory to an OpenEmbedded or Poky project root (OEROOT)"); + return false; + } + + File f = new File(txtProjectLocation.getText()); + if (!f.exists() || !f.isDirectory()) { + setErrorMessage("Invalid Directory"); + return false; + } + + if (txtInit.getText().length() == 0) { + setErrorMessage("Set configuration file before bitbake is launched."); + return false; + } + + File f2 = new File(getFileSegment(txtInit.getText())); + if (!f2.exists() || f2.isDirectory()) { + setErrorMessage("The configuration file is invalid."); + return false; + } + + setErrorMessage(null); + + return true; + } +} diff --git a/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/importProject/ConsolePage.java b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/importProject/ConsolePage.java new file mode 100644 index 0000000..86d5803 --- /dev/null +++ b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/importProject/ConsolePage.java @@ -0,0 +1,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); + } + + } + +} diff --git a/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/importProject/ImportOEProjectWizard.java b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/importProject/ImportOEProjectWizard.java new file mode 100644 index 0000000..b810fe7 --- /dev/null +++ b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/importProject/ImportOEProjectWizard.java @@ -0,0 +1,63 @@ +package org.openembedded.bc.ui.wizards.importProject; + +import java.util.Hashtable; +import java.util.Map; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IImportWizard; +import org.eclipse.ui.IWorkbench; +import org.openembedded.bc.ui.Activator; +import org.openembedded.bc.ui.model.ProjectInfo; +import org.openembedded.bc.ui.wizards.FiniteStateWizard; +import org.openembedded.bc.ui.wizards.newproject.CreateBBCProjectOperation; + + +public class ImportOEProjectWizard extends FiniteStateWizard implements IImportWizard { + protected final static String KEY_OEROOT = "OEROOT"; + public static final String KEY_NAME = "NAME"; + public static final String KEY_LOCATION = "LOCATION"; + public static final String KEY_INITPATH = "INITPATH"; + protected static final String KEY_PINFO = "PINFO"; + + private Map projectModel; + private IWorkbench workbench; + private IStructuredSelection selection; + + public ImportOEProjectWizard() { + projectModel = new Hashtable(); + } + + public Map getModel() { + return projectModel; + } + + @Override + public void addPages() { + addPage(new BBCProjectPage(projectModel)); + addPage(new ConsolePage(projectModel)); + } + + + public boolean performFinish() { + ProjectInfo pinfo = (ProjectInfo) projectModel.get(KEY_PINFO); + Activator.putProjInfo(pinfo.getRootPath(), pinfo); + try { + getContainer().run(false, false, new CreateBBCProjectOperation(pinfo)); + } 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()); + return false; + } + + return true; + } + + public void init(IWorkbench workbench, IStructuredSelection selection) { + this.workbench = workbench; + this.selection = selection; + this.setNeedsProgressMonitor(true); + setWindowTitle("BitBake Commander Project"); + } +} |