use of org.eclipse.ui.actions.WorkspaceModifyOperation in project xtext-xtend by eclipse.
the class AbstractNewXtendElementWizardPage method createType.
protected int createType() {
final int[] size = { 0 };
IRunnableWithProgress op = new WorkspaceModifyOperation() {
@Override
protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
try {
if (!getPackageFragment().exists()) {
try {
getPackageFragmentRoot().createPackageFragment(getPackageFragment().getElementName(), true, monitor);
} catch (JavaModelException e) {
displayError(Messages.ERROR_CREATING_PACKAGE, e.getMessage());
}
}
IResource res = getPackageFragment().getResource();
// $NON-NLS-1$
IFile xtendFile = ((IFolder) res).getFile(getTypeNameWithoutParameters() + ".xtend");
URI uri = storage2UriMapper.getUri(xtendFile);
size[0] = createXtendElement(monitor, xtendFile, whitespaceInformationProvider.getIndentationInformation(uri).getIndentString(), whitespaceInformationProvider.getLineSeparatorInformation(uri).getLineSeparator());
} catch (OperationCanceledException e) {
throw new InterruptedException();
} catch (Exception e) {
throw new InvocationTargetException(e);
} finally {
monitor.done();
}
}
};
try {
getContainer().run(true, false, op);
} catch (InterruptedException e) {
// cancelled by user
return 0;
} catch (InvocationTargetException e) {
Throwable realException = e.getTargetException();
MessageDialog.openError(getShell(), getElementCreationErrorMessage(), realException.getMessage());
}
return size[0];
}
use of org.eclipse.ui.actions.WorkspaceModifyOperation in project xtext-xtend by eclipse.
the class WorkbenchTestHelper method tearDown.
public void tearDown() throws Exception {
if (workbench.getActiveWorkbenchWindow() != null)
workbench.getActiveWorkbenchWindow().getActivePage().closeAllEditors(false);
new WorkspaceModifyOperation() {
@Override
protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
for (IFile file : getFiles()) {
try {
file.delete(true, null);
} catch (Exception exc) {
throw new RuntimeException(exc);
}
}
getFiles().clear();
IFolder binFolder = getProject(false).getFolder("bin");
if (binFolder.exists()) {
for (IResource binMember : binFolder.members()) {
try {
binMember.delete(true, null);
} catch (Exception exc) {
throw new RuntimeException(exc);
}
}
}
if (isLazyCreatedProject) {
deleteProject(getProject(false));
isLazyCreatedProject = false;
}
}
}.run(null);
IResourcesSetupUtil.waitForBuild();
}
use of org.eclipse.ui.actions.WorkspaceModifyOperation in project Palladio-Editors-Sirius by PalladioSimulator.
the class NewPalladioProjectWizard method performFinish.
@Override
public boolean performFinish() {
final IProject projectHandle = this.projectCreationPage.getProjectHandle();
final java.net.URI projectURI = (!this.projectCreationPage.useDefaults()) ? this.projectCreationPage.getLocationURI() : null;
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
final IProjectDescription desc = workspace.newProjectDescription(projectHandle.getName());
desc.setLocationURI(projectURI);
/*
* Creating the project encapsulated in a workspace operation
*/
final WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
@Override
protected void execute(final IProgressMonitor monitor) throws CoreException {
NewPalladioProjectWizard.this.project = createProject(desc, projectHandle, monitor);
}
};
/*
* This isn't as robust as the code in the BasicNewProjectResourceWizard class. Consider
* beefing this up to improve error handling.
*/
try {
getContainer().run(true, true, op);
} catch (final Exception e) {
MessageDialog.openError(getShell(), "Error", "An unexpected error occured. See stack trace");
e.printStackTrace();
return false;
}
if (this.project == null) {
return false;
}
BasicNewProjectResourceWizard.updatePerspective(this.config);
BasicNewProjectResourceWizard.selectAndReveal(this.project, this.workbench.getActiveWorkbenchWindow());
if (!getCurrentPerspectiveId().equals(PERSPECTIVE_ID)) {
boolean confirm = MessageDialog.openConfirm(getShell(), "Palladio Perspective", "This project is associated with the Palladio perspective.\n\nDo you want to open this perspective now?");
if (confirm)
openPalladioPerspective();
}
return true;
}
use of org.eclipse.ui.actions.WorkspaceModifyOperation in project eclipse.platform.text by eclipse.
the class AbstractDecoratedTextEditor method revealInEditor.
/**
* Selects and reveals the given offset and length in the given editor part.
*
* @param editor the editor part
* @param offset the offset
* @param length the length
* @since 3.7
*/
private static void revealInEditor(IEditorPart editor, final int offset, final int length) {
if (editor instanceof ITextEditor) {
((ITextEditor) editor).selectAndReveal(offset, length);
return;
}
// Support for non-text editor - try IGotoMarker interface
final IGotoMarker gotoMarkerTarget;
if (editor instanceof IGotoMarker)
gotoMarkerTarget = (IGotoMarker) editor;
else
gotoMarkerTarget = editor != null ? editor.getAdapter(IGotoMarker.class) : null;
if (gotoMarkerTarget != null) {
final IEditorInput input = editor.getEditorInput();
if (input instanceof IFileEditorInput) {
WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
@Override
protected void execute(IProgressMonitor monitor) throws CoreException {
IMarker marker = null;
try {
marker = ((IFileEditorInput) input).getFile().createMarker(IMarker.TEXT);
marker.setAttribute(IMarker.CHAR_START, offset);
marker.setAttribute(IMarker.CHAR_END, offset + length);
gotoMarkerTarget.gotoMarker(marker);
} finally {
if (marker != null)
marker.delete();
}
}
};
try {
op.run(null);
} catch (InvocationTargetException ex) {
// reveal failed
} catch (InterruptedException e) {
// $NON-NLS-1$
Assert.isTrue(false, "this operation can not be canceled");
}
}
return;
}
}
use of org.eclipse.ui.actions.WorkspaceModifyOperation in project xtext-xtend by eclipse.
the class JavaRefactoringIntegrationTest method renameXtendElement.
protected void renameXtendElement(final XtextEditor editor, final int offset, final String newName, final int allowedSeverity) throws Exception {
syncUtil.totalSync(false);
new WorkspaceModifyOperation() {
@Override
protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
ProcessorBasedRefactoring renameRefactoring = createXtendRenameRefactoring(editor, offset, newName);
assertTrue("Refactoring not applicable", renameRefactoring.isApplicable());
RefactoringStatus status = renameRefactoring.checkAllConditions(new NullProgressMonitor());
assertTrue(status.toString(), status.getSeverity() <= allowedSeverity);
Change change = renameRefactoring.createChange(new NullProgressMonitor());
change.perform(new NullProgressMonitor());
}
}.run(new NullProgressMonitor());
syncUtil.totalSync(false);
assertTrue(compositeRefactoringProcessorAccess.isDisposed());
}
Aggregations