[Esbox-commits] r182 - trunk/org.indt.esbox.python.ui/src/org/indt/esbox/python/ui/wizards
carolina at garage.maemo.org
carolina at garage.maemo.org
Thu Oct 25 22:24:44 EEST 2007
Author: carolina
Date: 2007-10-25 22:24:42 +0300 (Thu, 25 Oct 2007)
New Revision: 182
Added:
trunk/org.indt.esbox.python.ui/src/org/indt/esbox/python/ui/wizards/ESboxPythonProjectWizard.java
Log:
Fixing some details on Python Wizard
Added: trunk/org.indt.esbox.python.ui/src/org/indt/esbox/python/ui/wizards/ESboxPythonProjectWizard.java
===================================================================
--- trunk/org.indt.esbox.python.ui/src/org/indt/esbox/python/ui/wizards/ESboxPythonProjectWizard.java (rev 0)
+++ trunk/org.indt.esbox.python.ui/src/org/indt/esbox/python/ui/wizards/ESboxPythonProjectWizard.java 2007-10-25 19:24:42 UTC (rev 182)
@@ -0,0 +1,320 @@
+package org.indt.esbox.python.ui.wizards;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceStatus;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.WorkbenchException;
+import org.eclipse.ui.actions.WorkspaceModifyOperation;
+import org.eclipse.ui.dialogs.WizardNewProjectReferencePage;
+import org.python.pydev.plugin.PydevPlugin;
+import org.python.pydev.plugin.nature.PythonNature;
+import org.python.pydev.ui.perspective.PythonPerspectiveFactory;
+
+public class ESboxPythonProjectWizard extends Wizard implements INewWizard {
+
+ private IWorkbench workbench;
+
+ // private ISessionLocation session;
+
+ private boolean isNewSession;
+
+ protected IStructuredSelection selection;
+
+ protected IProject generatedProject;
+
+ protected NewPythonProjectWizardPage projectPage;
+
+ // protected SessionSelectionPage sessionSelectionPage;
+
+ //protected ConfigurationWizardMainPage newSessionPage;
+
+ protected WizardNewProjectReferencePage referencePage;
+
+ public ESboxPythonProjectWizard() {
+ super();
+ setNeedsProgressMonitor(true);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
+ */
+ public void init(IWorkbench workbench, IStructuredSelection currentSelection) {
+ this.workbench = workbench;
+ this.selection = currentSelection;
+ initializeDefaultPageImageDescriptor();
+ }
+
+ /**
+ * Add wizard pages to the instance
+ *
+ * @see org.eclipse.jface.wizard.IWizard#addPages()
+ */
+ public void addPages() {
+ projectPage = new NewPythonProjectWizardPage("ESbox Project Page");
+ projectPage.setTitle("Python Maemo Project");
+ projectPage.setDescription("Creates a new Python Maemo Project");
+ addPage(projectPage);
+
+// ISessionLocation[] sessions = KnownSessions.getInstance().getSessions();
+// if(sessions.length > 0) {
+// sessionSelectionPage = new SessionSelectionPage("Python Maemo Session Selection Page","Python Maemo Project",null);
+// sessionSelectionPage.setDescription("Select a session for your Python Maemo project");
+// addPage(sessionSelectionPage);
+// }
+//
+// newSessionPage = new ConfigurationWizardMainPage("Python Maemo New Session Page","Python Maemo Project",null);
+// newSessionPage.setDescription("Create a session for your Python Maemo project");
+// addPage(newSessionPage);
+
+ // only add page if there are already projects in the workspace
+ if (ResourcesPlugin.getWorkspace().getRoot().getProjects().length > 0) {
+ referencePage = new WizardNewProjectReferencePage("Reference Page");
+ referencePage.setTitle("Reference page");
+ referencePage.setDescription("Select referenced projects");
+ addPage(referencePage);
+ }
+
+ }
+
+ /**
+ * Creates a project resource given the project handle and description.
+ *
+ * @param description the project description to create a project resource for
+ * @param projectHandle the project handle to create a project resource for
+ * @param monitor the progress monitor to show visual progress with
+ * @param projectType
+ *
+ * @exception CoreException if the operation fails
+ * @exception OperationCanceledException if the operation is canceled
+ */
+ private void createProject(IProjectDescription description, IProject projectHandle, IProgressMonitor monitor, String projectType) throws CoreException, OperationCanceledException {
+ try {
+ monitor.beginTask("", 2000); //$NON-NLS-1$
+
+ projectHandle.create(description, new SubProgressMonitor(monitor, 1000));
+
+ if (monitor.isCanceled()){
+ throw new OperationCanceledException();
+ }
+
+ projectHandle.open(IResource.BACKGROUND_REFRESH, new SubProgressMonitor(monitor, 1000));
+
+ String projectPythonpath = null;
+ //also, after creating the project, create a default source folder and add it to the pythonpath.
+ if(projectPage.shouldCreatSourceFolder()){
+ IFolder folder = projectHandle.getFolder("src");
+ folder.create(true, true, monitor);
+
+ projectPythonpath = folder.getFullPath().toString();
+ }
+
+ //we should rebuild the path even if there's no source-folder (this way we will re-create the astmanager)
+ PythonNature.addNature(projectHandle, null, projectType, projectPythonpath);
+ ESboxPythonProjectNature.getDefault().addESboxPythonNature(projectHandle, /*session.getLocation(false)*/null,monitor);
+ } finally {
+ monitor.done();
+ }
+ }
+
+ /**
+ * Creates a new project resource with the entered name.
+ *
+ * @return the created project resource, or <code>null</code> if the project was not created
+ */
+ private IProject createNewProject() {
+ // get a project handle
+ final IProject newProjectHandle = projectPage.getProjectHandle();
+
+ // get a project descriptor
+ IPath defaultPath = Platform.getLocation();
+ IPath newPath = projectPage.getLocationPath();
+ if (defaultPath.equals(newPath)){
+ newPath = null;
+ }
+
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ final IProjectDescription description = workspace.newProjectDescription(newProjectHandle.getName());
+ description.setLocation(newPath);
+
+ // update the referenced project if provided
+ if (referencePage != null) {
+ IProject[] refProjects = referencePage.getReferencedProjects();
+ if (refProjects.length > 0)
+ description.setReferencedProjects(refProjects);
+ }
+
+ final String projectType = "python";
+ // define the operation to create a new project
+ WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
+ protected void execute(IProgressMonitor monitor) throws CoreException {
+ createProject(description, newProjectHandle, monitor, projectType);
+ }
+ };
+
+ // run the operation to create a new project
+ try {
+ getContainer().run(true, true, op);
+ } catch (InterruptedException e) {
+ return null;
+ } catch (InvocationTargetException e) {
+ Throwable t = e.getTargetException();
+ if (t instanceof CoreException) {
+ if (((CoreException) t).getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) {
+ MessageDialog.openError(getShell(), "IDEWorkbenchMessages.CreateProjectWizard_errorTitle", "IDEWorkbenchMessages.CreateProjectWizard_caseVariantExistsError");
+ } else {
+ ErrorDialog.openError(getShell(), "IDEWorkbenchMessages.CreateProjectWizard_errorTitle", null, ((CoreException) t).getStatus());
+ }
+ } else {
+ // Unexpected runtime exceptions and errors may still occur.
+ PydevPlugin.log(IStatus.ERROR, t.toString(), t);
+ MessageDialog.openError(getShell(), "IDEWorkbenchMessages.CreateProjectWizard_errorTitle", t.getMessage());
+ }
+ return null;
+ }
+
+ generatedProject = newProjectHandle;
+
+ return newProjectHandle;
+ }
+
+ /**
+ * The user clicked Finish button
+ *
+ * Launches another thread to create Python project. A progress monitor is shown in the UI thread.
+ */
+ public boolean performFinish() {
+ checkRepository();
+ createNewProject();
+
+ // Switch to default perspective
+ IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
+
+ try {
+ workbench.showPerspective(PythonPerspectiveFactory.PERSPECTIVE_ID, window);
+ } catch (WorkbenchException we) {
+ we.printStackTrace();
+ }
+
+ return true;
+ }
+
+ /**
+ * Set Python logo to top bar
+ */
+ protected void initializeDefaultPageImageDescriptor() {
+ ImageDescriptor desc = PydevPlugin.imageDescriptorFromPlugin(PydevPlugin.getPluginID(), "icons/python_logo.png");//$NON-NLS-1$
+ setDefaultPageImageDescriptor(desc);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.wizard.Wizard#getNextPage(org.eclipse.jface.wizard.IWizardPage)
+ */
+ public IWizardPage getNextPage(IWizardPage page) {
+// if (page == sessionSelectionPage) {
+// if (sessionSelectionPage.getLocation() == null) {
+// return newSessionPage;
+// } else {
+// try {
+// session = getLocation();
+// newSessionPage.setPageComplete(true);
+// return super.getNextPage(newSessionPage);
+// } catch (SSHException e) {
+// PythonUIActivator.getDefault().log(e);
+// }
+// }
+// } else {
+// if (page == newSessionPage) {
+// try {
+// session = getLocation();
+// } catch (SSHException e) {
+// PythonUIActivator.getDefault().log(e);
+// }
+// }
+// }
+ return super.getNextPage(page);
+ }
+
+ @Override
+ public boolean performCancel() {
+// if (session != null && isNewSession) {
+// KnownSessions.getInstance().disposeSession(session);
+// session = null;
+// }
+ return super.performCancel();
+
+ }
+
+ private void checkRepository() {
+// if (isNewSession) {
+// KnownSessions.getInstance().addSession(session, true /* broadcast */);
+// }
+ }
+
+// private ISessionLocation getLocation() throws SSHException {
+// // If the location page has a location, use it.
+// if (sessionSelectionPage != null) {
+// ISessionLocation newLocation = sessionSelectionPage.getLocation();
+// if (newLocation != null) {
+// return recordLocation(newLocation);
+// }
+// }
+//
+// // Otherwise, get the location from the create location page
+// final ISessionLocation[] locations = new ISessionLocation[] { null };
+// final SSHException[] exception = new SSHException[] { null };
+// getShell().getDisplay().syncExec(new Runnable() {
+// public void run() {
+// try {
+// locations[0] = newSessionPage.getLocation();
+// } catch (SSHException e) {
+// exception[0] = e;
+// }
+// }
+// });
+// if (exception[0] != null) {
+// throw exception[0];
+// }
+// return recordLocation(locations[0]);
+// }
+
+// private ISessionLocation recordLocation(ISessionLocation newSession) {
+// if (newSession == null) return session;
+// if (session == null || !newSession.equals(session)) {
+// if (session != null && isNewSession) {
+// // Dispose of the previous location
+// KnownSessions.getInstance().disposeSession(session);
+// }
+// session = newSession;
+// isNewSession = !KnownSessions.getInstance().isKnownSession(newSession.getLocation(false));
+// if (isNewSession) {
+// // Add the location silently so we can work with it
+// session = KnownSessions.getInstance().addSession(session, false /* silently */);
+// }
+// }
+// return session;
+// }
+}
More information about the Esbox-commits
mailing list