mirror of
https://github.com/processing/processing4.git
synced 2026-02-12 18:10:43 +01:00
Added some UI for the export wizard. Still non-functioning.
This commit is contained in:
@@ -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<ProjectTableEntryModel> 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<ProjectTableEntryModel>();
|
||||
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");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.
|
||||
* <p>
|
||||
* 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user