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