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 | |
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')
22 files changed, 3155 insertions, 0 deletions
diff --git a/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/FiniteStateWizard.java b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/FiniteStateWizard.java new file mode 100644 index 0000000..575b3ec --- /dev/null +++ b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/FiniteStateWizard.java @@ -0,0 +1,56 @@ +package org.openembedded.bc.ui.wizards;
+import java.util.Map;
+
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.swt.widgets.Composite;
+
+
+
+public abstract class FiniteStateWizard extends Wizard {
+ private boolean finishable = false;
+ private boolean canFinish;
+
+ public FiniteStateWizard() {
+ }
+
+ public abstract boolean performFinish();
+
+ /**
+ * @return Returns if the wizard is finishable in its current state.
+ */
+ public boolean isFinishable() {
+ return finishable;
+ }
+ /**
+ * @param finishable Change the finish state of the wizard.
+ */
+ public void setFinishable(boolean finishable) {
+ this.finishable = finishable;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.wizard.IWizard#createPageControls(org.eclipse.swt.widgets.Composite)
+ */
+ public void createPageControls(Composite pageContainer) {
+ super.createPageControls(pageContainer);
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IWizard.
+ */
+ public boolean canFinish() {
+ if (canFinish)
+ return true;
+ return super.canFinish();
+ }
+
+ public void setCanFinish(boolean canFinish) {
+ this.canFinish = canFinish;
+ }
+
+ /**
+ * Retrive the model object from the wizard.
+ * @return
+ */
+ public abstract Map getModel();
+}
diff --git a/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/FiniteStateWizardPage.java b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/FiniteStateWizardPage.java new file mode 100644 index 0000000..4a26d13 --- /dev/null +++ b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/FiniteStateWizardPage.java @@ -0,0 +1,148 @@ +package org.openembedded.bc.ui.wizards;
+import java.util.Map;
+
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+
+public abstract class FiniteStateWizardPage extends WizardPage {
+ protected Map model = null;
+ protected FiniteStateWizard wizard = null;
+ private static boolean previousState = false;
+ /**
+ * @param pageName
+ */
+ protected FiniteStateWizardPage(String name, Map model) {
+ super(name);
+ this.model = model;
+ this.setPageComplete(false);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
+ */
+ public abstract void createControl(Composite parent);
+
+ protected void setModelWizard() {
+ if (wizard == null) {
+ wizard = (FiniteStateWizard)FiniteStateWizardPage.this.getWizard();
+ }
+ }
+
+ /**
+ * Add page validation logic here. Returning <code>true</code> means that
+ * the page is complete and the user can go to the next page.
+ *
+ * @return
+ */
+ protected abstract boolean validatePage();
+
+ /**
+ * This method should be implemented by ModelWizardPage classes. This method
+ * is called after the <code>validatePage()</code> returns successfully.
+ * Update the model with the contents of the controls on the page.
+ */
+ protected abstract void updateModel();
+
+ /**
+ * Helper method to see if a field has some sort of text in it.
+ * @param value
+ * @return
+ */
+ protected boolean hasContents(String value) {
+ if (value == null || value.length() == 0) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * This method is called right before a page is displayed.
+ * This occurs on user action (Next/Back buttons).
+ */
+ public abstract void pageDisplay();
+
+ /**
+ * This method is called on the concrete WizardPage after the user has
+ * gone to the page after.
+ */
+ public abstract void pageCleanup();
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.IDialogPage#setVisible(boolean)
+ */
+ public void setVisible(boolean arg0) {
+
+ if (!arg0 && previousState) {
+ pageCleanup();
+ } else if (arg0 && !previousState) {
+ pageDisplay();
+ } else if (arg0 && previousState) {
+ pageDisplay();
+ }
+
+ previousState = arg0;
+
+ super.setVisible(arg0);
+ }
+
+ public class ValidationListener implements SelectionListener, ModifyListener, Listener, ISelectionChangedListener {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
+ */
+ public void widgetSelected(SelectionEvent e) {
+ validate();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
+ */
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
+ */
+ public void modifyText(ModifyEvent e) {
+ validate();
+ }
+
+ public void validate() {
+ if (validatePage()) {
+ updateModel();
+ setPageComplete(true);
+ return;
+ }
+
+ setPageComplete(false);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
+ */
+ public void handleEvent(Event event) {
+ validate();
+ }
+
+ public void selectionChanged(SelectionChangedEvent event) {
+ validate();
+ }
+ }
+}
diff --git a/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/NewBitBakeFileRecipeWizard.java b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/NewBitBakeFileRecipeWizard.java new file mode 100644 index 0000000..c02719f --- /dev/null +++ b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/NewBitBakeFileRecipeWizard.java @@ -0,0 +1,185 @@ +/***************************************************************************** + * 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; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.InvocationTargetException; + +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.ui.INewWizard; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWizard; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.ide.IDE; +import org.openembedded.bc.bitbake.BBLanguageHelper; + + +public class NewBitBakeFileRecipeWizard extends Wizard implements INewWizard { + private NewBitBakeFileRecipeWizardPage page; + private ISelection selection; + + public NewBitBakeFileRecipeWizard() { + super(); + setNeedsProgressMonitor(true); + } + + @Override + public void addPages() { + page = new NewBitBakeFileRecipeWizardPage(selection); + addPage(page); + } + + private void doFinish(String containerName, String fileName, String description, String license, String homepage, String author, String srcuri, IProgressMonitor monitor) throws CoreException { + + monitor.beginTask("Creating " + fileName, 2); + IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + IResource resource = root.findMember(new Path(containerName)); + if (!resource.exists() || !(resource instanceof IContainer)) { + throwCoreException("Container \"" + containerName + "\" does not exist."); + } + IContainer container = (IContainer) resource; + + // If the extension wasn't specified, assume .bb + if (!fileName.endsWith(BBLanguageHelper.BITBAKE_RECIPE_FILE_EXTENSION) || !fileName.endsWith(".inc") || !fileName.endsWith(".conf")) { + fileName = fileName + ".bb"; + } + + final IFile file = container.getFile(new Path(fileName)); + try { + InputStream stream = openContentStream(fileName, description, license, homepage, author, srcuri); + if (file.exists()) { + file.setContents(stream, true, true, monitor); + } else { + file.create(stream, true, monitor); + } + stream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + monitor.worked(1); + monitor.setTaskName("Opening file for editing..."); + getShell().getDisplay().asyncExec(new Runnable() { + public void run() { + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + try { + IDE.openEditor(page, file, true); + } catch (PartInitException e) { + e.printStackTrace(); + } + } + }); + monitor.worked(1); + } + + /** + * We will accept the selection in the workbench to see if we can initialize + * from it. + * + * @see IWorkbenchWizard#init(IWorkbench, IStructuredSelection) + */ + public void init(IWorkbench workbench, IStructuredSelection selection) { + this.selection = selection; + } + + /** + * We will initialize file contents with a sample text. + * @param srcuri + * @param author + * @param homepage + * @param license + * @param description + * @param fileName + * @param newPage + */ + + private InputStream openContentStream(String fileName, String description, String license, String homepage, String author, String srcuri) { + + StringBuffer sb = new StringBuffer(); + + sb.append("DESCRIPTION = \"" + description + "\"\n"); + + if (author.length() > 0) { + sb.append("AUTHOR = \"" + author + "\"\n"); + } + + if (homepage.length() > 0) { + sb.append("HOMEPAGE = \"" + homepage + "\"\n"); + } + + if (license.length() > 0) { + sb.append("LICENSE = \"" + license + "\"\n"); + } + + if (srcuri.length() > 0) { + sb.append("SRC_URI = \"" + srcuri + "\"\n"); + } + + sb.append("\n"); + + return new ByteArrayInputStream(sb.toString().getBytes()); + } + + @Override + public boolean performFinish() { + final String containerName = page.getContainerName(); + final String fileName = page.getFileName(); + final String description = page.getDescriptionText(); + final String license = page.getLicenseText(); + final String homepage = page.getHomepageText(); + final String author = page.getAuthorText(); + final String srcuri = page.getSrcuriText(); + + IRunnableWithProgress op = new IRunnableWithProgress() { + public void run(IProgressMonitor monitor) throws InvocationTargetException { + try { + doFinish(containerName, fileName, description, license, homepage, author, srcuri, monitor); + } catch (CoreException e) { + throw new InvocationTargetException(e); + } finally { + monitor.done(); + } + } + }; + try { + getContainer().run(true, false, op); + } catch (InterruptedException e) { + return false; + } catch (InvocationTargetException e) { + Throwable realException = e.getTargetException(); + MessageDialog.openError(getShell(), "Error", realException.getMessage()); + return false; + } + return true; + } + + private void throwCoreException(String message) throws CoreException { + IStatus status = new Status(IStatus.ERROR, "org.openembedded.bc.ui", IStatus.OK, message, null); + throw new CoreException(status); + } +}
\ No newline at end of file diff --git a/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java new file mode 100644 index 0000000..0f725a3 --- /dev/null +++ b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java @@ -0,0 +1,221 @@ +/***************************************************************************** + * 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; + +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.window.Window; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +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.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.dialogs.ContainerSelectionDialog; + +public class NewBitBakeFileRecipeWizardPage extends WizardPage { + private Text containerText; + + private Text fileText; + + private ISelection selection; + + private Text descriptionText; + + private Text licenseText; + + private Text homepageText; + + private Text authorText; + + private Text srcuriText; + public NewBitBakeFileRecipeWizardPage(ISelection selection) { + super("wizardPage"); + setTitle("BitBake Recipe"); + setDescription("Create a new BitBake recipe."); + this.selection = selection; + } + + public void createControl(Composite parent) { + Composite container = new Composite(parent, SWT.NULL); + GridLayout layout = new GridLayout(); + container.setLayout(layout); + layout.numColumns = 3; + layout.verticalSpacing = 9; + + createField(container, "&Recipe Name:", (fileText = new Text(container, SWT.BORDER | SWT.SINGLE))); + + Label label = new Label(container, SWT.NULL); + GridData gd = new GridData(); + gd.horizontalSpan = 3; + label.setLayoutData(gd); + + label = new Label(container, SWT.NULL); + label.setText("&Directory:"); + + containerText = new Text(container, SWT.BORDER | SWT.SINGLE); + gd = new GridData(GridData.FILL_HORIZONTAL); + containerText.setLayoutData(gd); + containerText.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + dialogChanged(); + } + }); + + Button button = new Button(container, SWT.PUSH); + button.setText("Browse..."); + button.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + handleBrowse(); + } + }); + + label = new Label(container, SWT.NULL); + gd = new GridData(); + gd.horizontalSpan = 3; + label.setLayoutData(gd); + + // label = new Label(container, SWT.SEPARATOR | SWT.HORIZONTAL); + createField(container, "&Package Description:", (descriptionText = new Text(container, SWT.BORDER | SWT.SINGLE))); + createField(container, "&License:", (licenseText = new Text(container, SWT.BORDER | SWT.SINGLE))); + createField(container, "&Homepage:", (homepageText = new Text(container, SWT.BORDER | SWT.SINGLE))); + createField(container, "Package &Author:", (authorText = new Text(container, SWT.BORDER | SWT.SINGLE))); + + // label = new Label(container, SWT.SEPARATOR | SWT.HORIZONTAL); + + createField(container, "SRC_URI:", (srcuriText = new Text(container, SWT.BORDER | SWT.SINGLE))); + + initialize(); + dialogChanged(); + setControl(container); + } + + private void createField(Composite container, String title, Text control) { + Label label = new Label(container, SWT.NONE); + label.setText(title); + label.moveAbove(control); + + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + gd.horizontalSpan = 2; + control.setLayoutData(gd); + control.addModifyListener(new ModifyListener() { + + public void modifyText(ModifyEvent e) { + dialogChanged(); + } + + }); + } + + private void dialogChanged() { + IResource container = ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(getContainerName())); + String fileName = getFileName(); + + if (getContainerName().length() == 0) { + updateStatus("Directory must be specified"); + return; + } + if (container == null || (container.getType() & (IResource.PROJECT | IResource.FOLDER)) == 0) { + updateStatus("File container must exist"); + return; + } + if (!container.isAccessible()) { + updateStatus("Project must be writable"); + return; + } + if (fileName.length() == 0) { + updateStatus("File name must be specified"); + return; + } + if (fileName.replace('\\', '/').indexOf('/', 1) > 0) { + updateStatus("File name must be valid"); + return; + } + + if (getDescriptionText().length() == 0) { + updateStatus("Recipe must have a description"); + return; + } + + updateStatus(null); + } + + public String getAuthorText() { + return authorText.getText(); + } + + public String getContainerName() { + return containerText.getText(); + } + + public String getDescriptionText() { + return descriptionText.getText(); + } + + public String getFileName() { + return fileText.getText(); + } + + public String getHomepageText() { + return homepageText.getText(); + } + + public String getLicenseText() { + return licenseText.getText(); + } + + public String getSrcuriText() { + return srcuriText.getText(); + } + + private void handleBrowse() { + ContainerSelectionDialog dialog = new ContainerSelectionDialog(getShell(), ResourcesPlugin.getWorkspace().getRoot(), false, "Select project directory"); + if (dialog.open() == Window.OK) { + Object[] result = dialog.getResult(); + if (result.length == 1) { + containerText.setText(((Path) result[0]).toString()); + } + } + } + + private void initialize() { + if (selection != null && selection.isEmpty() == false && selection instanceof IStructuredSelection) { + IStructuredSelection ssel = (IStructuredSelection) selection; + if (ssel.size() > 1) + return; + Object obj = ssel.getFirstElement(); + if (obj instanceof IResource) { + IContainer container; + if (obj instanceof IContainer) + container = (IContainer) obj; + else + container = ((IResource) obj).getParent(); + containerText.setText(container.getFullPath().toString()); + } + } + } + + private void updateStatus(String message) { + setErrorMessage(message); + setPageComplete(message == null); + } +}
\ No newline at end of file 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"); + } +} diff --git a/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/install/BBCProjectPage.java b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/install/BBCProjectPage.java new file mode 100644 index 0000000..a234bca --- /dev/null +++ b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/install/BBCProjectPage.java @@ -0,0 +1,244 @@ +/***************************************************************************** + * 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.install; + +import java.io.File; +import java.util.Hashtable; +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"; + public static final String INIT_SCRIPT_KEY = "Init Script"; + public static final String INSTALL_DIRECTORY_KEY = "Install Directory"; + public static final String PROJECT_NAME_KEY = "Project Name"; + + 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() { + + } + + @Override + public void pageDisplay() { + + } + + @Override + protected void updateModel() { + Map props = (Map) model.get(OptionsPage.OPTION_MAP); + + if (props == null) { + props = new Hashtable(); + model.put(OptionsPage.OPTION_MAP, props); + } + + props.put(INIT_SCRIPT_KEY, txtInit.getText()); + props.put(INSTALL_DIRECTORY_KEY, txtProjectLocation.getText()); + props.put(PROJECT_NAME_KEY, txtProjectName.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/install/BitbakePage.java b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/install/BitbakePage.java new file mode 100644 index 0000000..09e58b9 --- /dev/null +++ b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/install/BitbakePage.java @@ -0,0 +1,154 @@ +package org.openembedded.bc.ui.wizards.install; + +import java.io.File; +import java.io.IOException; +import java.io.Writer; +import java.lang.reflect.InvocationTargetException; +import java.util.Map; + +import org.eclipse.core.commands.ParameterValueConversionException; +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.FiniteStateWizard; +import org.openembedded.bc.ui.wizards.FiniteStateWizardPage; +import org.openembedded.bc.ui.wizards.importProject.ImportOEProjectWizard; +import org.openembedded.bc.ui.wizards.newproject.BBConfigurationInitializeOperation; + + +/** + * Bitbake console view. + * + * @author kgilmer + * + */ +public class BitbakePage extends FiniteStateWizardPage { + + private boolean valid = false; + + public BitbakePage(Map model) { + super("Bitbake Console Page", model); + setTitle("Extracting BitBake Environment"); + setMessage("Output of 'bitbake -e' command"); + } + + 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() { + Map props = (Map) model.get(OptionsPage.OPTION_MAP); + + try { + String initPath = InstallJob.substitute((String) props.get(BBCProjectPage.INIT_SCRIPT_KEY), model); + String location = InstallJob.substitute((String) props.get(BBCProjectPage.INSTALL_DIRECTORY_KEY), model); + String name = null; + if (props.containsKey(BBCProjectPage.PROJECT_NAME_KEY)) { + name = InstallJob.substitute((String) props.get(BBCProjectPage.PROJECT_NAME_KEY), model); + } else { + name = parseName((String) props.get("Install Directory")); + } + + ProjectInfo pinfo = new ProjectInfo(); + pinfo.setInitScriptPath(initPath); + pinfo.setLocation(location); + pinfo.setName(name); + + ConsoleWriter cw = new ConsoleWriter(); + this.getContainer().run(false, false, new BBConfigurationInitializeOperation(pinfo, cw)); + txtConsole.setText(cw.getContents()); + valid = true; + model.put(InstallWizard.KEY_PINFO, pinfo); + } catch (InvocationTargetException e) { + Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, e.getTargetException().getMessage(), e)); + setErrorMessage("Failed to create project."); + txtConsole.setText(e.getTargetException().getMessage()); + valid = false; + setPageComplete(valid); + return; + } catch (InterruptedException e) { + } catch (ParameterValueConversionException e) { + Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e)); + setErrorMessage("Failed to create project: " + e.getMessage()); + valid = false; + setPageComplete(valid); + return; + } + + setPageComplete(valid); + ((FiniteStateWizard) this.getWizard()).setCanFinish(true); + } + + private String parseName(String name) { + String[] e = name.split(File.separator); + return e[e.length - 1]; + } + + @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/install/Flavor.java b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/install/Flavor.java new file mode 100644 index 0000000..7462047 --- /dev/null +++ b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/install/Flavor.java @@ -0,0 +1,50 @@ +/** + * + */ +package org.openembedded.bc.ui.wizards.install; + +import java.io.IOException; + +// # Flavor Label (shows in UI)| description text| image URL| script URL + +/** + * Data class for flavor definition. + * @author kgilmer + * + */ +public class Flavor { + private final String label; + private final String description; + private final String imageURL; + private final String scriptURL; + + public Flavor(String line) throws IOException { + String [] e = line.split("\\|"); + + if (e.length != 4) { + throw new IOException("Invalid flavor line: " + line); + } + + label = e[0]; + description = e[1]; + imageURL = e[2]; + scriptURL = e[3]; + } + + public String getLabel() { + return label; + } + + public String getDescription() { + return description; + } + + public String getImageURL() { + return imageURL; + } + + public String getScriptURL() { + return scriptURL; + } + +}
\ No newline at end of file diff --git a/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/install/FlavorPage.java b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/install/FlavorPage.java new file mode 100644 index 0000000..db75c98 --- /dev/null +++ b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/install/FlavorPage.java @@ -0,0 +1,182 @@ +package org.openembedded.bc.ui.wizards.install; + +import java.io.IOException; +import java.util.Hashtable; +import java.util.List; +import java.util.Map; + +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.TableColumn; +import org.openembedded.bc.ui.Activator; +import org.openembedded.bc.ui.wizards.FiniteStateWizardPage; + + +/** + * Select which flavor of OE is to be installed. + * + * @author kgilmer + * + */ +public class FlavorPage extends FiniteStateWizardPage { + protected static final String OE_FLAVOR = "FLAVOR"; + protected static final String OE_FLAVOR_TITLE = "OE_FLAVOR_TITLE"; + protected static final String INSTALL_SCRIPT = "INSTALL_SCRIPT"; + + private boolean controlsCreated; + private TableViewer flavorList; + + protected FlavorPage(Map model) { + super("Flavor", model); + setTitle("Select OpenEmbedded Flavor"); + setMessage("Select the flavor of OpenEmbedded you wish to install..."); + } + + + public void createControl(Composite parent) { + Composite top = new Composite(parent, SWT.None); + top.setLayout(new GridLayout()); + top.setLayoutData(new GridData(GridData.FILL_BOTH)); + + flavorList = new TableViewer(top, SWT.BORDER); + flavorList.setContentProvider(new FlavorContentProvider()); + flavorList.setLabelProvider(new FlavorLabelProvider()); + flavorList.getTable().setLayoutData(new GridData(GridData.FILL_BOTH)); + flavorList.addSelectionChangedListener(new ValidationListener()); + + TableColumn tc = new TableColumn(flavorList.getTable(), SWT.LEFT); + tc.setText("Image"); + tc.setWidth(128); + + tc = new TableColumn(flavorList.getTable(), SWT.LEFT); + tc.setText("Title"); + tc.setWidth(300); + /* + tc = new TableColumn(flavorList.getTable(), SWT.LEFT); + tc.setText("Description"); + tc.setWidth(300);*/ + + + setControl(top); + } + + + public void pageCleanup() { + + } + + + public void pageDisplay() { + getContainer().getShell().setSize(getContainer().getShell().getSize().x, 600); + if (!controlsCreated) { + try { + flavorList.setInput(InstallScriptHelper.getFlavors("scripts/install_flavors.txt")); + controlsCreated = true; + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + + + protected void updateModel() { + Flavor f = (Flavor) ((IStructuredSelection) flavorList.getSelection()).getFirstElement(); + model.put(OE_FLAVOR, f); + model.put(OE_FLAVOR_TITLE, f.getLabel()); + try { + model.put(INSTALL_SCRIPT, InstallScriptHelper.loadFile(f.getScriptURL())); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + + protected boolean validatePage() { + return flavorList.getSelection() != null; + } + + private class FlavorContentProvider implements IStructuredContentProvider { + + + public Object[] getElements(Object arg0) { + return ((List) arg0).toArray(); + } + + + public void dispose() { + } + + + public void inputChanged(Viewer arg0, Object arg1, Object arg2) { + } + + } + + private class FlavorLabelProvider implements ITableLabelProvider { + private Map imageMap = new Hashtable(); + + + public Image getColumnImage(Object arg0, int arg1) { + Flavor f = (Flavor) arg0; + Image i = null; + + if (arg1 == 0) { + i = (Image) imageMap.get(f); + if (i == null) { + i = Activator.getImageDescriptor(f.getImageURL()).createImage(); + imageMap.put(f, i); + } + } + + return i; + } + + + public String getColumnText(Object arg0, int arg1) { + Flavor f = (Flavor) arg0; + if (arg1 == 1) { + return f.getLabel(); + } else if (arg1 == 2) { + return f.getDescription(); + } + + return null; + } + + + public void addListener(ILabelProviderListener arg0) { + + } + + + public void dispose() { + // TODO Auto-generated method stub + + } + + + public boolean isLabelProperty(Object arg0, String arg1) { + // TODO Auto-generated method stub + return false; + } + + + public void removeListener(ILabelProviderListener arg0) { + // TODO Auto-generated method stub + + } + + } + +} diff --git a/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/install/InstallJob.java b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/install/InstallJob.java new file mode 100644 index 0000000..5b2b0a7 --- /dev/null +++ b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/install/InstallJob.java @@ -0,0 +1,170 @@ +/** + * + */ +package org.openembedded.bc.ui.wizards.install; + +import java.io.BufferedReader; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.commands.ParameterValueConversionException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.openembedded.bc.bitbake.ICommandResponseHandler; +import org.openembedded.bc.bitbake.ShellSession; +import org.openembedded.bc.ui.Activator; + + +class InstallJob extends Job { + + private final Map mod; + private UICommandResponseHandler cmdOut; + private boolean errorOccurred = false; + private String errorMessage = ""; + + public InstallJob(Map model, ProgressPage progressPage) { + super("Install OpenEmbedded"); + mod = model; + cmdOut = new UICommandResponseHandler(progressPage); + } + + @Override + protected IStatus run(IProgressMonitor monitor) { + BufferedReader reader = new BufferedReader(new StringReader( + (String) mod.get(FlavorPage.INSTALL_SCRIPT))); + String line = null; + Map vars = loadVariables(); + + try { + ShellSession shell = new ShellSession(ShellSession.SHELL_TYPE_BASH, + null, null, null); + while ((line = reader.readLine()) != null && !errorOccurred) { + line = line.trim(); + if (line.length() > 0 && !line.startsWith("#")) { + line = substitute(line, vars); + cmdOut.printCmd(line); + System.out.println("Running: " + line); + shell.execute(line, cmdOut); + } else if (line.startsWith("#")) { + cmdOut.printDialog(line.substring(1).trim()); + } + } + + if (errorOccurred) { + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, + "Failed to install OpenEmbedded: " + errorMessage); + } + } catch (Exception e) { + e.printStackTrace(); + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, + "Failed to install OpenEmbedded", e); + } + + return Status.OK_STATUS; + } + + private Map loadVariables() { + return (Map) mod.get(OptionsPage.OPTION_MAP); + } + + /** + * Return a string with variable substitutions in place. + * + * @param expression + * @return Input string with any substitutions from this file. + * @throws ParameterValueConversionException + */ + public static String substitute(String expression, Map mo) + throws ParameterValueConversionException { + + List vars; + int literals = 0; + + while ((vars = parseVars(expression)).size() > literals) { + for (Iterator i = vars.iterator(); i.hasNext();) { + String varName = (String) i.next(); + String varToken = "${" + varName + "}"; + + if (mo.containsKey(varName)) { + expression = expression.replace(varToken, (String) mo + .get(varName)); + } else if (System.getProperty(varName) != null) { + expression = expression.replace(varToken, System + .getProperty(varName)); + } else if (varName.toUpperCase().equals("HOME")) { + expression = expression.replace(varToken, System + .getProperty("user.home")); + } else { + //throw new ParameterValueConversionException( + // "Unable to match parameter: " + expression); + // Leave the value, treat as a literal. + literals++; + } + } + } + + return expression; + } + + /** + * + * @param line + * @return A list of variables in $[variable name] format. + */ + public static List parseVars(String line) { + List l = new ArrayList(); + + int i = 0; + + while ((i = line.indexOf("${", i)) > -1) { + int i2 = line.indexOf("}", i); + + String var = line.subSequence(i + 2, i2).toString().trim(); + + if (var.length() > 0 && !l.contains(var)) { + l.add(var); + } + i++; + } + + return l; + } + + private class UICommandResponseHandler implements ICommandResponseHandler { + + private final ProgressPage progressPage; + + public UICommandResponseHandler(ProgressPage progressPage) { + this.progressPage = progressPage; + } + + public void printDialog(String msg) { + progressPage.printDialog(msg); + } + + public void response(String line, boolean isError) { + if (isError) { + progressPage.printLine(line, ProgressPage.PRINT_ERR); + //errorOccurred = true; + //errorMessage = line; + } else { + progressPage.printLine(line, ProgressPage.PRINT_OUT); + if (line.endsWith("!!OTEWIZARDSTOP")) { + errorOccurred = true; + errorMessage = line; + } + } + } + + public void printCmd(String cmd) { + progressPage.printLine(cmd, ProgressPage.PRINT_CMD); + } + + } + +}
\ No newline at end of file diff --git a/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/install/InstallParameter.java b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/install/InstallParameter.java new file mode 100644 index 0000000..517a0fe --- /dev/null +++ b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/install/InstallParameter.java @@ -0,0 +1,99 @@ +/** + * + */ +package org.openembedded.bc.ui.wizards.install; + +class InstallParameter { + public static final int DT_TEXT = 1; + public static final int DT_COMBO = 2; + public static final int DT_LIST = 3; + public static final int DT_NUMBER = 4; + public static final int DT_DIRECTORY = 5; + public static final int DT_FILE = 6; + public static final int DT_CHECKBOX = 7; + + private boolean valid = false; + private int type; + private String label; + private boolean required; + private String data; + private String helpURL; + private String helpText; + + public int getType() { + return type; + } + + public String getLabel() { + return label; + } + + public boolean isRequired() { + return required; + } + + public String getData() { + return data; + } + + public String getHelpURL() { + return helpURL; + } + + public String getHelpText() { + return helpText; + } + + public InstallParameter(String var) { + // {|Datatype|Label|UnRequired|Data|Help|} + // {|T|Distribution|R|angstrom-2008.1|http://wiki.openembedded.net/index.php/Getting_started#Create_local_configuration|} + + String[] elems = var.split("\\|"); + + if (elems.length == 5 || elems.length == 6) { + if (elems[0].equals("T")) { + type = DT_TEXT; + } else if (elems[0].equals("D")) { + type = DT_DIRECTORY; + } else if (elems[0].equals("F")) { + type = DT_FILE; + } else if (elems[0].equals("C")) { + type = DT_COMBO; + } else if (elems[0].equals("B")) { + type = DT_CHECKBOX; + } else { + throw new RuntimeException("Invalid field format: " + var); + } + + label = elems[1]; + + if (elems[2].equals("R")) { + required = true; + } else if (elems[2].equals("U")) { + required = false; + } else { + throw new RuntimeException("Invalid field format: " + var); + } + + data = elems[3].trim(); + + if (elems[4].trim().length() > 0) { + helpURL = elems[4].trim(); + } + + if (elems.length == 6) { + helpText = elems[5]; + } + + valid = true; + } else { + throw new RuntimeException("Invalid field format: " + var); + } + } + + public boolean isValid() { + + return valid; + } + +}
\ No newline at end of file diff --git a/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/install/InstallScriptHelper.java b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/install/InstallScriptHelper.java new file mode 100644 index 0000000..5225929 --- /dev/null +++ b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/install/InstallScriptHelper.java @@ -0,0 +1,52 @@ +package org.openembedded.bc.ui.wizards.install; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; + +import org.openembedded.bc.ui.Activator; + + +/** + * Helper for loading install scripts. + * @author kgilmer + * + */ +public class InstallScriptHelper { + + public static List getFlavors(String filePath) throws IOException { + InputStream is = Activator.getDefault().getBundle().getResource(filePath).openStream(); + List list = new ArrayList(); + + BufferedReader br = new BufferedReader(new InputStreamReader(is)); + String line = null; + + while ((line = br.readLine()) != null) { + line = line.trim(); + + if (line.length() > 0 && !line.startsWith("#")) { + list.add(new Flavor(line)); + } + } + + return list; + } + + public static String loadFile(String fileName) throws IOException { + InputStream is = Activator.getDefault().getBundle().getResource(fileName).openStream(); + + BufferedReader br = new BufferedReader(new InputStreamReader(is)); + String line = null; + StringBuffer sb = new StringBuffer(); + + while ((line = br.readLine()) != null) { + sb.append(line); + sb.append('\n'); + } + + return sb.toString(); + } +} diff --git a/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/install/InstallWizard.java b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/install/InstallWizard.java new file mode 100644 index 0000000..2297939 --- /dev/null +++ b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/install/InstallWizard.java @@ -0,0 +1,105 @@ +package org.openembedded.bc.ui.wizards.install; + +import java.lang.reflect.InvocationTargetException; +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.IWorkbench; +import org.eclipse.ui.IWorkbenchWizard; +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; + + +/** + * A wizard for installing a fresh copy of an OE system. + * + * @author kgilmer + * + */ +public class InstallWizard extends FiniteStateWizard implements IWorkbenchWizard { + + static final String KEY_PINFO = "KEY_PINFO"; + private Map model; + + public InstallWizard() { + this.model = new Hashtable(); + setWindowTitle("BitBake Commander"); + setNeedsProgressMonitor(false); + setDefaultPageImageDescriptor(Activator.getImageDescriptor("icons/OE_logo_96.png")); + } + + public InstallWizard(IStructuredSelection selection) { + model = new Hashtable(); + } + + /*@Override + public IWizardPage getNextPage(IWizardPage page) { + if (page instanceof WelcomePage) { + if (model.containsKey(WelcomePage.ACTION_USE)) { + return bbcProjectPage; + } + } else if (page instanceof ProgressPage) { + return bitbakePage; + } + + if (super.getNextPage(page) != null) { + System.out.println("next page: " + super.getNextPage(page).getClass().getName()); + } else { + System.out.println("end page"); + } + + return super.getNextPage(page); + } + + @Override + public boolean canFinish() { + System.out.println("can finish: " + super.canFinish()); + return super.canFinish(); + } +*/ + @Override + public void addPages() { + // flavorPage = new FlavorPage(model); + // bitbakePage = new BitbakePage(model); + // bbcProjectPage = new BBCProjectPage(model); + //addPage(new WelcomePage(model)); + addPage(new FlavorPage(model)); + addPage(new OptionsPage(model)); + addPage(new ProgressPage(model)); + //addPage(bbcProjectPage); + addPage(new BitbakePage(model)); + } + + @Override + public Map getModel() { + return model; + } + + @Override + public boolean performFinish() { + ProjectInfo pinfo = (ProjectInfo) model.get(KEY_PINFO); + Activator.putProjInfo(pinfo.getRootPath(), pinfo); + try { + getContainer().run(false, false, new CreateBBCProjectOperation(pinfo)); + } catch (InvocationTargetException e) { + e.printStackTrace(); + Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e)); + this.getContainer().getCurrentPage().setTitle("Failed to create project: " + e.getTargetException().getMessage()); + return false; + } catch (Exception e) { + Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e)); + this.getContainer().getCurrentPage().setTitle("Failed to create project: " + e.getMessage()); + return false; + } + + return true; + } + + public void init(IWorkbench workbench, IStructuredSelection selection) { + } +} diff --git a/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/install/OptionsPage.java b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/install/OptionsPage.java new file mode 100644 index 0000000..97115f1 --- /dev/null +++ b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/install/OptionsPage.java @@ -0,0 +1,313 @@ +package org.openembedded.bc.ui.wizards.install; + +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.FocusListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.DirectoryDialog; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Link; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.PlatformUI; +import org.openembedded.bc.ui.wizards.FiniteStateWizardPage; + + +/** + * Select which flavor of OE is to be installed. + * + * @author kgilmer + * + */ +public class OptionsPage extends FiniteStateWizardPage { + + private Map vars; + private Composite c1; + private Composite top; + protected static final String OPTION_MAP = "OPTION_MAP"; + private static final String DEFAULT_MESSAGE = "Enter these parameters to install."; + private List controlList; + private boolean controlsCreated = false; + + protected OptionsPage(Map model) { + super("Options", model); + setTitle("Installing..."); + setMessage(DEFAULT_MESSAGE); + } + + @Override + public void createControl(Composite parent) { + top = new Composite(parent, SWT.None); + top.setLayout(new GridLayout()); + top.setLayoutData(new GridData(GridData.FILL_BOTH)); + + c1 = new Composite(top, SWT.None); + c1.setLayout(new GridLayout(3, false)); + c1.setLayoutData(new GridData(GridData.FILL_BOTH)); + + setControl(top); + } + + private void createControls(Composite comp, Map v, List cl) { + ValidationListener listener = new ValidationListener(); + + for (Iterator i = v.keySet().iterator(); i.hasNext();) { + + String label = (String) i.next(); + final InstallParameter ip = (InstallParameter) v.get(label); + + if (ip.getType() != InstallParameter.DT_CHECKBOX) { + Label title = new Label(comp, SWT.None); + title.setText(ip.getLabel() + ": "); + if (ip.getHelpText() != null) { + title.setToolTipText(ip.getHelpText()); + } + } else { + //If we are creating checkbox, layout differently. + new Label(comp, SWT.None); + } + + Control toolTipControl = null; + switch (ip.getType()) { + case InstallParameter.DT_TEXT: + Text field = new Text(comp, SWT.BORDER); + field.setData(ip); + field.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + field.addModifyListener(listener); + field.setText(ip.getData()); + cl.add(field); + toolTipControl = field; + break; + case InstallParameter.DT_DIRECTORY: + Composite locComposite = new Composite(comp, 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); + + final Text location = new Text(locComposite, SWT.BORDER); + location.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + location.setText(ip.getData()); + location.addModifyListener(listener); + location.setData(ip); + toolTipControl = location; + cl.add(location); + + Button button = new Button(locComposite, SWT.PUSH); + button.setText("..."); + button.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + DirectoryDialog fd = new DirectoryDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(), SWT.OPEN); + + fd.setText(ip.getLabel()); + + String selected = fd.open(); + + if (selected != null) { + location.setText(selected); + // updateModel(); + } + } + }); + break; + case InstallParameter.DT_FILE: + Composite fileComposite = new Composite(comp, SWT.NONE); + gd = new GridData(GridData.VERTICAL_ALIGN_END | GridData.FILL_HORIZONTAL); + gd.horizontalIndent = 0; + fileComposite.setLayoutData(gd); + gl = new GridLayout(2, false); + gl.marginWidth = 0; + fileComposite.setLayout(gl); + + final Text fileLocation = new Text(fileComposite, SWT.BORDER); + fileLocation.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + fileLocation.setText(ip.getData()); + fileLocation.addModifyListener(listener); + fileLocation.setData(ip); + toolTipControl = fileLocation; + cl.add(fileLocation); + + button = new Button(fileComposite, SWT.PUSH); + button.setText("..."); + button.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + FileDialog fd = new FileDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(), SWT.OPEN); + + fd.setText(ip.getLabel()); + + String selected = fd.open(); + + if (selected != null) { + fileLocation.setText(selected); + // updateModel(); + } + } + }); + break; + case InstallParameter.DT_COMBO: + Combo cfield = new Combo(comp, SWT.READ_ONLY); + cfield.setData(ip); + // cfield.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + cfield.addModifyListener(listener); + cfield.setItems(ip.getData().split(",")); + cfield.setText(ip.getData().split(",")[0]); + toolTipControl = cfield; + cl.add(cfield); + break; + case InstallParameter.DT_CHECKBOX: + Button bfield = new Button(comp, SWT.CHECK); + bfield.setData(ip); + bfield.setText(ip.getLabel()); + // bfield.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + bfield.addSelectionListener(listener); + if (ip.getData().trim().toUpperCase().equals("TRUE")) { + bfield.setSelection(true); + } + toolTipControl = bfield; + cl.add(bfield); + break; + default: + throw new RuntimeException("Unknown or unimplemented field: " + ip.getType()); + } + + // Setup tool tips and wizard help. + if (toolTipControl != null) { + if (ip.getHelpText() != null) { + toolTipControl.setToolTipText(ip.getHelpText()); + toolTipControl.addFocusListener(new FocusListener() { + + public void focusLost(FocusEvent e) { + } + + public void focusGained(FocusEvent e) { + setMessage(ip.getHelpText()); + } + }); + } else { + toolTipControl.addFocusListener(new FocusListener() { + + public void focusLost(FocusEvent e) { + } + + public void focusGained(FocusEvent e) { + setMessage(DEFAULT_MESSAGE); + ; + } + }); + } + } + + // Create a hyperlink to help content if exists, or invisible label if not. + if (ip.getHelpURL() != null) { + Link l = new Link(comp, SWT.None); + l.setText("<a>Help...</a>"); + l.addSelectionListener(new SelectionListener() { + + public void widgetSelected(SelectionEvent e) { + org.eclipse.swt.program.Program.launch(ip.getHelpURL()); + } + + public void widgetDefaultSelected(SelectionEvent e) { + // TODO Auto-generated method stub + + } + }); + } else { + new Label(comp, SWT.None); + } + } + } + + @Override + public void pageCleanup() { + + } + + @Override + public void pageDisplay() { + if (!controlsCreated) { + controlList = new ArrayList(); + + vars = parseVars((String) model.get(FlavorPage.INSTALL_SCRIPT)); + + createControls(c1, vars, controlList); + c1.layout(); + + controlsCreated = true; + setTitle(((String) model.get(FlavorPage.OE_FLAVOR_TITLE)).trim() + " Options"); + } + updateModel(); + } + + public static Map parseVars(String line) { + Map l = new LinkedHashMap(); + + int i = 0; + + while ((i = line.indexOf("{|", i)) > -1) { + int i2 = line.indexOf("|}", i); + + String var = line.subSequence(i + 2, i2).toString().trim(); + + if (var.length() > 0) { + InstallParameter ip = new InstallParameter(var + " "); + + if (ip.isValid() && !l.containsKey(ip.getLabel())) { + l.put(ip.getLabel(), ip); + } + } + i++; + } + + return l; + } + + @Override + protected void updateModel() { + Map m = new Hashtable(); + + for (Iterator i = controlList.iterator(); i.hasNext();) { + Control t = (Control) i.next(); + String val = null; + InstallParameter ip = (InstallParameter) t.getData(); + + if (t instanceof Text) { + val = ((Text) t).getText(); + } else if (t instanceof Combo) { + val = ((Combo) t).getText(); + } else if (t instanceof Button) { + val = Boolean.toString(((Button) t).getSelection()); + } else { + throw new RuntimeException("Unknown control type: " + t.getClass().getName()); + } + + m.put(ip.getLabel(), val); + } + model.put(OPTION_MAP, m); + } + + @Override + protected boolean validatePage() { + return true; + } + +} diff --git a/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/install/ProgressPage.java b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/install/ProgressPage.java new file mode 100644 index 0000000..6a54a6b --- /dev/null +++ b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/install/ProgressPage.java @@ -0,0 +1,191 @@ +package org.openembedded.bc.ui.wizards.install; + + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.StringReader; +import java.util.Map; + +import org.eclipse.core.runtime.jobs.IJobChangeEvent; +import org.eclipse.core.runtime.jobs.IJobChangeListener; +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.Label; +import org.eclipse.swt.widgets.ProgressBar; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.PlatformUI; +import org.openembedded.bc.ui.wizards.FiniteStateWizardPage; + + +/** + * Select which flavor of OE is to be installed. + * @author kgilmer + * + */ +public class ProgressPage extends FiniteStateWizardPage { + + private static final String STARTED_INSTALL = "STARTED_INSTALL"; + private Text txtConsole; + private StringBuffer consoleBuffer; + private ProgressBar pbProgress; + private String lastError; + + protected static final int PRINT_CMD = 1; + protected static final int PRINT_OUT = 2; + protected static final int PRINT_ERR = 3; + + protected ProgressPage(Map model) { + super("Progress", model); + setTitle("Installing OpenEmbedded"); + setMessage(""); + } + + public void createControl(Composite parent) { + Composite top = new Composite(parent, SWT.None); + top.setLayout(new GridLayout()); + top.setLayoutData(new GridData(GridData.FILL_BOTH)); + + txtConsole = new Text(top, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER); + txtConsole.setLayoutData(new GridData(GridData.FILL_BOTH)); + txtConsole.setFont(JFaceResources.getFont(JFaceResources.TEXT_FONT)); + txtConsole.setEditable(false); + + Label s = new Label(top, SWT.SEPARATOR | SWT.HORIZONTAL); + s.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + pbProgress = new ProgressBar(top, SWT.HORIZONTAL | SWT.BORDER); + + setControl(top); + } + + protected void printLine(String line, final int type) { + if (consoleBuffer == null) { + consoleBuffer = new StringBuffer(); + } + + if (type == PRINT_CMD) { + consoleBuffer.append("$ "); + } else if (type == PRINT_ERR) { + consoleBuffer.append("ERROR: "); + lastError = line; + } + + consoleBuffer.append(line); + consoleBuffer.append('\n'); + + PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { + + + public void run() { + txtConsole.setText(consoleBuffer.toString()); + txtConsole.setSelection(txtConsole.getText().length() - 1); + + if (type == PRINT_CMD) { + pbProgress.setSelection(pbProgress.getSelection() + 1); + } + } + + }); + } + + public void pageCleanup() { + + } + + public void pageDisplay() { + if (!model.containsKey(STARTED_INSTALL)) { + model.put(STARTED_INSTALL, new Boolean(true)); + + try { + pbProgress.setMaximum(getLineCount((String) model.get(FlavorPage.INSTALL_SCRIPT))); + } catch (IOException e) { + //TODO add logging here. + e.printStackTrace(); + return; + } + + executeInstall(); + } + } + + private int getLineCount(String str) throws IOException { + int count = 0; + + BufferedReader br = new BufferedReader(new StringReader(str)); + + while (br.readLine() != null) { + count++; + } + + return count; + } + + private void executeInstall() { + InstallJob j = new InstallJob(model, this); + j.addJobChangeListener(new IJobChangeListener() { + + public void aboutToRun(IJobChangeEvent event) { + } + + + public void awake(IJobChangeEvent event) { + } + + + public void done(final IJobChangeEvent event) { + PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { + + + public void run() { + if (event.getResult().isOK()) { + setMessage("Installation complete, next is to load into workspace."); + pbProgress.setVisible(false); + setPageComplete(true); + } else { + setErrorMessage("An error occurred while installing OpenEmbedded:\n" + lastError); + } + } + + }); + } + + public void running(IJobChangeEvent event) { + } + + + public void scheduled(IJobChangeEvent event) { + } + + + public void sleeping(IJobChangeEvent event) { + } + + }); + setMessage("Installing OpenEmbedded..."); + j.schedule(); + } + + + protected void updateModel() { + } + + + protected boolean validatePage() { + + return true; + } + + public void printDialog(final String msg) { + PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { + + + public void run() { + setMessage(msg); + } + }); + } + +} diff --git a/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/install/WelcomePage.java b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/install/WelcomePage.java new file mode 100644 index 0000000..cbb4317 --- /dev/null +++ b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/install/WelcomePage.java @@ -0,0 +1,96 @@ +package org.openembedded.bc.ui.wizards.install; + +import java.util.Map; + +import org.eclipse.swt.SWT; +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.Label; +import org.openembedded.bc.ui.wizards.FiniteStateWizardPage; + + +public class WelcomePage extends FiniteStateWizardPage { + + public static final String ACTION_INSTALL = "ACTION_INSTALL"; + public static final String ACTION_USE = "ACTION_USE"; + private Button installButton; + private Button useButton; + + protected WelcomePage(Map model) { + super("Introduction", model); + setTitle("Select Project Type"); + } + + @Override + public void createControl(Composite parent) { + Composite top = new Composite(parent, SWT.None); + top.setLayout(new GridLayout()); + top.setLayoutData(new GridData(GridData.FILL_BOTH)); + + ValidationListener listener = new ValidationListener(); + + installButton = new Button(top, SWT.RADIO | SWT.WRAP); + installButton.setText("Install a flavor of OpenEmbedded on your computer."); + Composite lc = new Composite(top, SWT.None); + lc.setLayout(new GridLayout(2, false)); + lc.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + Label spacer = new Label(lc, SWT.None); + spacer.setText(" "); + Label installLabel = new Label(lc, SWT.WRAP); + installLabel.setText( + "This will install a flavor of OpenEmbedded in your Eclipse workspace. It is the " + + "recommended option for new projects in Eclipse." + ); + installLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + installButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + installButton.addSelectionListener(listener); + + useButton = new Button(top, SWT.RADIO | SWT.WRAP); + useButton.setText("Use an existing local copy of OpenEmbedded."); + lc = new Composite(top, SWT.None); + lc.setLayout(new GridLayout(2, false)); + lc.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + spacer = new Label(lc, SWT.None); + spacer.setText(" "); + installLabel = new Label(lc, SWT.WRAP); + installLabel.setText( + "A working install " + + "of a flavor of OpenEmbedded is required. An init script will need to be selected to initialize " + + "the environment."); + installLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + useButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + useButton.addSelectionListener(listener); + + setControl(top); + } + + @Override + public void pageCleanup() { + } + + @Override + public void pageDisplay() { + setMessage("Choose to install a new instance or an existing one."); + } + + @Override + protected void updateModel() { + model.remove(ACTION_INSTALL); + model.remove(ACTION_USE); + + if (installButton.getSelection()) { + model.put(ACTION_INSTALL, ACTION_INSTALL); + } else if (useButton.getSelection()) { + model.put(ACTION_USE, ACTION_USE); + } + } + + @Override + protected boolean validatePage() { + return useButton.getSelection() || installButton.getSelection(); + } +} diff --git a/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/newproject/BBConfigurationInitializeOperation.java b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/newproject/BBConfigurationInitializeOperation.java new file mode 100644 index 0000000..ae3f90c --- /dev/null +++ b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/newproject/BBConfigurationInitializeOperation.java @@ -0,0 +1,59 @@ +/***************************************************************************** + * 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.newproject; + +import java.io.Writer; +import java.lang.reflect.InvocationTargetException; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.openembedded.bc.bitbake.BBSession; +import org.openembedded.bc.bitbake.ProjectInfoHelper; +import org.openembedded.bc.ui.Activator; +import org.openembedded.bc.ui.model.ProjectInfo; + + +public class BBConfigurationInitializeOperation implements IRunnableWithProgress { + + private final ProjectInfo pinfo; + private final Writer writer; + + public BBConfigurationInitializeOperation(ProjectInfo pinfo) { + this.pinfo = pinfo; + writer = null; + } + + public BBConfigurationInitializeOperation(ProjectInfo pinfo, Writer writer) { + this.pinfo = pinfo; + this.writer = writer; + } + + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + BBSession session; + try { + ProjectInfoHelper.store(pinfo.getRootPath(), pinfo); + session = Activator.getBBSession(pinfo.getRootPath(), writer); + + if (!session.isInitialized()) { + session.initialize(); + } + + if (session.isEmpty()) { + Activator.clearBBSession(pinfo.getRootPath()); + throw new RuntimeException("Bitbake failed silently. No configuration is availalbe."); + } + + } catch (Exception e) { + Activator.clearBBSession(pinfo.getRootPath()); + throw new InvocationTargetException(e); + } + } +} diff --git a/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/newproject/CreateBBCProjectOperation.java b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/newproject/CreateBBCProjectOperation.java new file mode 100644 index 0000000..9e67e5b --- /dev/null +++ b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/newproject/CreateBBCProjectOperation.java @@ -0,0 +1,107 @@ +/***************************************************************************** + * 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.newproject; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Arrays; +import java.util.Vector; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.QualifiedName; +import org.eclipse.core.runtime.Status; +import org.eclipse.ui.actions.WorkspaceModifyOperation; +import org.openembedded.bc.bitbake.ProjectInfoHelper; +import org.openembedded.bc.ui.Activator; +import org.openembedded.bc.ui.builder.BitbakeCommanderNature; +import org.openembedded.bc.ui.model.ProjectInfo; + + + +/** + * Creates a bbc project + * @author kgilmer + * + */ +public class CreateBBCProjectOperation extends WorkspaceModifyOperation { + + public static final String OEFS_SCHEME = "OEFS://"; + public static final QualifiedName BBC_PROJECT_INIT = new QualifiedName(null, "BBC_PROJECT_INIT"); + public static void addNatureToProject(IProject proj, String nature_id, IProgressMonitor monitor) throws CoreException { + IProjectDescription desc = proj.getDescription(); + Vector natureIds = new Vector(); + + natureIds.add(nature_id); + natureIds.addAll(Arrays.asList(desc.getNatureIds())); + desc.setNatureIds((String[]) natureIds.toArray(new String[natureIds.size()])); + + proj.setDescription(desc, monitor); + } + + private ProjectInfo projInfo; + + public CreateBBCProjectOperation(ProjectInfo projInfo) { + this.projInfo = projInfo; + } + + protected void addNatures(IProject proj, IProgressMonitor monitor) throws CoreException { + addNatureToProject(proj, BitbakeCommanderNature.NATURE_ID, monitor); + } + + private IProjectDescription createProjectDescription(IWorkspace workspace, ProjectInfo projInfo2) throws CoreException { + IProjectDescription desc = workspace.newProjectDescription(projInfo2.getProjectName()); + + try { + System.out.println("Calling creageProjeDesc"); + desc.setLocationURI(new URI(OEFS_SCHEME + projInfo2.getRootPath())); + } catch (URISyntaxException e) { + throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Unable to load filesystem.", e)); + } + + return desc; + } + + @Override + protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { + System.out.println("Init: " + projInfo.getInitScriptPath()); + System.out.println("Proj: " + projInfo.getProjectName()); + System.out.println("Root: " + projInfo.getRootPath()); + + IProjectDescription desc = createProjectDescription(ResourcesPlugin.getWorkspace(), projInfo); + + IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot(); + + IProject proj = wsroot.getProject(projInfo.getProjectName()); + proj.create(desc, monitor); + try { + ProjectInfoHelper.store(proj.getLocationURI().getPath(), projInfo); + } catch (IOException e) { + throw new InvocationTargetException(e); + } + + proj.open(monitor); + + addNatures(proj, monitor); + } + + public ProjectInfo getProjectInfo() { + return projInfo; + } +} diff --git a/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/variable/VariablePage.java b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/variable/VariablePage.java new file mode 100644 index 0000000..5919581 --- /dev/null +++ b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/variable/VariablePage.java @@ -0,0 +1,262 @@ +package org.openembedded.bc.ui.wizards.variable; + +import java.util.Comparator; +import java.util.Map; + +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerFilter; +import org.eclipse.jface.viewers.ViewerSorter; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.Text; +import org.openembedded.bc.ui.wizards.FiniteStateWizardPage; + + +/** + * The wizard page for the Variable Wizard. + * @author kgilmer + * + */ +public class VariablePage extends FiniteStateWizardPage { + + private Text txtName; + private Text txtValue; + private TableViewer viewer; + private TableColumn c1; + private TableColumn c2; + + protected VariablePage(Map model) { + super("BitBake Commander", model); + setTitle("BitBake Variable Viewer"); + setDescription("Sort and fitler global BitBake variables by name or value."); + } + + @Override + public void createControl(Composite parent) { + Composite top = new Composite(parent, SWT.None); + top.setLayout(new GridLayout(2, true)); + top.setLayoutData(new GridData(GridData.FILL_BOTH)); + + ValidationListener listener = new ValidationListener(); + + txtName = new Text(top, SWT.BORDER); + txtName.addModifyListener(listener); + txtName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + txtValue = new Text(top, SWT.BORDER); + txtValue.addModifyListener(listener); + txtValue.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + viewer = new TableViewer(top); + + Table table = viewer.getTable(); + table.setLinesVisible(true); + table.setHeaderVisible(true); + GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); + data.heightHint = 200; + data.horizontalSpan = 2; + table.setLayoutData(data); + c1 = new TableColumn(table, SWT.NONE); + c1.setText("Name"); + c1.setWidth(200); + c1.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + ((VariableViewerSorter) viewer.getSorter()).doSort(0); + viewer.refresh(); + } + }); + + c2 = new TableColumn(table, SWT.NONE); + c2.setText("Value"); + c2.setWidth(200); + c2.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + ((VariableViewerSorter) viewer.getSorter()).doSort(1); + viewer.refresh(); + } + }); + + viewer.setContentProvider(new VariableContentProvider()); + viewer.setLabelProvider(new VariableLabelProvider()); + viewer.setSorter(new VariableViewerSorter()); + + viewer.setFilters(new ViewerFilter[] {new MapViewerFilter()}); + setControl(top); + } + + @Override + public void pageCleanup() { + + } + + @Override + public void pageDisplay() { + viewer.setInput(model); + } + + @Override + protected void updateModel() { + viewer.refresh(); + } + + @Override + protected boolean validatePage() { + return true; + } + + /** + * A content provider for the variable wizard dialog. + * @author kgilmer + * + */ + private class VariableContentProvider implements IStructuredContentProvider { + + public Object[] getElements(Object inputElement) { + return model.keySet().toArray(); + } + + public void dispose() { + + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + + } + } + + /** + * A label provider for variable wizard dialog. + * @author kgilmer + * + */ + private class VariableLabelProvider implements ITableLabelProvider { + + public Image getColumnImage(Object element, int columnIndex) { + return null; + } + + public String getColumnText(Object element, int columnIndex) { + String val; + + switch (columnIndex) { + case 0: + val = element.toString(); + break; + case 1: + val = (String) model.get(element); + break; + default: + val = ""; + break; + } + + return val; + } + + public void addListener(ILabelProviderListener listener) { + + } + + public void dispose() { + + } + + public boolean isLabelProperty(Object element, String property) { + return false; + } + + public void removeListener(ILabelProviderListener listener) { + + } + + } + + /** + * + * A tableviewer sorter found on the internet. + * + */ + class VariableViewerSorter extends ViewerSorter { + private static final int ASCENDING = 0; + + private static final int DESCENDING = 1; + + private int column; + + private int direction; + + public void doSort(int column) { + if (column == this.column) { + // Same column as last sort; toggle the direction + direction = 1 - direction; + } else { + // New column; do an ascending sort + this.column = column; + direction = ASCENDING; + } + } + + public int compare(Viewer viewer, Object e1, Object e2) { + int rc = 0; + Comparator c = this.getComparator(); + // Determine which column and do the appropriate sort + switch (column) { + case 0: + rc = c.compare(e1, e2); + break; + case 1: + rc = c.compare(model.get(e1), model.get(e2)); + break; + } + + // If descending order, flip the direction + if (direction == DESCENDING) + rc = -rc; + + return rc; + } + } + + /** + * A filter for the name/value model. + * @author kgilmer + * + */ + private class MapViewerFilter extends ViewerFilter { + + public MapViewerFilter() { + } + + @Override + public boolean select(Viewer viewer, Object parentElement, Object element) { + String keyFilter = txtName.getText(); + String valFilter = txtValue.getText(); + + String elem = (String) element; + String val = (String) model.get(element); + + if (keyFilter.length() > 0 && elem.indexOf(keyFilter) == -1 ) { + return false; + } + + if (valFilter.length() > 0 && val.indexOf(valFilter) == -1 ) { + return false; + } + + return true; + } + + } + +} diff --git a/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/variable/VariableWizard.java b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/variable/VariableWizard.java new file mode 100644 index 0000000..d93a440 --- /dev/null +++ b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/variable/VariableWizard.java @@ -0,0 +1,43 @@ +package org.openembedded.bc.ui.wizards.variable; + +import java.util.Hashtable; +import java.util.Map; + +import org.eclipse.jface.viewers.IStructuredSelection; +import org.openembedded.bc.ui.wizards.FiniteStateWizard; + + +/** + * This wizard is used to view, filter, and search for BitBake variables and variable contents. + * @author kgilmer + * + */ +public class VariableWizard extends FiniteStateWizard { + + private Map model; + + public VariableWizard(Map model) { + this.model = model; + setWindowTitle("BitBake Commander"); + } + + public VariableWizard(IStructuredSelection selection) { + model = new Hashtable(); + } + + @Override + public void addPages() { + addPage(new VariablePage(model)); + } + + @Override + public Map getModel() { + return model; + } + + @Override + public boolean performFinish() { + return true; + } + +} |