use of org.eclipse.ui.actions.WorkspaceModifyOperation in project translationstudio8 by heartsome.
the class ImportProjectWizardPage method createProjects.
/**
* Create the selected projects
*
* @return boolean <code>true</code> if all project creations were
* successful.
*/
public boolean createProjects() {
saveWidgetValues();
final Object[] selected = projectsList.getCheckedElements();
createdProjects = new ArrayList();
WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
protected void execute(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
//$NON-NLS-1$
monitor.beginTask("", selected.length);
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
for (int i = 0; i < selected.length; i++) {
createExistingProject((ProjectRecord) selected[i], new SubProgressMonitor(monitor, 1));
}
} finally {
monitor.done();
}
}
};
// run the new project creation operation
try {
getContainer().run(true, true, op);
} catch (InterruptedException e) {
return false;
} catch (InvocationTargetException e) {
// one of the steps resulted in a core exception
Throwable t = e.getTargetException();
String message = DataTransferMessages.WizardExternalProjectImportPage_errorMessage;
IStatus status;
if (t instanceof CoreException) {
status = ((CoreException) t).getStatus();
} else {
status = new Status(IStatus.ERROR, IDEWorkbenchPlugin.IDE_WORKBENCH, 1, message, t);
}
ErrorDialog.openError(getShell(), message, null, status);
return false;
}
ArchiveFileManipulations.closeStructureProvider(structureProvider, getShell());
return true;
}
use of org.eclipse.ui.actions.WorkspaceModifyOperation in project translationstudio8 by heartsome.
the class NewFolderDialogOfHs method createNewFolder.
/**
* Creates a new folder with the given name and optionally linking to
* the specified link target.
*
* @param folderName name of the new folder
* @param linkTarget name of the link target folder. may be null.
* @return IFolder the new folder
*/
private IFolder createNewFolder(String folderName, final URI linkTarget) {
final IFolder folderHandle = createFolderHandle(folderName);
WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
public void execute(IProgressMonitor monitor) throws CoreException {
try {
monitor.beginTask(IDEWorkbenchMessages.NewFolderDialog_progress, 2000);
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
if (linkTarget == null) {
folderHandle.create(false, true, monitor);
} else {
folderHandle.createLink(linkTarget, IResource.ALLOW_MISSING_LOCAL, monitor);
}
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
} finally {
monitor.done();
}
}
};
try {
PlatformUI.getWorkbench().getProgressService().busyCursorWhile(operation);
} catch (InterruptedException exception) {
return null;
} catch (InvocationTargetException exception) {
if (exception.getTargetException() instanceof CoreException) {
ErrorDialog.openError(getShell(), // no special message
IDEWorkbenchMessages.NewFolderDialog_errorTitle, // no special message
null, ((CoreException) exception.getTargetException()).getStatus());
} else {
// CoreExceptions are handled above, but unexpected runtime exceptions and errors may still occur.
IDEWorkbenchPlugin.log(getClass(), "createNewFolder", //$NON-NLS-1$
exception.getTargetException());
MessageDialog.openError(getShell(), IDEWorkbenchMessages.NewFolderDialog_errorTitle, NLS.bind(IDEWorkbenchMessages.NewFolderDialog_internalError, exception.getTargetException().getMessage()));
}
return null;
}
return folderHandle;
}
use of org.eclipse.ui.actions.WorkspaceModifyOperation in project translationstudio8 by heartsome.
the class ResourceMgmtActionProvider method makeActions.
protected void makeActions() {
IShellProvider sp = new IShellProvider() {
public Shell getShell() {
return shell;
}
};
openProjectAction = new OpenResourceAction(sp);
openProjectAction.setText(WorkbenchNavigatorMessages.actions_ResourceMgmtActionProvider_openProjectAction);
closeProjectAction = new CloseResourceAction(sp);
closeProjectAction.setText(WorkbenchNavigatorMessages.actions_ResourceMgmtActionProvider_closeProjectAction);
//
// closeUnrelatedProjectsAction = new CloseUnrelatedProjectsAction(sp);
// closeUnrelatedProjectsAction.setText("关闭无关的项目");
refreshAction = new RefreshAction(sp) {
public void run() {
final IStatus[] errorStatus = new IStatus[1];
errorStatus[0] = Status.OK_STATUS;
final WorkspaceModifyOperation op = (WorkspaceModifyOperation) createOperation(errorStatus);
WorkspaceJob job = new //$NON-NLS-1$
WorkspaceJob(//$NON-NLS-1$
"refresh") {
public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
try {
op.run(monitor);
if (shell != null && !shell.isDisposed()) {
shell.getDisplay().asyncExec(new Runnable() {
public void run() {
StructuredViewer viewer = getActionSite().getStructuredViewer();
if (viewer != null && viewer.getControl() != null && !viewer.getControl().isDisposed()) {
viewer.refresh();
}
}
});
}
} catch (InvocationTargetException e) {
String msg = NLS.bind(WorkbenchNavigatorMessages.actions_ResourceMgmtActionProvider_logTitle, getClass().getName(), e.getTargetException());
throw new CoreException(new Status(IStatus.ERROR, NavigatorPlugin.PLUGIN_ID, IStatus.ERROR, msg, e.getTargetException()));
} catch (InterruptedException e) {
return Status.CANCEL_STATUS;
}
return errorStatus[0];
}
};
ISchedulingRule rule = op.getRule();
if (rule != null) {
job.setRule(rule);
}
job.setUser(true);
job.schedule();
}
};
refreshAction.setText(WorkbenchNavigatorMessages.actions_ResourceMgmtActionProvider_refreshAction);
//$NON-NLS-1$
refreshAction.setDisabledImageDescriptor(getImageDescriptor("dlcl16/refresh_nav.gif"));
//$NON-NLS-1$
refreshAction.setImageDescriptor(getImageDescriptor("elcl16/refresh_nav.gif"));
refreshAction.setActionDefinitionId(IWorkbenchCommandConstants.FILE_REFRESH);
if (getContext() == null) {
refreshAction.setEnabled(false);
} else {
IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
refreshAction.selectionChanged(selection);
refreshAction.setEnabled(!selection.isEmpty());
}
// buildAction = new BuildAction(sp, IncrementalProjectBuilder.INCREMENTAL_BUILD);
// buildAction.setActionDefinitionId(IWorkbenchCommandConstants.PROJECT_BUILD_PROJECT);
}
use of org.eclipse.ui.actions.WorkspaceModifyOperation in project sling by apache.
the class AbstractNewSlingApplicationWizard method performFinish.
/**
* This method is called when 'Finish' button is pressed in the wizard. We will create an operation and run it using
* wizard as execution context.
*/
public boolean performFinish() {
try {
// create projects
final List<IProject> createdProjects = new ArrayList<>();
getContainer().run(false, true, new WorkspaceModifyOperation() {
@Override
protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
createdProjects.addAll(createProjects(monitor));
}
});
// configure projects
final Projects[] projects = new Projects[1];
getContainer().run(false, true, new WorkspaceModifyOperation() {
@Override
protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
projects[0] = configureCreatedProjects(createdProjects, monitor);
}
});
// deploy the projects on server
getContainer().run(false, true, new WorkspaceModifyOperation() {
@Override
protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
deployProjectsOnServer(projects[0], monitor);
}
});
// ensure server is started and all modules are published
getContainer().run(false, false, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
publishModules(createdProjects, monitor);
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
}
});
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return false;
} catch (InvocationTargetException e) {
reportError(e.getTargetException());
return false;
}
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);
}
}
Aggregations