Search in sources :

Example 11 with WorkspaceModifyOperation

use of org.eclipse.ui.actions.WorkspaceModifyOperation in project knime-core by knime.

the class WorkflowImportWizard method createWorkflows.

/**
 * Create the selected workflows.
 *
 * @return boolean <code>true</code> if all project creations were
 *         successful.
 */
public boolean createWorkflows() {
    final boolean copy = m_import.isCopyWorkflows();
    final String target = m_import.getDestination();
    final Collection<IWorkflowImportElement> workflows = m_import.getWorkflowsToImport();
    // validate target path
    final IPath targetPath = getValidatedTargetPath(target);
    WorkspaceModifyOperation op = new WorkflowImportOperation(workflows, targetPath, copy, getShell());
    // run the new project creation operation
    try {
        getContainer().run(true, false, op);
    } catch (InterruptedException e) {
        return false;
    } catch (InvocationTargetException e) {
        // one of the steps resulted in a core exception
        Throwable t = e.getTargetException();
        String message = "Error during import!";
        IStatus status;
        if (t instanceof CoreException) {
            status = ((CoreException) t).getStatus();
        } else {
            status = new Status(IStatus.ERROR, KNIMEUIPlugin.PLUGIN_ID, 1, message, t);
        }
        LOGGER.error(message, t);
        ErrorDialog.openError(getShell(), message, null, status);
        return false;
    } catch (Exception e) {
        String message = "Error during import!";
        IStatus status = new Status(IStatus.ERROR, KNIMEUIPlugin.PLUGIN_ID, 1, message, e);
        ErrorDialog.openError(getShell(), message, null, status);
        LOGGER.error(message, e);
    }
    return true;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IStatus(org.eclipse.core.runtime.IStatus) IPath(org.eclipse.core.runtime.IPath) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) InvocationTargetException(java.lang.reflect.InvocationTargetException) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) CoreException(org.eclipse.core.runtime.CoreException)

Example 12 with WorkspaceModifyOperation

use of org.eclipse.ui.actions.WorkspaceModifyOperation in project tdi-studio-se by Talend.

the class AbstractTalendEditor method doSaveAs.

@Override
public void doSaveAs() {
    SaveAsDialog dialog = new SaveAsDialog(getSite().getWorkbenchWindow().getShell());
    dialog.setOriginalFile(((IFileEditorInput) getEditorInput()).getFile());
    dialog.open();
    IPath path = dialog.getResult();
    if (path == null) {
        return;
    }
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final IFile file = workspace.getRoot().getFile(path);
    WorkspaceModifyOperation op = new WorkspaceModifyOperation() {

        @Override
        public void execute(final IProgressMonitor monitor) throws CoreException {
            try {
                savePreviewPictures();
                getProcess().saveXmlFile();
            // file.refreshLocal(IResource.DEPTH_ONE, monitor);
            } catch (Exception e) {
                // e.printStackTrace();
                ExceptionHandler.process(e);
            }
        }
    };
    try {
        new ProgressMonitorDialog(getSite().getWorkbenchWindow().getShell()).run(false, true, op);
        // setInput(new FileEditorInput((IFile) file));
        getCommandStack().markSaveLocation();
        setDirty(false);
    } catch (Exception e) {
        // e.printStackTrace();
        ExceptionHandler.process(e);
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) SaveAsDialog(org.eclipse.ui.dialogs.SaveAsDialog) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) IWorkspace(org.eclipse.core.resources.IWorkspace) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) CoreException(org.eclipse.core.runtime.CoreException) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 13 with WorkspaceModifyOperation

use of org.eclipse.ui.actions.WorkspaceModifyOperation in project bndtools by bndtools.

the class ImportBndWorkspaceWizard method performFinish.

@Override
public boolean performFinish() {
    final ImportSettings importSettings = new ImportSettings(mainPage.getSelectedFolder(), mainPage.isDeleteSettings(), mainPage.isInferExecutionEnvironment());
    // create the new project operation
    final WorkspaceModifyOperation op = new WorkspaceModifyOperation() {

        @Override
        protected void execute(IProgressMonitor monitor) throws CoreException {
            try {
                importProjects(importSettings, monitor);
            } catch (Exception e) {
                throw new CoreException(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, "Error during import of Bnd workspace!", e));
            }
        }
    };
    Job importJob = new Job("Import Bnd Workspace") {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            try {
                op.run(monitor);
            } catch (InvocationTargetException e) {
                Throwable t = e.getCause();
                if (t instanceof CoreException && ((CoreException) t).getStatus().getException() != null) {
                    // unwrap the cause of the CoreException
                    t = ((CoreException) t).getStatus().getException();
                }
                return new Status(Status.ERROR, Plugin.PLUGIN_ID, "Could not finish import job for Bnd Workspace!", t);
            } catch (InterruptedException e) {
                return Status.CANCEL_STATUS;
            }
            return Status.OK_STATUS;
        }
    };
    importJob.schedule();
    try {
        // Prompt to switch to the BndTools perspective
        IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
        IPerspectiveDescriptor currentPerspective = window.getActivePage().getPerspective();
        if (!"bndtools.perspective".equals(currentPerspective.getId())) {
            if (MessageDialog.openQuestion(getShell(), "Bndtools Perspective", "Switch to the Bndtools perspective?")) {
                this.workbench.showPerspective("bndtools.perspective", window);
            }
        }
    } catch (WorkbenchException e) {
        error("Unable to switch to BndTools perspective", e);
    }
    return true;
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) WorkbenchException(org.eclipse.ui.WorkbenchException) WorkbenchException(org.eclipse.ui.WorkbenchException) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) JavaModelException(org.eclipse.jdt.core.JavaModelException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IPerspectiveDescriptor(org.eclipse.ui.IPerspectiveDescriptor) Job(org.eclipse.core.runtime.jobs.Job)

Example 14 with WorkspaceModifyOperation

use of org.eclipse.ui.actions.WorkspaceModifyOperation in project xtext-xtend by eclipse.

the class UIResourceChangeRegistryTest method testFileContents_changed.

@Test
public void testFileContents_changed() {
    try {
        final IProject project = WorkbenchTestHelper.createPluginProject("foo");
        final IFolder folder = project.getFolder("bar");
        final WorkspaceModifyOperation _function = new WorkspaceModifyOperation() {

            @Override
            protected void execute(final IProgressMonitor it) throws CoreException, InvocationTargetException, InterruptedException {
                folder.create(true, true, null);
                IFile _file = folder.getFile("test.txt");
                StringInputStream _stringInputStream = new StringInputStream("Hello");
                _file.create(_stringInputStream, true, null);
            }
        };
        this.modifyWorkspace(_function);
        final String folderPath = "/foo/bar/test.txt";
        this.resourceChangeRegistry.registerGetContents(folderPath, this.uri);
        final WorkspaceModifyOperation _function_1 = new WorkspaceModifyOperation() {

            @Override
            protected void execute(final IProgressMonitor it) throws CoreException, InvocationTargetException, InterruptedException {
                IFile _file = folder.getFile("test.txt");
                StringInputStream _stringInputStream = new StringInputStream("Hello Xtend");
                _file.setContents(_stringInputStream, true, true, null);
            }
        };
        this.modifyWorkspace(_function_1);
        Assert.assertFalse(this.resourceChangeRegistry.getContentsListeners().containsKey(folderPath));
        Assert.assertEquals(1, this.resourceChangeRegistry.queuedURIs.size());
        this.resourceChangeRegistry.registerGetContents(folderPath, this.uri);
        final WorkspaceModifyOperation _function_2 = new WorkspaceModifyOperation() {

            @Override
            protected void execute(final IProgressMonitor it) throws CoreException, InvocationTargetException, InterruptedException {
                folder.getFile("test.txt").setCharset("UTF-8", null);
            }
        };
        this.modifyWorkspace(_function_2);
        Assert.assertFalse(this.resourceChangeRegistry.getContentsListeners().containsKey(folderPath));
        Assert.assertEquals(2, this.resourceChangeRegistry.queuedURIs.size());
        this.resourceChangeRegistry.registerGetContents(folderPath, this.uri);
        final WorkspaceModifyOperation _function_3 = new WorkspaceModifyOperation() {

            @Override
            protected void execute(final IProgressMonitor it) throws CoreException, InvocationTargetException, InterruptedException {
                folder.getFile("test.txt").delete(true, true, null);
            }
        };
        this.modifyWorkspace(_function_3);
        Assert.assertFalse(this.resourceChangeRegistry.getContentsListeners().containsKey(folderPath));
        Assert.assertEquals(3, this.resourceChangeRegistry.queuedURIs.size());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) StringInputStream(org.eclipse.xtext.util.StringInputStream) IFile(org.eclipse.core.resources.IFile) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Example 15 with WorkspaceModifyOperation

use of org.eclipse.ui.actions.WorkspaceModifyOperation in project xtext-xtend by eclipse.

the class UIResourceChangeRegistryTest method testFolderExists.

@Test
public void testFolderExists() {
    try {
        final String folderPath = "/foo/bar";
        this.resourceChangeRegistry.registerExists(folderPath, this.uri);
        Assert.assertTrue(this.resourceChangeRegistry.getExistsListeners().containsKey(folderPath));
        final IProject project = WorkbenchTestHelper.createPluginProject("foo");
        Assert.assertTrue(this.resourceChangeRegistry.getExistsListeners().containsKey(folderPath));
        final IFolder folder = project.getFolder("bar");
        Assert.assertTrue(this.resourceChangeRegistry.getExistsListeners().containsKey(folderPath));
        final WorkspaceModifyOperation _function = new WorkspaceModifyOperation() {

            @Override
            protected void execute(final IProgressMonitor it) throws CoreException, InvocationTargetException, InterruptedException {
                folder.create(true, true, null);
            }
        };
        this.modifyWorkspace(_function);
        Assert.assertFalse(this.resourceChangeRegistry.getExistsListeners().containsKey(folderPath));
        Assert.assertEquals(1, this.resourceChangeRegistry.queuedURIs.size());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Aggregations

WorkspaceModifyOperation (org.eclipse.ui.actions.WorkspaceModifyOperation)24 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)23 InvocationTargetException (java.lang.reflect.InvocationTargetException)18 CoreException (org.eclipse.core.runtime.CoreException)15 IFile (org.eclipse.core.resources.IFile)7 IFolder (org.eclipse.core.resources.IFolder)7 IProject (org.eclipse.core.resources.IProject)7 Test (org.junit.Test)6 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)5 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)5 IStatus (org.eclipse.core.runtime.IStatus)4 Status (org.eclipse.core.runtime.Status)4 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)4 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 IResource (org.eclipse.core.resources.IResource)2 IWorkspace (org.eclipse.core.resources.IWorkspace)2 IPath (org.eclipse.core.runtime.IPath)2 URI (org.eclipse.emf.common.util.URI)2