From f42f65c8ceb9910c18cbb929d203e997d168a57b Mon Sep 17 00:00:00 2001 From: lonnen Date: Fri, 17 Sep 2010 20:40:46 +0000 Subject: [PATCH] Added some UI for the export wizard. Still non-functioning. --- .../Processing Plugin for Eclipse/feature.xml | 2 +- .../META-INF/MANIFEST.MF | 2 +- .../processing.plugin.ui/META-INF/MANIFEST.MF | 2 +- ...xportAsAppletSelectProjectsWizardPage.java | 180 ++++++++++++++++++ .../ui/wizards/ExportAsAppletWizard.java | 71 +++---- .../ui/wizards/ExportAsAppletWizardPage.java | 70 ------- 6 files changed, 212 insertions(+), 115 deletions(-) create mode 100644 editor/processing.plugin.ui/src/processing/plugin/ui/wizards/ExportAsAppletSelectProjectsWizardPage.java delete mode 100644 editor/processing.plugin.ui/src/processing/plugin/ui/wizards/ExportAsAppletWizardPage.java diff --git a/editor/Processing Plugin for Eclipse/feature.xml b/editor/Processing Plugin for Eclipse/feature.xml index 4d1bdb42f..2a60da974 100644 --- a/editor/Processing Plugin for Eclipse/feature.xml +++ b/editor/Processing Plugin for Eclipse/feature.xml @@ -2,7 +2,7 @@ diff --git a/editor/processing.plugin.core/META-INF/MANIFEST.MF b/editor/processing.plugin.core/META-INF/MANIFEST.MF index aea013b8f..ae0ea0a29 100644 --- a/editor/processing.plugin.core/META-INF/MANIFEST.MF +++ b/editor/processing.plugin.core/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Processing Plugin Core Bundle-SymbolicName: processing.plugin.core;singleton:=true -Bundle-Version: 0.1.0.1 +Bundle-Version: 0.2.0.0 Bundle-Activator: processing.plugin.core.ProcessingCore Bundle-Vendor: Processing.org Require-Bundle: org.eclipse.core.runtime, diff --git a/editor/processing.plugin.ui/META-INF/MANIFEST.MF b/editor/processing.plugin.ui/META-INF/MANIFEST.MF index d33ea31aa..6708a0409 100644 --- a/editor/processing.plugin.ui/META-INF/MANIFEST.MF +++ b/editor/processing.plugin.ui/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Processing Plugin User Interface Elements Bundle-SymbolicName: processing.plugin.ui;singleton:=true -Bundle-Version: 0.1.4.1 +Bundle-Version: 0.2.0.0 Bundle-Activator: processing.plugin.ui.ProcessingPlugin Bundle-Vendor: Processing.org Require-Bundle: org.eclipse.ui, diff --git a/editor/processing.plugin.ui/src/processing/plugin/ui/wizards/ExportAsAppletSelectProjectsWizardPage.java b/editor/processing.plugin.ui/src/processing/plugin/ui/wizards/ExportAsAppletSelectProjectsWizardPage.java new file mode 100644 index 000000000..60e3a6560 --- /dev/null +++ b/editor/processing.plugin.ui/src/processing/plugin/ui/wizards/ExportAsAppletSelectProjectsWizardPage.java @@ -0,0 +1,180 @@ +/** + * Copyright (c) 2010 Chris Lonnen. 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.opensource.org/licenses/eclipse-1.0.php + * + * Contributors: + * Chris Lonnen - initial API and implementation + */ +package processing.plugin.ui.wizards; + +import java.util.ArrayList; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.jface.viewers.CheckboxTableViewer; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; + +import processing.plugin.core.builder.SketchProject; + +/** And export wizard page allowing users to select which projects are going to be exported. */ +public class ExportAsAppletSelectProjectsWizardPage extends WizardPage { + + /** Internal class for building the export wizard table. */ + private class ProjectTableContentProvider implements IStructuredContentProvider{ + + ArrayList entries; + + public ProjectTableContentProvider(){ + this.updateProjectList(); + } + + public void dispose() { entries = null; } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + this.updateProjectList(); + } + + /** Dumps the list of open SketchProjects */ + public Object[] getElements(Object inputElement) { + return entries.toArray(); + } + + /** Grabs all open sketch projects from the workplace and adds them to the array */ + public void updateProjectList(){ + entries = new ArrayList(); + IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); + for(IProject p: projects){ + if (p == null) break; + if (!p.isAccessible()) break; + if (SketchProject.isSketchProject(p)){ + ProjectTableEntryModel entry = new ProjectTableEntryModel(); + if (entry.setEntry(p)) entries.add(entry); + } + } + + } + + } + + /** A model for a sketch project and a message about its last build. */ + public class ProjectTableEntryModel { + + private SketchProject sp; + + public ProjectTableEntryModel(){} + + public boolean setEntry(IProject project){ + SketchProject candidate = SketchProject.forProject(project); + return setEntry(candidate); + } + + public boolean setEntry(SketchProject project){ + if (project == null) return false; + sp = project; + System.out.println("Adding: " + project.getProject().getName()); + return true; + } + + public SketchProject getProject(){ return sp; } + + public String getAdditionalMessage(){ + return (sp.wasLastBuildSuccessful()) ? "" : "Warning: there were errors on the last build."; + } + + } + + /** Provides text for a model entry item */ + public class ProjectTableLabelProvider implements ITableLabelProvider{ + + // do nothing + public void addListener(ILabelProviderListener listener) { } + + // do nothing + public void dispose() { } + + // do nothing + public boolean isLabelProperty(Object element, String property) { return false; } + + // do nothing + public void removeListener(ILabelProviderListener listener) { } + + // no images + public Image getColumnImage(Object element, int columnIndex) { return null; } + + /** Gets the column text */ + public String getColumnText(Object element, int columnIndex) { + System.out.println(element.toString()); + System.out.println(columnIndex); + switch (columnIndex) { + case 0: // project + if (element instanceof ProjectTableEntryModel) + return ((ProjectTableEntryModel) element).getProject().getProject().getName(); + if (element != null) + element.toString(); + return ""; + case 1: // warning message + if (element instanceof ProjectTableEntryModel) + return ((ProjectTableEntryModel) element).getAdditionalMessage(); + return ""; + default: + return ""; + } + } + + } + + /** a checkbox table of workspace projects */ + private CheckboxTableViewer projectTable; + + /* constructor */ + protected ExportAsAppletSelectProjectsWizardPage(String pageName) { + super(pageName); + setTitle("Export Sketch as Applet Wizard"); + setDescription("Select the Sketch projects to be exported."); + } + + /* create the GUI stuff */ + public void createControl(Composite parent) { + Composite container = new Composite(parent, SWT.NULL); + container.setLayout(new FormLayout()); + setControl(container); + + projectTable = CheckboxTableViewer.newCheckList(container, SWT.BORDER); + projectTable.setContentProvider(new ProjectTableContentProvider()); + projectTable.setLabelProvider(new ProjectTableLabelProvider()); + + final FormData formData = new FormData(); + formData.bottom = new FormAttachment(100,0); + formData.right = new FormAttachment(100,0); + formData.top = new FormAttachment(0,0); + formData.left = new FormAttachment(0,0); + + final Table table = projectTable.getTable(); + table.setLayoutData(formData); + table.setHeaderVisible(true); + + final TableColumn rightTableColumn = new TableColumn(table,SWT.NONE); + rightTableColumn.setWidth(200); + rightTableColumn.setText("Name"); + + final TableColumn leftTableColumn = new TableColumn(table,SWT.NONE); + leftTableColumn.setWidth(250); + leftTableColumn.setText("Notes"); + } + +} diff --git a/editor/processing.plugin.ui/src/processing/plugin/ui/wizards/ExportAsAppletWizard.java b/editor/processing.plugin.ui/src/processing/plugin/ui/wizards/ExportAsAppletWizard.java index e37a288d3..b69467b66 100644 --- a/editor/processing.plugin.ui/src/processing/plugin/ui/wizards/ExportAsAppletWizard.java +++ b/editor/processing.plugin.ui/src/processing/plugin/ui/wizards/ExportAsAppletWizard.java @@ -10,33 +10,25 @@ */ package processing.plugin.ui.wizards; -import java.util.Iterator; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; +//import java.util.Iterator; +//import org.eclipse.core.resources.IProject; +//import org.eclipse.core.resources.IResource; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.Wizard; import org.eclipse.ui.IExportWizard; import org.eclipse.ui.IWorkbench; -import processing.plugin.core.builder.SketchProject; /** - * A wizard to export a Processing sketch project as an applet + * An export wizard for processing projects. *

- * Contains a single page. - * @author lonnen - * + * The single page presents users with a list of open sketch Projects in + * the workspace and the user can check one or all of them to export. */ public class ExportAsAppletWizard extends Wizard implements IExportWizard { /** single page */ - private ExportAsAppletWizardPage page; - - /** The project to be exported */ - private IProject project; - - /** The current selection when the export is called. */ - private IStructuredSelection fSelection; + private ExportAsAppletSelectProjectsWizardPage page; public ExportAsAppletWizard() {} @@ -48,39 +40,34 @@ public class ExportAsAppletWizard extends Wizard implements IExportWizard { * page prompts with the name of the sketch before continuing. */ public void init(IWorkbench workbench, IStructuredSelection selection) { - workbench.getActiveWorkbenchWindow().getActivePage(); - Iterator iter = selection.iterator(); - while (iter.hasNext()){ - Object selectedElement = iter.next(); - if (selectedElement instanceof IProject) { - IProject proj = (IProject) selectedElement; - if(SketchProject.isSketchProject(proj)){ - - } - } else if (selectedElement instanceof IResource){ - IProject proj = ((IResource) selectedElement).getProject(); - if(SketchProject.isSketchProject(proj)){ - setProject(proj); - break; - } - } - } - - } - - public void setProject(IProject project){ - this.project = project; - if (page != null) page.setProject(project); - } +// workbench.getActiveWorkbenchWindow().getActivePage(); +// Iterator iter = selection.iterator(); +// while (iter.hasNext()){ +// Object selectedElement = iter.next(); +// if (selectedElement instanceof IProject) { +// IProject proj = (IProject) selectedElement; +// if(SketchProject.isSketchProject(proj)){ +// +// } +// } else if (selectedElement instanceof IResource){ +// IProject proj = ((IResource) selectedElement).getProject(); +// if(SketchProject.isSketchProject(proj)){ +// setProject(proj); +// break; +// } +// } + // Nowadays the page takes care of it. User selects from whatever is open. + + } public void addPages(){ - page = new ExportAsAppletWizardPage("Export Sketch Wizard"); - page.setProject(project); + page = new ExportAsAppletSelectProjectsWizardPage("Export Sketch Wizard"); addPage(page); } public boolean performFinish() { - return SketchProject.forProject(page.getProject()).exportAsApplet(); +// return SketchProject.forProject(page.getProject()).exportAsApplet(); + return false; } } diff --git a/editor/processing.plugin.ui/src/processing/plugin/ui/wizards/ExportAsAppletWizardPage.java b/editor/processing.plugin.ui/src/processing/plugin/ui/wizards/ExportAsAppletWizardPage.java deleted file mode 100644 index 0f618cf9d..000000000 --- a/editor/processing.plugin.ui/src/processing/plugin/ui/wizards/ExportAsAppletWizardPage.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Copyright (c) 2010 Chris Lonnen. 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.opensource.org/licenses/eclipse-1.0.php - * - * Contributors: - * Chris Lonnen - initial API and implementation - */ -package processing.plugin.ui.wizards; - -import org.eclipse.core.resources.IProject; -import org.eclipse.jface.wizard.WizardPage; -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; - -public class ExportAsAppletWizardPage extends WizardPage { - - IProject project; - - /** should only be instantiated by its corresponding wizard */ - protected ExportAsAppletWizardPage(String pageName) { - super(pageName); - setTitle("Export Sketch Wizard"); - setDescription("Export your sketch as an applet."); - } - - public void setProject(IProject project){ - this.project = project; - } - - /** nothing fancy here, just a confirmation. the core will handle most of it. */ - public void createControl(Composite parent) { - setPageComplete(false); - - Composite container = new Composite(parent, SWT.NULL); - final GridLayout gridLayout = new GridLayout(); - gridLayout.numColumns = 3; - container.setLayout(gridLayout); - setControl(container); - - final Label label = new Label(container, SWT.NONE); - final Label label2 = new Label(container, SWT.NONE); - final GridData gridData = new GridData(); - gridData.horizontalSpan = 3; - label.setLayoutData(gridData); - label2.setLayoutData(gridData); - if (project != null ){ - label.setText( - "You're about to export " + project.getName() + " as an applet."); - label2.setText( - "Click finish to proceed or cancel to select a different sketch."); - setPageComplete(true); - } else { - label.setText( - "The wizard cannot figure out what you are trying to export."); - label2.setText( - "Click cancel to go back and select a different sketch or .pde file."); - } - } - - public IProject getProject(){ - return project; - } - -}