Search in sources :

Example 1 with WorkspaceModifyOperation

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;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ArrayList(java.util.ArrayList) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException)

Example 2 with WorkspaceModifyOperation

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;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IFolder(org.eclipse.core.resources.IFolder)

Example 3 with WorkspaceModifyOperation

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);
}
Also used : IShellProvider(org.eclipse.jface.window.IShellProvider) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) CloseResourceAction(org.eclipse.ui.actions.CloseResourceAction) IStatus(org.eclipse.core.runtime.IStatus) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) OpenResourceAction(org.eclipse.ui.actions.OpenResourceAction) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) InvocationTargetException(java.lang.reflect.InvocationTargetException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) RefreshAction(org.eclipse.ui.actions.RefreshAction) CoreException(org.eclipse.core.runtime.CoreException) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer)

Example 4 with WorkspaceModifyOperation

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;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 5 with WorkspaceModifyOperation

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);
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) SaveAsDialog(org.eclipse.ui.dialogs.SaveAsDialog) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) IWorkspace(org.eclipse.core.resources.IWorkspace) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) CoreException(org.eclipse.core.runtime.CoreException) PersistenceException(org.talend.commons.exception.PersistenceException)

Aggregations

CoreException (org.eclipse.core.runtime.CoreException)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 WorkspaceModifyOperation (org.eclipse.ui.actions.WorkspaceModifyOperation)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 IStatus (org.eclipse.core.runtime.IStatus)3 Status (org.eclipse.core.runtime.Status)3 ArrayList (java.util.ArrayList)2 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)2 IOException (java.io.IOException)1 IFile (org.eclipse.core.resources.IFile)1 IFolder (org.eclipse.core.resources.IFolder)1 IProject (org.eclipse.core.resources.IProject)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)1 IPath (org.eclipse.core.runtime.IPath)1 MultiStatus (org.eclipse.core.runtime.MultiStatus)1 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)1 ISchedulingRule (org.eclipse.core.runtime.jobs.ISchedulingRule)1 Job (org.eclipse.core.runtime.jobs.Job)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1