Search in sources :

Example 16 with WorkspaceModifyOperation

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

the class AbstractNewXtendElementWizardPage method createType.

protected int createType() {
    final int[] size = { 0 };
    IRunnableWithProgress op = new WorkspaceModifyOperation() {

        @Override
        protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
            if (monitor == null) {
                monitor = new NullProgressMonitor();
            }
            try {
                if (!getPackageFragment().exists()) {
                    try {
                        getPackageFragmentRoot().createPackageFragment(getPackageFragment().getElementName(), true, monitor);
                    } catch (JavaModelException e) {
                        displayError(Messages.ERROR_CREATING_PACKAGE, e.getMessage());
                    }
                }
                IResource res = getPackageFragment().getResource();
                // $NON-NLS-1$
                IFile xtendFile = ((IFolder) res).getFile(getTypeNameWithoutParameters() + ".xtend");
                URI uri = storage2UriMapper.getUri(xtendFile);
                size[0] = createXtendElement(monitor, xtendFile, whitespaceInformationProvider.getIndentationInformation(uri).getIndentString(), whitespaceInformationProvider.getLineSeparatorInformation(uri).getLineSeparator());
            } catch (OperationCanceledException e) {
                throw new InterruptedException();
            } catch (Exception e) {
                throw new InvocationTargetException(e);
            } finally {
                monitor.done();
            }
        }
    };
    try {
        getContainer().run(true, false, op);
    } catch (InterruptedException e) {
        // cancelled by user
        return 0;
    } catch (InvocationTargetException e) {
        Throwable realException = e.getTargetException();
        MessageDialog.openError(getShell(), getElementCreationErrorMessage(), realException.getMessage());
    }
    return size[0];
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) JavaModelException(org.eclipse.jdt.core.JavaModelException) IFile(org.eclipse.core.resources.IFile) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) URI(org.eclipse.emf.common.util.URI) JavaModelException(org.eclipse.jdt.core.JavaModelException) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 17 with WorkspaceModifyOperation

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

the class WorkbenchTestHelper method tearDown.

public void tearDown() throws Exception {
    if (workbench.getActiveWorkbenchWindow() != null)
        workbench.getActiveWorkbenchWindow().getActivePage().closeAllEditors(false);
    new WorkspaceModifyOperation() {

        @Override
        protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
            for (IFile file : getFiles()) {
                try {
                    file.delete(true, null);
                } catch (Exception exc) {
                    throw new RuntimeException(exc);
                }
            }
            getFiles().clear();
            IFolder binFolder = getProject(false).getFolder("bin");
            if (binFolder.exists()) {
                for (IResource binMember : binFolder.members()) {
                    try {
                        binMember.delete(true, null);
                    } catch (Exception exc) {
                        throw new RuntimeException(exc);
                    }
                }
            }
            if (isLazyCreatedProject) {
                deleteProject(getProject(false));
                isLazyCreatedProject = false;
            }
        }
    }.run(null);
    IResourcesSetupUtil.waitForBuild();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) InvocationTargetException(java.lang.reflect.InvocationTargetException) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 18 with WorkspaceModifyOperation

use of org.eclipse.ui.actions.WorkspaceModifyOperation in project Palladio-Editors-Sirius by PalladioSimulator.

the class NewPalladioProjectWizard method performFinish.

@Override
public boolean performFinish() {
    final IProject projectHandle = this.projectCreationPage.getProjectHandle();
    final java.net.URI projectURI = (!this.projectCreationPage.useDefaults()) ? this.projectCreationPage.getLocationURI() : null;
    final IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final IProjectDescription desc = workspace.newProjectDescription(projectHandle.getName());
    desc.setLocationURI(projectURI);
    /*
         * Creating the project encapsulated in a workspace operation
         */
    final WorkspaceModifyOperation op = new WorkspaceModifyOperation() {

        @Override
        protected void execute(final IProgressMonitor monitor) throws CoreException {
            NewPalladioProjectWizard.this.project = createProject(desc, projectHandle, monitor);
        }
    };
    /*
         * This isn't as robust as the code in the BasicNewProjectResourceWizard class. Consider
         * beefing this up to improve error handling.
         */
    try {
        getContainer().run(true, true, op);
    } catch (final Exception e) {
        MessageDialog.openError(getShell(), "Error", "An unexpected error occured. See stack trace");
        e.printStackTrace();
        return false;
    }
    if (this.project == null) {
        return false;
    }
    BasicNewProjectResourceWizard.updatePerspective(this.config);
    BasicNewProjectResourceWizard.selectAndReveal(this.project, this.workbench.getActiveWorkbenchWindow());
    if (!getCurrentPerspectiveId().equals(PERSPECTIVE_ID)) {
        boolean confirm = MessageDialog.openConfirm(getShell(), "Palladio Perspective", "This project is associated with the Palladio perspective.\n\nDo you want to open this perspective now?");
        if (confirm)
            openPalladioPerspective();
    }
    return true;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IProject(org.eclipse.core.resources.IProject) WorkbenchException(org.eclipse.ui.WorkbenchException) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 19 with WorkspaceModifyOperation

use of org.eclipse.ui.actions.WorkspaceModifyOperation in project eclipse.platform.text by eclipse.

the class AbstractDecoratedTextEditor method revealInEditor.

/**
 * Selects and reveals the given offset and length in the given editor part.
 *
 * @param editor the editor part
 * @param offset the offset
 * @param length the length
 * @since 3.7
 */
private static void revealInEditor(IEditorPart editor, final int offset, final int length) {
    if (editor instanceof ITextEditor) {
        ((ITextEditor) editor).selectAndReveal(offset, length);
        return;
    }
    // Support for non-text editor - try IGotoMarker interface
    final IGotoMarker gotoMarkerTarget;
    if (editor instanceof IGotoMarker)
        gotoMarkerTarget = (IGotoMarker) editor;
    else
        gotoMarkerTarget = editor != null ? editor.getAdapter(IGotoMarker.class) : null;
    if (gotoMarkerTarget != null) {
        final IEditorInput input = editor.getEditorInput();
        if (input instanceof IFileEditorInput) {
            WorkspaceModifyOperation op = new WorkspaceModifyOperation() {

                @Override
                protected void execute(IProgressMonitor monitor) throws CoreException {
                    IMarker marker = null;
                    try {
                        marker = ((IFileEditorInput) input).getFile().createMarker(IMarker.TEXT);
                        marker.setAttribute(IMarker.CHAR_START, offset);
                        marker.setAttribute(IMarker.CHAR_END, offset + length);
                        gotoMarkerTarget.gotoMarker(marker);
                    } finally {
                        if (marker != null)
                            marker.delete();
                    }
                }
            };
            try {
                op.run(null);
            } catch (InvocationTargetException ex) {
            // reveal failed
            } catch (InterruptedException e) {
                // $NON-NLS-1$
                Assert.isTrue(false, "this operation can not be canceled");
            }
        }
        return;
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFileEditorInput(org.eclipse.ui.IFileEditorInput) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) IGotoMarker(org.eclipse.ui.ide.IGotoMarker) IMarker(org.eclipse.core.resources.IMarker) IEditorInput(org.eclipse.ui.IEditorInput) IURIEditorInput(org.eclipse.ui.IURIEditorInput) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 20 with WorkspaceModifyOperation

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

the class JavaRefactoringIntegrationTest method renameXtendElement.

protected void renameXtendElement(final XtextEditor editor, final int offset, final String newName, final int allowedSeverity) throws Exception {
    syncUtil.totalSync(false);
    new WorkspaceModifyOperation() {

        @Override
        protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
            ProcessorBasedRefactoring renameRefactoring = createXtendRenameRefactoring(editor, offset, newName);
            assertTrue("Refactoring not applicable", renameRefactoring.isApplicable());
            RefactoringStatus status = renameRefactoring.checkAllConditions(new NullProgressMonitor());
            assertTrue(status.toString(), status.getSeverity() <= allowedSeverity);
            Change change = renameRefactoring.createChange(new NullProgressMonitor());
            change.perform(new NullProgressMonitor());
        }
    }.run(new NullProgressMonitor());
    syncUtil.totalSync(false);
    assertTrue(compositeRefactoringProcessorAccess.isDisposed());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) Change(org.eclipse.ltk.core.refactoring.Change) ProcessorBasedRefactoring(org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring) InvocationTargetException(java.lang.reflect.InvocationTargetException)

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