Search in sources :

Example 1 with IResourceChangeEvent

use of org.eclipse.core.resources.IResourceChangeEvent 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 IResourceChangeEvent

use of org.eclipse.core.resources.IResourceChangeEvent in project flux by eclipse.

the class Activator method initCoreService.

private void initCoreService(String userChannel) throws CoreException {
    repository = new Repository(messageConnector, userChannel);
    liveEditCoordinator = new LiveEditCoordinator(messageConnector);
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    resourceListener = new CloudSyncResourceListener(repository);
    workspace.addResourceChangeListener(resourceListener, IResourceChangeEvent.POST_CHANGE);
    metadataListener = new CloudSyncMetadataListener(repository);
    workspace.addResourceChangeListener(metadataListener, IResourceChangeEvent.POST_BUILD);
    this.repositoryListener = new IRepositoryListener() {

        @Override
        public void projectDisconnected(IProject project) {
            removeConnectedProjectPreference(project.getName());
        }

        @Override
        public void projectConnected(IProject project) {
            addConnectedProjectPreference(project.getName());
        }

        @Override
        public void resourceChanged(IResource resource) {
        // nothing
        }
    };
    getRepository().addRepositoryListener(repositoryListener);
    workspaceListener = new IResourceChangeListener() {

        public void resourceChanged(IResourceChangeEvent event) {
            if (event.getResource() instanceof IProject) {
                IResourceDelta delta = event.getDelta();
                if (delta == null) {
                    return;
                }
                if (delta.getKind() == IResourceDelta.REMOVED) {
                    IProject project = (IProject) event.getResource();
                    removeConnectedProjectPreference(project.getName());
                } else if (delta.getKind() == IResourceDelta.CHANGED) {
                // TODO, we aren't handling project renaming yet
                // IProject project = (IProject) event.getResource();
                // String oldName =
                // delta.getMovedFromPath().lastSegment();
                // removeConnectedProjectPreference(oldName);
                // addConnectedProjectPreference(project.getName());
                }
            }
        }
    };
    workspace.addResourceChangeListener(workspaceListener);
    updateProjectConnections();
}
Also used : IResourceChangeEvent(org.eclipse.core.resources.IResourceChangeEvent) IWorkspace(org.eclipse.core.resources.IWorkspace) CloudSyncMetadataListener(org.eclipse.flux.core.internal.CloudSyncMetadataListener) IResourceChangeListener(org.eclipse.core.resources.IResourceChangeListener) CloudSyncResourceListener(org.eclipse.flux.core.internal.CloudSyncResourceListener) IProject(org.eclipse.core.resources.IProject) IResource(org.eclipse.core.resources.IResource) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Example 3 with IResourceChangeEvent

use of org.eclipse.core.resources.IResourceChangeEvent 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 IResourceChangeEvent

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

the class RefactoringHistoryService method connect.

/**
	 * {@inheritDoc}
	 */
public void connect() {
    fReferenceCount++;
    if (fReferenceCount == 1) {
        fOperationListener = new IOperationHistoryListener() {

            public void historyNotification(final OperationHistoryEvent event) {
                performHistoryNotification(event);
            }
        };
        OperationHistoryFactory.getOperationHistory().addOperationHistoryListener(fOperationListener);
        fResourceListener = new IResourceChangeListener() {

            public void resourceChanged(final IResourceChangeEvent event) {
                peformResourceChanged(event);
            }
        };
        ResourcesPlugin.getWorkspace().addResourceChangeListener(fResourceListener, IResourceChangeEvent.PRE_CLOSE | IResourceChangeEvent.POST_CHANGE);
    }
}
Also used : IOperationHistoryListener(org.eclipse.core.commands.operations.IOperationHistoryListener) IResourceChangeEvent(org.eclipse.core.resources.IResourceChangeEvent) OperationHistoryEvent(org.eclipse.core.commands.operations.OperationHistoryEvent) IResourceChangeListener(org.eclipse.core.resources.IResourceChangeListener)

Example 5 with IResourceChangeEvent

use of org.eclipse.core.resources.IResourceChangeEvent in project bndtools by bndtools.

the class OSGiRunLaunchDelegate method registerLaunchPropertiesRegenerator.

/**
     * Registers a resource listener with the project model file to update the launcher when the model or any of the
     * run-bundles changes. The resource listener is automatically unregistered when the launched process terminates.
     *
     * @param project
     * @param launch
     * @throws CoreException
     */
private void registerLaunchPropertiesRegenerator(final Project project, final ILaunch launch) throws CoreException {
    final IResource targetResource = LaunchUtils.getTargetResource(launch.getLaunchConfiguration());
    if (targetResource == null)
        return;
    final IPath bndbndPath;
    try {
        bndbndPath = Central.toPath(project.getPropertiesFile());
    } catch (Exception e) {
        throw new CoreException(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error querying bnd.bnd file location", e));
    }
    try {
        Central.toPath(project.getTarget());
    } catch (Exception e) {
        throw new CoreException(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error querying project output folder", e));
    }
    final IResourceChangeListener resourceListener = new IResourceChangeListener() {

        @Override
        public void resourceChanged(IResourceChangeEvent event) {
            try {
                final AtomicBoolean update = new AtomicBoolean(false);
                // Was the properties file (bnd.bnd or *.bndrun) included in
                // the delta?
                IResourceDelta propsDelta = event.getDelta().findMember(bndbndPath);
                if (propsDelta == null && targetResource.getType() == IResource.FILE)
                    propsDelta = event.getDelta().findMember(targetResource.getFullPath());
                if (propsDelta != null) {
                    if (propsDelta.getKind() == IResourceDelta.CHANGED) {
                        update.set(true);
                    }
                }
                // list
                if (!update.get()) {
                    final Set<String> runBundleSet = new HashSet<String>();
                    for (String bundlePath : bndLauncher.getRunBundles()) {
                        runBundleSet.add(new org.eclipse.core.runtime.Path(bundlePath).toPortableString());
                    }
                    event.getDelta().accept(new IResourceDeltaVisitor() {

                        @Override
                        public boolean visit(IResourceDelta delta) throws CoreException {
                            // match
                            if (update.get())
                                return false;
                            IResource resource = delta.getResource();
                            if (resource.getType() == IResource.FILE) {
                                IPath location = resource.getLocation();
                                boolean isRunBundle = location != null ? runBundleSet.contains(location.toPortableString()) : false;
                                update.compareAndSet(false, isRunBundle);
                                return false;
                            }
                            // Recurse into containers
                            return true;
                        }
                    });
                }
                if (update.get()) {
                    project.forceRefresh();
                    project.setChanged();
                    bndLauncher.update();
                }
            } catch (Exception e) {
                logger.logError("Error updating launch properties file.", e);
            }
        }
    };
    ResourcesPlugin.getWorkspace().addResourceChangeListener(resourceListener);
    // Register a listener for termination of the launched process
    Runnable onTerminate = new Runnable() {

        @Override
        public void run() {
            ResourcesPlugin.getWorkspace().removeResourceChangeListener(resourceListener);
            display.asyncExec(new Runnable() {

                @Override
                public void run() {
                    if (dialog != null && dialog.getShell() != null) {
                        dialog.getShell().dispose();
                    }
                }
            });
        }
    };
    DebugPlugin.getDefault().addDebugEventListener(new TerminationListener(launch, onTerminate));
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IPath(org.eclipse.core.runtime.IPath) IPath(org.eclipse.core.runtime.IPath) IResourceChangeListener(org.eclipse.core.resources.IResourceChangeListener) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IResourceChangeEvent(org.eclipse.core.resources.IResourceChangeEvent) CoreException(org.eclipse.core.runtime.CoreException) IResourceDeltaVisitor(org.eclipse.core.resources.IResourceDeltaVisitor) IResource(org.eclipse.core.resources.IResource) IResourceDelta(org.eclipse.core.resources.IResourceDelta) HashSet(java.util.HashSet)

Aggregations

IResourceChangeEvent (org.eclipse.core.resources.IResourceChangeEvent)5 IResourceChangeListener (org.eclipse.core.resources.IResourceChangeListener)5 IWorkspace (org.eclipse.core.resources.IWorkspace)3 IResource (org.eclipse.core.resources.IResource)2 IResourceDelta (org.eclipse.core.resources.IResourceDelta)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 IOperationHistoryListener (org.eclipse.core.commands.operations.IOperationHistoryListener)1 OperationHistoryEvent (org.eclipse.core.commands.operations.OperationHistoryEvent)1 IProject (org.eclipse.core.resources.IProject)1 IResourceDeltaVisitor (org.eclipse.core.resources.IResourceDeltaVisitor)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 IStatus (org.eclipse.core.runtime.IStatus)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Status (org.eclipse.core.runtime.Status)1 CloudSyncMetadataListener (org.eclipse.flux.core.internal.CloudSyncMetadataListener)1 CloudSyncResourceListener (org.eclipse.flux.core.internal.CloudSyncResourceListener)1 JavaRefactoringDescriptor (org.eclipse.jdt.core.refactoring.descriptors.JavaRefactoringDescriptor)1