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;
}
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();
}
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();
}
});
}
});
}
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);
}
}
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));
}
Aggregations