Search in sources :

Example 6 with WorkspaceModifyOperation

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

the class SearchManager method setCurrentSearch.

void setCurrentSearch(final Search search) {
    if (fCurrentSearch == search)
        return;
    SearchPlugin.getWorkspace().removeResourceChangeListener(this);
    WorkspaceModifyOperation op = new WorkspaceModifyOperation(null) {

        @Override
        protected void execute(IProgressMonitor monitor) throws CoreException {
            internalSetCurrentSearch(search, monitor);
        }
    };
    boolean isAutoBuilding = SearchPlugin.setAutoBuilding(false);
    try {
        ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
        dialog.run(true, true, op);
    } catch (InvocationTargetException ex) {
        ExceptionHandler.handle(ex, SearchMessages.Search_Error_switchSearch_title, SearchMessages.Search_Error_switchSearch_message);
    } catch (InterruptedException e) {
    // Do nothing. Operation has been canceled.
    } finally {
        SearchPlugin.setAutoBuilding(isAutoBuilding);
    }
    getPreviousSearches().remove(search);
    getPreviousSearches().addFirst(search);
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 7 with WorkspaceModifyOperation

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

the class NewModelWizard method performFinish.

@Override
public boolean performFinish() {
    this.modelURI = this.modelCreationPage.getPlatformURI();
    final boolean createRepresentation = this.representationCreationPage.isRepresentationCreationEnabled();
    final String representationName = this.representationCreationPage.getRepresentationName();
    final IRunnableWithProgress op = new WorkspaceModifyOperation() {

        @Override
        protected void execute(final IProgressMonitor monitor) throws CoreException {
            final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(URI.decode(NewModelWizard.this.modelURI.segment(1)));
            createModel(project, createRepresentation, representationName, monitor);
            finish();
        }
    };
    try {
        this.getContainer().run(true, true, op);
    } catch (InvocationTargetException | InterruptedException e) {
        e.printStackTrace();
        return false;
    }
    return true;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 8 with WorkspaceModifyOperation

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

the class UIResourceChangeRegistryTest method testFolderChildren_AddedChild.

@Test
public void testFolderChildren_AddedChild() {
    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);
            }
        };
        this.modifyWorkspace(_function);
        final String folderPath = "/foo/bar";
        this.resourceChangeRegistry.registerGetChildren(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 World");
                _file.create(_stringInputStream, true, null);
            }
        };
        this.modifyWorkspace(_function_1);
        Assert.assertFalse(this.resourceChangeRegistry.getChildrenListeners().containsKey(folderPath));
        Assert.assertEquals(1, this.resourceChangeRegistry.queuedURIs.size());
        this.resourceChangeRegistry.registerGetChildren(folderPath, this.uri);
        final WorkspaceModifyOperation _function_2 = 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_2);
        Assert.assertTrue(this.resourceChangeRegistry.getChildrenListeners().containsKey(folderPath));
        Assert.assertEquals(1, this.resourceChangeRegistry.queuedURIs.size());
        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.getChildrenListeners().containsKey(folderPath));
        Assert.assertEquals(2, 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 9 with WorkspaceModifyOperation

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

the class UIResourceChangeRegistryTest method testFolderChildren.

@Test
public void testFolderChildren() {
    try {
        final IProject project = WorkbenchTestHelper.createPluginProject("foo");
        final String folderPath = "/foo/bar";
        this.resourceChangeRegistry.registerGetChildren(folderPath, this.uri);
        Assert.assertTrue(this.resourceChangeRegistry.getChildrenListeners().containsKey(folderPath));
        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);
            }
        };
        this.modifyWorkspace(_function);
        Assert.assertFalse(this.resourceChangeRegistry.getChildrenListeners().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)

Example 10 with WorkspaceModifyOperation

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

the class ChangeLogAction method createChangeLog.

protected IFile createChangeLog(IPath changelog) {
    IWorkspaceRoot myWorkspaceRoot = getWorkspaceRoot();
    IWorkbench ws = PlatformUI.getWorkbench();
    final IFile changelog_File = myWorkspaceRoot.getFile(changelog);
    final InputStream initialContents = new ByteArrayInputStream(new byte[0]);
    WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {

        @Override
        public void execute(IProgressMonitor monitor) throws CoreException {
            try {
                // $NON-NLS-1$
                monitor.beginTask(Messages.getString("ChangeLog.AddingChangeLog"), 2000);
                changelog_File.create(initialContents, false, monitor);
                if (monitor.isCanceled()) {
                    throw new OperationCanceledException();
                }
            } finally {
                monitor.done();
            }
        }
    };
    try {
        new ProgressMonitorDialog(ws.getActiveWorkbenchWindow().getShell()).run(true, true, operation);
    } catch (InterruptedException e) {
        // $NON-NLS-1$
        reportErr(Messages.getString("ChangeLog.ErrInterrupted"), e);
        return null;
    } catch (InvocationTargetException e) {
        // $NON-NLS-1$
        reportErr(Messages.getString("ChangeLog.ErrInvocation"), e);
        return null;
    }
    // FIXME:  we should put this refreshLocal call into a thread (filed as bug #256180)
    try {
        IContainer changelogContainer = myWorkspaceRoot.getContainerForLocation(changelog);
        if (changelogContainer != null)
            changelogContainer.refreshLocal(2, null);
    } catch (CoreException e) {
        // $NON-NLS-1$
        reportErr(Messages.getString("ChangeLog.ErrRefresh"), e);
        return null;
    }
    return changelog_File;
}
Also used : IFile(org.eclipse.core.resources.IFile) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) IWorkbench(org.eclipse.ui.IWorkbench) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) IContainer(org.eclipse.core.resources.IContainer)

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