Search in sources :

Example 1 with CreateProjectOperation

use of org.eclipse.ui.ide.undo.CreateProjectOperation in project erlide_eclipse by erlang.

the class ProjectCreator method createProject.

public IProject createProject() throws CoreException {
    final IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final IProject newProjectHandle = workspace.getRoot().getProject(name);
    if (newProjectHandle.exists()) {
        throw new CoreException(Status.OK_STATUS);
    }
    final IProjectDescription description = workspace.newProjectDescription(name);
    description.setLocationURI(location);
    // // update the referenced project if provided
    if (referencedProjects != null) {
        description.setReferencedProjects(referencedProjects);
    }
    // create the new project operation
    final IRunnableWithProgress op = new IRunnableWithProgress() {

        @Override
        public void run(final IProgressMonitor monitor) throws InvocationTargetException {
            final CreateProjectOperation op1 = new CreateProjectOperation(description, WizardMessages.NewProject_windowTitle);
            try {
                // https://bugs.eclipse.org/bugs/show_bug.cgi?id=219901
                // Making this undoable would be a bad idea
                op1.execute(monitor, notifier);
                newProjectHandle.open(monitor);
                description.setNatureIds(new String[] { ErlangCore.NATURE_ID });
                newProjectHandle.setDescription(description, null);
                final BuilderTool builder = info.getBuilder();
                ErlangNature.setErlangProjectBuilder(newProjectHandle, builder);
                createBuilderConfig(builder);
                createFolders(newProjectHandle, Lists.newArrayList(info.getOutputDir()), monitor);
                createFolders(newProjectHandle, info.getSourceDirs(), monitor);
                createFolders(newProjectHandle, info.getIncludeDirs(), monitor);
                createConfig(newProjectHandle, info.getConfigType(), monitor);
                final IErlProject erlProject = ErlangEngine.getInstance().getModel().getErlangProject(newProjectHandle);
                erlProject.setConfigType(info.getConfigType());
                final BuilderProperties builderProperties = new BuilderProperties();
                builderProperties.setBuilderTool(builder);
                builderProperties.setCompileTarget(info.getBuilderData().get("compile"));
                builderProperties.setCleanTarget(info.getBuilderData().get("clean"));
                erlProject.setBuilderProperties(builderProperties);
                erlProject.setProperties(info);
            } catch (final Exception e) {
                throw new InvocationTargetException(e);
            }
        }
    };
    // run the new project creation operation
    try {
        context.run(false, true, op);
    } catch (final InterruptedException e) {
        return null;
    } catch (final InvocationTargetException e) {
        final Throwable t = e.getTargetException();
        if (t instanceof ExecutionException && t.getCause() instanceof CoreException) {
            final CoreException cause = (CoreException) t.getCause();
            StatusAdapter status;
            if (cause.getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) {
                status = new StatusAdapter(StatusUtil.newStatus(IStatus.WARNING, NLS.bind(WizardMessages.NewProject_caseVariantExistsError, newProjectHandle.getName()), cause));
            } else {
                status = new StatusAdapter(StatusUtil.newStatus(cause.getStatus().getSeverity(), WizardMessages.NewProject_errorMessage, cause));
            }
            status.setProperty(IStatusAdapterConstants.TITLE_PROPERTY, WizardMessages.NewProject_errorMessage);
            StatusManager.getManager().handle(status, StatusManager.BLOCK);
        } else {
            final StatusAdapter status = new StatusAdapter(new Status(IStatus.WARNING, ErlideUIPlugin.PLUGIN_ID, 0, NLS.bind(WizardMessages.NewProject_internalError, t.getMessage()), t));
            status.setProperty(IStatusAdapterConstants.TITLE_PROPERTY, WizardMessages.NewProject_errorMessage);
            StatusManager.getManager().handle(status, StatusManager.LOG | StatusManager.BLOCK);
        }
        return null;
    }
    return newProjectHandle;
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IResourceStatus(org.eclipse.core.resources.IResourceStatus) StatusAdapter(org.eclipse.ui.statushandlers.StatusAdapter) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) ExecutionException(org.eclipse.core.commands.ExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) BuilderProperties(org.erlide.engine.model.builder.BuilderProperties) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) CreateProjectOperation(org.eclipse.ui.ide.undo.CreateProjectOperation) ExecutionException(org.eclipse.core.commands.ExecutionException) BuilderTool(org.erlide.engine.model.builder.BuilderTool)

Example 2 with CreateProjectOperation

use of org.eclipse.ui.ide.undo.CreateProjectOperation in project tdq-studio-se by Talend.

the class DQStructureManager method createNewProject.

/**
 * Creates a new project resource with the special name.MOD mzhao 2009-03-18 make this method as public.For
 * {@link org.talend.dataprofiler.core.migration.impl.TDCPFolderMergeTask} use.
 *
 * @return the created project resource, or <code>null</code> if the project was not created
 * @throws InterruptedException
 * @throws InvocationTargetException
 * @throws CoreException
 */
public IProject createNewProject(String projectName) throws InvocationTargetException, InterruptedException, CoreException {
    // get a project handle
    final IProject newProjectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final IProjectDescription description = workspace.newProjectDescription(newProjectHandle.getName());
    // create the new project operation
    IRunnableWithProgress op = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            CreateProjectOperation createProjOp = new CreateProjectOperation(description, // $NON-NLS-1$
            DefaultMessagesImpl.getString("DQStructureManager.createDataProfile"));
            try {
                PlatformUI.getWorkbench().getOperationSupport().getOperationHistory().execute(createProjOp, monitor, WorkspaceUndoUtil.getUIInfoAdapter(null));
            } catch (ExecutionException e) {
                throw new InvocationTargetException(e);
            }
        }
    };
    // project always exist.
    if (!newProjectHandle.exists()) {
        ProgressUI.popProgressDialog(op);
    }
    return newProjectHandle;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) CreateProjectOperation(org.eclipse.ui.ide.undo.CreateProjectOperation) ExecutionException(org.eclipse.core.commands.ExecutionException) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 3 with CreateProjectOperation

use of org.eclipse.ui.ide.undo.CreateProjectOperation in project mdw-designer by CenturyLinkCloud.

the class ProjectInflator method inflateCloudProject.

public void inflateCloudProject(final IRunnableContext container) {
    getProject().setCloudProject(true);
    // get a project handle
    final IProject newProjectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(workflowProject.getName());
    // get a project descriptor
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final IProjectDescription description = workspace.newProjectDescription(newProjectHandle.getName());
    // create the new project operation
    IRunnableWithProgress op = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            Repository newRepo = null;
            try {
                if (workflowProject.getPersistType() == PersistType.Git)
                    createGitRepository(monitor);
                CreateProjectOperation op = new CreateProjectOperation(description, "MDW Cloud Project");
                PlatformUI.getWorkbench().getOperationSupport().getOperationHistory().execute(op, monitor, WorkspaceUndoUtil.getUIInfoAdapter(shell));
            } catch (Exception ex) {
                throw new InvocationTargetException(ex);
            } finally {
                if (newRepo != null)
                    newRepo.close();
            }
        }
    };
    // run the new project creation operation
    try {
        container.run(false, false, op);
        ProgressMonitorDialog pmDialog = new MdwProgressMonitorDialog(MdwPlugin.getShell());
        pmDialog.run(true, false, new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask("Inflating Workflow Project", 250);
                monitor.worked(5);
                // configure as Java project
                ProjectConfigurator projConf = new ProjectConfigurator(getProject(), MdwPlugin.getSettings());
                projConf.setJava(new SubProgressMonitor(monitor, 3));
                ProjectUpdater updater = new ProjectUpdater(getProject(), MdwPlugin.getSettings());
                // bootstrap
                updater.updateMappingFiles(new SubProgressMonitor(monitor, 3));
                // versions
                // of
                // the
                // property
                // files
                updater.updateFrameworkJars(new SubProgressMonitor(monitor, 150));
                updater.updateWebProjectJars(new SubProgressMonitor(monitor, 50));
                try {
                    if (getProject().isOsgi())
                        projConf.addJavaProjectSourceFolder(getProject().getOsgiSettings().getSourceDir(), new SubProgressMonitor(monitor, 3));
                    else if (!getProject().isWar())
                        projConf.addJavaProjectSourceFolder("src", monitor);
                    projConf.setJavaBuildOutputPath("build/classes", new SubProgressMonitor(monitor, 5));
                    projConf.addFrameworkJarsToClasspath(monitor);
                    // add the workflow facet
                    // already
                    getProject().setSkipFacetPostInstallUpdates(true);
                    // did
                    // framework
                    // updates
                    IFacetedProject facetedProject = ProjectFacetsManager.create(getProject().getSourceProject(), true, new SubProgressMonitor(monitor, 3));
                    IProjectFacetVersion javaFacetVersion = ProjectFacetsManager.getProjectFacet("java").getDefaultVersion();
                    if (Float.parseFloat(javaFacetVersion.getVersionString()) < 1.6)
                        javaFacetVersion = ProjectFacetsManager.getProjectFacet("java").getVersion("1.6");
                    if (workflowProject.isCloudOnly())
                        javaFacetVersion = ProjectFacetsManager.getProjectFacet("java").getVersion("1.7");
                    facetedProject.installProjectFacet(javaFacetVersion, null, new SubProgressMonitor(monitor, 3));
                    IProjectFacetVersion mdwFacet = ProjectFacetsManager.getProjectFacet("mdw.workflow").getDefaultVersion();
                    facetedProject.installProjectFacet(mdwFacet, getProject(), new SubProgressMonitor(monitor, 3));
                    if (workflowProject.isOsgi()) {
                        IProjectFacet utilFacet = ProjectFacetsManager.getProjectFacet("jst.utility");
                        IProjectFacetVersion facetVer = utilFacet.getDefaultVersion();
                        IActionDefinition def = facetVer.getActionDefinition(null, IFacetedProject.Action.Type.INSTALL);
                        Object cfg = def.createConfigObject();
                        facetedProject.installProjectFacet(ProjectFacetsManager.getProjectFacet("jst.utility").getDefaultVersion(), cfg, new SubProgressMonitor(monitor, 3));
                    } else if (workflowProject.isWar()) {
                        // add the facet to the xml file
                        IFile facetsFile = workflowProject.getSourceProject().getFile(".settings/org.eclipse.wst.common.project.facet.core.xml");
                        if (facetsFile.exists()) {
                            String content = new String(PluginUtil.readFile(facetsFile));
                            int insert = content.indexOf("</faceted-project>");
                            content = content.substring(0, insert) + "  <installed facet=\"jst.web\" version=\"3.0\"/>\n" + content.substring(insert);
                            PluginUtil.writeFile(facetsFile, content, new SubProgressMonitor(monitor, 3));
                        }
                    }
                    final ProjectConfigurator configurator = new ProjectConfigurator(getProject(), MdwPlugin.getSettings());
                    if (!workflowProject.isOsgi() && !workflowProject.isWar()) {
                        MdwPlugin.getDisplay().syncExec(new Runnable() {

                            public void run() {
                                try {
                                    configurator.createFrameworkSourceCodeAssociations(MdwPlugin.getShell(), new NullProgressMonitor());
                                } catch (CoreException ex) {
                                    PluginMessages.log(ex);
                                }
                            }
                        });
                    }
                    if (workflowProject.isOsgi()) {
                        generateOsgiArtifacts(new SubProgressMonitor(monitor, 10));
                        configurator.configureOsgiProject(shell, new SubProgressMonitor(monitor, 5));
                    } else if (workflowProject.isWar()) {
                        generateWarCloudArtifacts(new SubProgressMonitor(monitor, 10));
                        // force
                        configurator.addMavenNature(new SubProgressMonitor(monitor, 5));
                    // maven
                    // refresh
                    }
                } catch (Exception ex) {
                    throw new InvocationTargetException(ex);
                }
            }
        });
    } catch (Exception ex) {
        PluginMessages.uiError(ex, "Create Cloud Project", workflowProject);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFacetedProject(org.eclipse.wst.common.project.facet.core.IFacetedProject) IFile(org.eclipse.core.resources.IFile) MdwProgressMonitorDialog(com.centurylink.mdw.plugin.designer.dialogs.MdwProgressMonitorDialog) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProjectFacetVersion(org.eclipse.wst.common.project.facet.core.IProjectFacetVersion) IActionDefinition(org.eclipse.wst.common.project.facet.core.IActionDefinition) MdwProgressMonitorDialog(com.centurylink.mdw.plugin.designer.dialogs.MdwProgressMonitorDialog) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IProject(org.eclipse.core.resources.IProject) URISyntaxException(java.net.URISyntaxException) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) ExecutionException(org.eclipse.core.commands.ExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) Repository(org.eclipse.jgit.lib.Repository) VcsRepository(com.centurylink.mdw.plugin.project.model.VcsRepository) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IProjectFacet(org.eclipse.wst.common.project.facet.core.IProjectFacet) CreateProjectOperation(org.eclipse.ui.ide.undo.CreateProjectOperation)

Example 4 with CreateProjectOperation

use of org.eclipse.ui.ide.undo.CreateProjectOperation in project tdi-studio-se by Talend.

the class ComponentProjectManager method createNewProject.

/**
     * Creates a new project resource with the selected name.
     * <p>
     * In normal usage, this method is invoked after the user has pressed Finish on the wizard; the enablement of the
     * Finish button implies that all controls on the pages currently contain valid values.
     * </p>
     * <p>
     * Note that this wizard caches the new project once it has been successfully created; subsequent invocations of
     * this method will answer the same project resource without attempting to create it again.
     * </p>
     * 
     * @return the created project resource, or <code>null</code> if the project was not created
     */
public IProject createNewProject(String directroy, String projectName, Shell shell) {
    if (projDir.equals(directroy)) {
        return project;
    }
    final Shell currentShell = shell;
    // get a project handle
    final IProject newProjectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
    if (newProjectHandle.getRawLocation() != null) {
        if (newProjectHandle.getRawLocation().equals(directroy)) {
            return newProjectHandle;
        } else {
            try {
                newProjectHandle.delete(false, true, null);
            } catch (CoreException e) {
                // e.printStackTrace();
                org.talend.componentdesigner.exception.ExceptionHandler.process(e);
            }
        }
    }
    // final IJavaProject javaProjHandle = JavaCore.create(newProjectHandle);
    // get a project descriptor
    URI location = null;
    if (directroy == null || directroy.equals(PluginConstant.EMPTY_STRING)) {
        return null;
    } else {
        location = new File(directroy).toURI();
    }
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final IProjectDescription description = workspace.newProjectDescription(newProjectHandle.getName());
    description.setLocationURI(location);
    // create the new project operation
    IRunnableWithProgress op = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            CreateProjectOperation op = new CreateProjectOperation(description, //$NON-NLS-1$
            Messages.getString("ComponentProjectManager.NewProject"));
            try {
                PlatformUI.getWorkbench().getOperationSupport().getOperationHistory().execute(op, monitor, WorkspaceUndoUtil.getUIInfoAdapter(currentShell));
            } catch (ExecutionException e) {
                throw new InvocationTargetException(e);
            }
        }
    };
    // run the new project creation o`peration
    try {
        ProgressUI.popProgressDialog(op, shell);
    } catch (InterruptedException e) {
        return null;
    } catch (InvocationTargetException e) {
        Throwable t = e.getTargetException();
        if (t instanceof ExecutionException && t.getCause() instanceof CoreException) {
            CoreException cause = (CoreException) t.getCause();
            StatusAdapter status;
            if (cause.getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) {
                status = new StatusAdapter(new Status(IStatus.WARNING, ComponentDesigenerPlugin.PLUGIN_ID, IStatus.WARNING, Messages.getString("ComponentProjectManager.WarningMsg", //$NON-NLS-1$
                newProjectHandle.getName()), cause));
            } else {
                status = new StatusAdapter(new Status(cause.getStatus().getSeverity(), ComponentDesigenerPlugin.PLUGIN_ID, cause.getStatus().getSeverity(), Messages.getString("ComponentProjectManager.CreationProblems"), //$NON-NLS-1$
                cause));
            }
            //$NON-NLS-1$
            status.setProperty(StatusAdapter.TITLE_PROPERTY, Messages.getString("ComponentProjectManager.CreationProblems"));
            StatusManager.getManager().handle(status, StatusManager.BLOCK);
        } else {
            StatusAdapter status = new StatusAdapter(new Status(IStatus.WARNING, ComponentDesigenerPlugin.PLUGIN_ID, 0, Messages.getString("ComponentProjectManager.InternalErrorMsg", t.getMessage()), //$NON-NLS-1$
            t));
            //$NON-NLS-1$
            status.setProperty(StatusAdapter.TITLE_PROPERTY, Messages.getString("ComponentProjectManager.CreationProblems"));
            StatusManager.getManager().handle(status, StatusManager.LOG | StatusManager.BLOCK);
        }
        return null;
    }
    project = newProjectHandle;
    return project;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IResourceStatus(org.eclipse.core.resources.IResourceStatus) StatusAdapter(org.eclipse.ui.statushandlers.StatusAdapter) URI(java.net.URI) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) CreateProjectOperation(org.eclipse.ui.ide.undo.CreateProjectOperation) ExecutionException(org.eclipse.core.commands.ExecutionException) File(java.io.File)

Example 5 with CreateProjectOperation

use of org.eclipse.ui.ide.undo.CreateProjectOperation in project mdw-designer by CenturyLinkCloud.

the class ProjectInflator method inflateRemoteProject.

public void inflateRemoteProject(final IRunnableContext container) {
    // get a project handle
    final IProject newProjectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(workflowProject.getName());
    // get a project descriptor
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final IProjectDescription description = workspace.newProjectDescription(newProjectHandle.getName());
    // create the new project operation
    IRunnableWithProgress op = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            CreateProjectOperation op = new CreateProjectOperation(description, "MDW Remote Project");
            try {
                PlatformUI.getWorkbench().getOperationSupport().getOperationHistory().execute(op, monitor, WorkspaceUndoUtil.getUIInfoAdapter(shell));
            } catch (ExecutionException ex) {
                throw new InvocationTargetException(ex);
            }
        }
    };
    // run the new project creation operation
    try {
        container.run(true, true, op);
    } catch (Exception ex) {
        PluginMessages.uiError(shell, ex, "Create Remote Project", workflowProject);
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) CreateProjectOperation(org.eclipse.ui.ide.undo.CreateProjectOperation) ExecutionException(org.eclipse.core.commands.ExecutionException) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) URISyntaxException(java.net.URISyntaxException) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) ExecutionException(org.eclipse.core.commands.ExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)5 ExecutionException (org.eclipse.core.commands.ExecutionException)5 IProject (org.eclipse.core.resources.IProject)5 IProjectDescription (org.eclipse.core.resources.IProjectDescription)5 IWorkspace (org.eclipse.core.resources.IWorkspace)5 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)5 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)5 CreateProjectOperation (org.eclipse.ui.ide.undo.CreateProjectOperation)5 CoreException (org.eclipse.core.runtime.CoreException)4 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2 IResourceStatus (org.eclipse.core.resources.IResourceStatus)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 StatusAdapter (org.eclipse.ui.statushandlers.StatusAdapter)2 MdwProgressMonitorDialog (com.centurylink.mdw.plugin.designer.dialogs.MdwProgressMonitorDialog)1 VcsRepository (com.centurylink.mdw.plugin.project.model.VcsRepository)1 File (java.io.File)1 URI (java.net.URI)1 IFile (org.eclipse.core.resources.IFile)1