use of org.eclipse.ui.actions.WorkspaceModifyOperation in project knime-core by knime.
the class WorkflowImportWizard method createWorkflows.
/**
* Create the selected workflows.
*
* @return boolean <code>true</code> if all project creations were
* successful.
*/
public boolean createWorkflows() {
final boolean copy = m_import.isCopyWorkflows();
final String target = m_import.getDestination();
final Collection<IWorkflowImportElement> workflows = m_import.getWorkflowsToImport();
// validate target path
final IPath targetPath = getValidatedTargetPath(target);
WorkspaceModifyOperation op = new WorkflowImportOperation(workflows, targetPath, copy, getShell());
// run the new project creation operation
try {
getContainer().run(true, false, op);
} catch (InterruptedException e) {
return false;
} catch (InvocationTargetException e) {
// one of the steps resulted in a core exception
Throwable t = e.getTargetException();
String message = "Error during import!";
IStatus status;
if (t instanceof CoreException) {
status = ((CoreException) t).getStatus();
} else {
status = new Status(IStatus.ERROR, KNIMEUIPlugin.PLUGIN_ID, 1, message, t);
}
LOGGER.error(message, t);
ErrorDialog.openError(getShell(), message, null, status);
return false;
} catch (Exception e) {
String message = "Error during import!";
IStatus status = new Status(IStatus.ERROR, KNIMEUIPlugin.PLUGIN_ID, 1, message, e);
ErrorDialog.openError(getShell(), message, null, status);
LOGGER.error(message, e);
}
return true;
}
use of org.eclipse.ui.actions.WorkspaceModifyOperation in project tdi-studio-se by Talend.
the class AbstractTalendEditor method doSaveAs.
@Override
public void doSaveAs() {
SaveAsDialog dialog = new SaveAsDialog(getSite().getWorkbenchWindow().getShell());
dialog.setOriginalFile(((IFileEditorInput) getEditorInput()).getFile());
dialog.open();
IPath path = dialog.getResult();
if (path == null) {
return;
}
IWorkspace workspace = ResourcesPlugin.getWorkspace();
final IFile file = workspace.getRoot().getFile(path);
WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
@Override
public void execute(final IProgressMonitor monitor) throws CoreException {
try {
savePreviewPictures();
getProcess().saveXmlFile();
// file.refreshLocal(IResource.DEPTH_ONE, monitor);
} catch (Exception e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
}
};
try {
new ProgressMonitorDialog(getSite().getWorkbenchWindow().getShell()).run(false, true, op);
// setInput(new FileEditorInput((IFile) file));
getCommandStack().markSaveLocation();
setDirty(false);
} catch (Exception e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
}
use of org.eclipse.ui.actions.WorkspaceModifyOperation in project bndtools by bndtools.
the class ImportBndWorkspaceWizard method performFinish.
@Override
public boolean performFinish() {
final ImportSettings importSettings = new ImportSettings(mainPage.getSelectedFolder(), mainPage.isDeleteSettings(), mainPage.isInferExecutionEnvironment());
// create the new project operation
final WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
@Override
protected void execute(IProgressMonitor monitor) throws CoreException {
try {
importProjects(importSettings, monitor);
} catch (Exception e) {
throw new CoreException(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, "Error during import of Bnd workspace!", e));
}
}
};
Job importJob = new Job("Import Bnd Workspace") {
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
op.run(monitor);
} catch (InvocationTargetException e) {
Throwable t = e.getCause();
if (t instanceof CoreException && ((CoreException) t).getStatus().getException() != null) {
// unwrap the cause of the CoreException
t = ((CoreException) t).getStatus().getException();
}
return new Status(Status.ERROR, Plugin.PLUGIN_ID, "Could not finish import job for Bnd Workspace!", t);
} catch (InterruptedException e) {
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
};
importJob.schedule();
try {
// Prompt to switch to the BndTools perspective
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
IPerspectiveDescriptor currentPerspective = window.getActivePage().getPerspective();
if (!"bndtools.perspective".equals(currentPerspective.getId())) {
if (MessageDialog.openQuestion(getShell(), "Bndtools Perspective", "Switch to the Bndtools perspective?")) {
this.workbench.showPerspective("bndtools.perspective", window);
}
}
} catch (WorkbenchException e) {
error("Unable to switch to BndTools perspective", e);
}
return true;
}
use of org.eclipse.ui.actions.WorkspaceModifyOperation in project xtext-xtend by eclipse.
the class UIResourceChangeRegistryTest method testFileContents_changed.
@Test
public void testFileContents_changed() {
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);
IFile _file = folder.getFile("test.txt");
StringInputStream _stringInputStream = new StringInputStream("Hello");
_file.create(_stringInputStream, true, null);
}
};
this.modifyWorkspace(_function);
final String folderPath = "/foo/bar/test.txt";
this.resourceChangeRegistry.registerGetContents(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 Xtend");
_file.setContents(_stringInputStream, true, true, null);
}
};
this.modifyWorkspace(_function_1);
Assert.assertFalse(this.resourceChangeRegistry.getContentsListeners().containsKey(folderPath));
Assert.assertEquals(1, this.resourceChangeRegistry.queuedURIs.size());
this.resourceChangeRegistry.registerGetContents(folderPath, this.uri);
final WorkspaceModifyOperation _function_2 = new WorkspaceModifyOperation() {
@Override
protected void execute(final IProgressMonitor it) throws CoreException, InvocationTargetException, InterruptedException {
folder.getFile("test.txt").setCharset("UTF-8", null);
}
};
this.modifyWorkspace(_function_2);
Assert.assertFalse(this.resourceChangeRegistry.getContentsListeners().containsKey(folderPath));
Assert.assertEquals(2, this.resourceChangeRegistry.queuedURIs.size());
this.resourceChangeRegistry.registerGetContents(folderPath, this.uri);
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.getContentsListeners().containsKey(folderPath));
Assert.assertEquals(3, 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 testFolderExists.
@Test
public void testFolderExists() {
try {
final String folderPath = "/foo/bar";
this.resourceChangeRegistry.registerExists(folderPath, this.uri);
Assert.assertTrue(this.resourceChangeRegistry.getExistsListeners().containsKey(folderPath));
final IProject project = WorkbenchTestHelper.createPluginProject("foo");
Assert.assertTrue(this.resourceChangeRegistry.getExistsListeners().containsKey(folderPath));
final IFolder folder = project.getFolder("bar");
Assert.assertTrue(this.resourceChangeRegistry.getExistsListeners().containsKey(folderPath));
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.getExistsListeners().containsKey(folderPath));
Assert.assertEquals(1, this.resourceChangeRegistry.queuedURIs.size());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations