Search in sources :

Example 21 with WorkspaceModifyOperation

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

the class RefactoringIntegrationTest method doRename.

protected void doRename(EObject targetElement, String newName) throws Exception {
    URI targetElementURI = EcoreUtil.getURI(targetElement);
    RenameElementProcessor processor = processorProvider.get();
    processor.initialize(new IRenameElementContext.Impl(targetElementURI, targetElement.eClass(), null, null, null));
    processor.setNewName(newName);
    RefactoringStatus initialStatus = processor.checkInitialConditions(new NullProgressMonitor());
    assertTrue(initialStatus.isOK());
    RefactoringStatus finalStatus = processor.checkFinalConditions(new NullProgressMonitor(), null);
    assertTrue(finalStatus.toString(), finalStatus.isOK());
    final Change change = processor.createChange(new NullProgressMonitor());
    assertNotNull(change);
    new WorkspaceModifyOperation() {

        @Override
        protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
            change.perform(monitor);
        }
    }.run(null);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) Change(org.eclipse.ltk.core.refactoring.Change) URI(org.eclipse.emf.common.util.URI) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IRenameElementContext(org.eclipse.xtext.ui.refactoring.ui.IRenameElementContext) RenameElementProcessor(org.eclipse.xtext.ui.refactoring.impl.RenameElementProcessor)

Example 22 with WorkspaceModifyOperation

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

the class RenameStrategyTest method testOverrideIndicatorAnnotationAfterFileRename.

@Test
public void testOverrideIndicatorAnnotationAfterFileRename() throws Exception {
    testHelper.createFile("test/SuperClass", "package test\nclass SuperClass { def foo() {}}");
    final IFile subClassFile = testHelper.createFile("test/SubClass", "package test\nclass SubClass extends SuperClass { override foo () {}}");
    IResourcesSetupUtil.waitForBuild();
    XtextEditor openEditor = testHelper.openEditor(subClassFile);
    final OverrideIndicatorAnnotation[] annotationBeforeFileRename = new OverrideIndicatorAnnotation[] { null };
    final OverrideIndicatorAnnotation[] annotationAfterFileRename = new OverrideIndicatorAnnotation[] { null };
    final ISourceViewer sourceViewer = openEditor.getInternalSourceViewer();
    sleepWhile(Predicates.isNull(), new Provider<Object>() {

        @Override
        public OverrideIndicatorAnnotation get() {
            annotationBeforeFileRename[0] = Iterators.getOnlyElement(Iterators.filter(sourceViewer.getAnnotationModel().getAnnotationIterator(), OverrideIndicatorAnnotation.class), null);
            return annotationBeforeFileRename[0];
        }
    }, TimeUnit.SECONDS.toMillis(10));
    assertNotNull(annotationBeforeFileRename[0]);
    new WorkspaceModifyOperation() {

        @Override
        protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
            subClassFile.move(subClassFile.getFullPath().removeLastSegments(1).append("Test.xtend"), true, monitor);
        }
    }.run(new NullProgressMonitor());
    IResourcesSetupUtil.waitForBuild();
    sleepWhile(Predicates.isNull(), new Provider<Object>() {

        @Override
        public OverrideIndicatorAnnotation get() {
            OverrideIndicatorAnnotation ann = Iterators.getOnlyElement(Iterators.filter(sourceViewer.getAnnotationModel().getAnnotationIterator(), OverrideIndicatorAnnotation.class), null);
            if (ann != annotationBeforeFileRename[0])
                annotationAfterFileRename[0] = ann;
            return annotationAfterFileRename[0];
        }
    }, TimeUnit.SECONDS.toMillis(10));
    assertNotNull(annotationAfterFileRename[0]);
    assertNotSame(annotationBeforeFileRename[0], annotationAfterFileRename[0]);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) OverrideIndicatorAnnotation(org.eclipse.xtend.ide.editor.OverrideIndicatorAnnotation) IFile(org.eclipse.core.resources.IFile) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) EObject(org.eclipse.emf.ecore.EObject) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) Test(org.junit.Test)

Example 23 with WorkspaceModifyOperation

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

the class SearchManager method removeAllSearches.

void removeAllSearches() {
    SearchPlugin.getWorkspace().removeResourceChangeListener(this);
    WorkspaceModifyOperation op = new WorkspaceModifyOperation(null) {

        @Override
        protected void execute(IProgressMonitor monitor) throws CoreException {
            monitor.beginTask(SearchMessages.SearchManager_updating, 100);
            SearchPlugin.getWorkspace().getRoot().deleteMarkers(SearchUI.SEARCH_MARKER, true, IResource.DEPTH_INFINITE);
            monitor.worked(100);
            monitor.done();
        }
    };
    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_deleteMarkers_title, SearchMessages.Search_Error_deleteMarkers_message);
    } catch (InterruptedException e) {
    // Do nothing. Operation has been canceled.
    } finally {
        SearchPlugin.getWorkspace().addResourceChangeListener(this);
        SearchPlugin.setAutoBuilding(isAutoBuilding);
    }
    // clear searches
    fPreviousSearches = new LinkedList<>();
    fCurrentSearch = null;
    // update viewers
    Iterator<SearchResultViewer> iter = fListeners.iterator();
    while (iter.hasNext()) {
        SearchResultViewer viewer = iter.next();
        handleAllSearchesRemoved(viewer);
    }
}
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 24 with WorkspaceModifyOperation

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

the class RPMNewProject method performFinish.

@Override
public boolean performFinish() {
    try {
        WorkspaceModifyOperation op = new WorkspaceModifyOperation() {

            @Override
            protected void execute(IProgressMonitor monitor) throws CoreException {
                createProject(monitor != null ? monitor : new NullProgressMonitor());
            }
        };
        getContainer().run(false, true, op);
    } catch (InvocationTargetException x) {
        return false;
    } catch (InterruptedException x) {
        return false;
    }
    return true;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) 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