Search in sources :

Example 1 with IResourceChangeListener

use of org.eclipse.core.resources.IResourceChangeListener in project che by eclipse.

the class RefactoringTest method performRefactoring.

protected final RefactoringStatus performRefactoring(Refactoring ref, boolean providesUndo) throws Exception {
    performDummySearch();
    IUndoManager undoManager = getUndoManager();
    if (DESCRIPTOR_TEST) {
        final CreateChangeOperation create = new CreateChangeOperation(new CheckConditionsOperation(ref, CheckConditionsOperation.ALL_CONDITIONS), RefactoringStatus.FATAL);
        create.run(new NullProgressMonitor());
        RefactoringStatus checkingStatus = create.getConditionCheckingStatus();
        if (!checkingStatus.isOK())
            return checkingStatus;
        Change change = create.getChange();
        ChangeDescriptor descriptor = change.getDescriptor();
        if (descriptor instanceof RefactoringChangeDescriptor) {
            RefactoringChangeDescriptor rcd = (RefactoringChangeDescriptor) descriptor;
            RefactoringDescriptor refactoringDescriptor = rcd.getRefactoringDescriptor();
            if (refactoringDescriptor instanceof JavaRefactoringDescriptor) {
                JavaRefactoringDescriptor jrd = (JavaRefactoringDescriptor) refactoringDescriptor;
                RefactoringStatus validation = jrd.validateDescriptor();
                if (!validation.isOK())
                    return validation;
                RefactoringStatus refactoringStatus = new RefactoringStatus();
                Class expected = jrd.getClass();
                RefactoringContribution contribution = RefactoringCore.getRefactoringContribution(jrd.getID());
                jrd = (JavaRefactoringDescriptor) contribution.createDescriptor(jrd.getID(), jrd.getProject(), jrd.getDescription(), jrd.getComment(), contribution.retrieveArgumentMap(jrd), jrd.getFlags());
                assertEquals(expected, jrd.getClass());
                ref = jrd.createRefactoring(refactoringStatus);
                if (!refactoringStatus.isOK())
                    return refactoringStatus;
                TestRenameParticipantSingle.reset();
                TestCreateParticipantSingle.reset();
                TestMoveParticipantSingle.reset();
                TestDeleteParticipantSingle.reset();
            }
        }
    }
    final CreateChangeOperation create = new CreateChangeOperation(new CheckConditionsOperation(ref, CheckConditionsOperation.ALL_CONDITIONS), RefactoringStatus.FATAL);
    final PerformChangeOperation perform = new PerformChangeOperation(create);
    perform.setUndoManager(undoManager, ref.getName());
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    if (fIsPreDeltaTest) {
        IResourceChangeListener listener = new IResourceChangeListener() {

            public void resourceChanged(IResourceChangeEvent event) {
                if (create.getConditionCheckingStatus().isOK() && perform.changeExecuted()) {
                    TestModelProvider.assertTrue(event.getDelta());
                }
            }
        };
        try {
            TestModelProvider.clearDelta();
            workspace.checkpoint(false);
            workspace.addResourceChangeListener(listener);
            executePerformOperation(perform, workspace);
        } finally {
            workspace.removeResourceChangeListener(listener);
        }
    } else {
        executePerformOperation(perform, workspace);
    }
    RefactoringStatus status = create.getConditionCheckingStatus();
    if (!status.isOK())
        return status;
    assertTrue("Change wasn't executed", perform.changeExecuted());
    Change undo = perform.getUndoChange();
    if (providesUndo) {
        assertNotNull("Undo doesn't exist", undo);
        assertTrue("Undo manager is empty", undoManager.anythingToUndo());
    } else {
        assertNull("Undo manager contains undo but shouldn't", undo);
    }
    return null;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IUndoManager(org.eclipse.ltk.core.refactoring.IUndoManager) RefactoringContribution(org.eclipse.ltk.core.refactoring.RefactoringContribution) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) Change(org.eclipse.ltk.core.refactoring.Change) IResourceChangeListener(org.eclipse.core.resources.IResourceChangeListener) ChangeDescriptor(org.eclipse.ltk.core.refactoring.ChangeDescriptor) RefactoringChangeDescriptor(org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor) RefactoringChangeDescriptor(org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor) JavaRefactoringDescriptor(org.eclipse.jdt.core.refactoring.descriptors.JavaRefactoringDescriptor) RefactoringDescriptor(org.eclipse.ltk.core.refactoring.RefactoringDescriptor) CreateChangeOperation(org.eclipse.ltk.core.refactoring.CreateChangeOperation) PerformChangeOperation(org.eclipse.ltk.core.refactoring.PerformChangeOperation) IResourceChangeEvent(org.eclipse.core.resources.IResourceChangeEvent) IWorkspace(org.eclipse.core.resources.IWorkspace) CheckConditionsOperation(org.eclipse.ltk.core.refactoring.CheckConditionsOperation) JavaRefactoringDescriptor(org.eclipse.jdt.core.refactoring.descriptors.JavaRefactoringDescriptor)

Example 2 with IResourceChangeListener

use of org.eclipse.core.resources.IResourceChangeListener in project tesb-studio-se by Talend.

the class ResourceEditorListener method partClosed.

@Override
public void partClosed(IWorkbenchPartReference partRef) {
    IWorkbenchPart part = partRef.getPart(true);
    if (part instanceof IEditorPart) {
        IEditorInput input = ((IEditorPart) part).getEditorInput();
        if (input instanceof RouteResourceInput) {
            Item item = ((RouteResourceInput) input).getItem();
            if (item.getProperty().getId().equals(editorInput.getItem().getProperty().getId())) {
                try {
                    ProxyRepositoryFactory.getInstance().unlock(item);
                    page.getWorkbenchWindow().getPartService().removePartListener(this);
                    IResourceChangeListener l = editorInput.getListener();
                    if (null != l) {
                        ResourcesPlugin.getWorkspace().removeResourceChangeListener(l);
                    }
                } catch (Exception e) {
                    ExceptionHandler.process(e);
                }
            }
        }
    }
}
Also used : RouteResourceInput(org.talend.designer.camel.resource.editors.input.RouteResourceInput) Item(org.talend.core.model.properties.Item) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IEditorPart(org.eclipse.ui.IEditorPart) IResourceChangeListener(org.eclipse.core.resources.IResourceChangeListener) IEditorInput(org.eclipse.ui.IEditorInput)

Example 3 with IResourceChangeListener

use of org.eclipse.core.resources.IResourceChangeListener in project translationstudio8 by heartsome.

the class ApplicationWorkbenchWindowAdvisor method addWorkplaceListener.

public void addWorkplaceListener() {
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    workspace.addResourceChangeListener(new IResourceChangeListener() {

        public void resourceChanged(IResourceChangeEvent event) {
            //刷新项目导航视图
            Display.getDefault().syncExec(new Runnable() {

                public void run() {
                    IViewPart findView = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("net.heartsome.cat.common.ui.navigator.view");
                    if (null == findView) {
                        return;
                    }
                    IAction refreshActionHandler = findView.getViewSite().getActionBars().getGlobalActionHandler(ActionFactory.REFRESH.getId());
                    if (null == refreshActionHandler) {
                        return;
                    }
                    refreshActionHandler.run();
                }
            });
        }
    });
}
Also used : IResourceChangeEvent(org.eclipse.core.resources.IResourceChangeEvent) IViewPart(org.eclipse.ui.IViewPart) IAction(org.eclipse.jface.action.IAction) IWorkspace(org.eclipse.core.resources.IWorkspace) IResourceChangeListener(org.eclipse.core.resources.IResourceChangeListener)

Example 4 with IResourceChangeListener

use of org.eclipse.core.resources.IResourceChangeListener in project xtext-eclipse by eclipse.

the class Bug486584Test method tearDown.

@Override
@After
public void tearDown() throws Exception {
    super.tearDown();
    for (IResourceChangeListener l : resourceChangeListeners) {
        ResourcesPlugin.getWorkspace().removeResourceChangeListener(l);
    }
    resourceChangeListeners.clear();
}
Also used : IResourceChangeListener(org.eclipse.core.resources.IResourceChangeListener) After(org.junit.After)

Example 5 with IResourceChangeListener

use of org.eclipse.core.resources.IResourceChangeListener in project erlide_eclipse by erlang.

the class ErlModel method setupWorkspaceListeners.

public final void setupWorkspaceListeners() {
    final IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final IPathVariableManager pvm = workspace.getPathVariableManager();
    pvm.addChangeListener(fPathVariableChangeListener);
    final IResourceChangeListener listener = new ResourceChangeListener();
    workspace.addResourceChangeListener(listener);
}
Also used : IPathVariableManager(org.eclipse.core.resources.IPathVariableManager) IWorkspace(org.eclipse.core.resources.IWorkspace) IResourceChangeListener(org.eclipse.core.resources.IResourceChangeListener) IResourceChangeListener(org.eclipse.core.resources.IResourceChangeListener)

Aggregations

IResourceChangeListener (org.eclipse.core.resources.IResourceChangeListener)19 IResourceChangeEvent (org.eclipse.core.resources.IResourceChangeEvent)14 IResource (org.eclipse.core.resources.IResource)9 IProject (org.eclipse.core.resources.IProject)8 IResourceDelta (org.eclipse.core.resources.IResourceDelta)6 IWorkspace (org.eclipse.core.resources.IWorkspace)6 IPath (org.eclipse.core.runtime.IPath)6 CoreException (org.eclipse.core.runtime.CoreException)5 IResourceDeltaVisitor (org.eclipse.core.resources.IResourceDeltaVisitor)3 File (java.io.File)2 IOException (java.io.IOException)2 IFile (org.eclipse.core.resources.IFile)2 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)2 IDocumentWrapper (bndtools.editor.model.IDocumentWrapper)1 ProjectModel (ch.acanda.eclipse.pmd.domain.ProjectModel)1 WorkspaceModel (ch.acanda.eclipse.pmd.domain.WorkspaceModel)1 ProjectModelRepository (ch.acanda.eclipse.pmd.repository.ProjectModelRepository)1 ILiferayLegacyProjectUpdater (com.liferay.ide.project.core.upgrade.ILiferayLegacyProjectUpdater)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1