Search in sources :

Example 1 with DeleteResourcesOperation

use of org.eclipse.ui.ide.undo.DeleteResourcesOperation in project translationstudio8 by heartsome.

the class DeleteResourceAndCloseEditorAction method scheduleDeleteJob.

/**
	 * Schedule a job to delete the resources to delete.
	 * @param resourcesToDelete
	 */
private void scheduleDeleteJob(final IResource[] resourcesToDelete) {
    // use a non-workspace job with a runnable inside so we can avoid
    // periodic updates
    Job deleteJob = new Job(IDEWorkbenchMessages.DeleteResourceAction_jobName) {

        public IStatus run(final IProgressMonitor monitor) {
            try {
                final DeleteResourcesOperation op = new DeleteResourcesOperation(resourcesToDelete, IDEWorkbenchMessages.DeleteResourceAction_operationLabel, deleteContent);
                op.setModelProviderIds(getModelProviderIds());
                // added to the undo history.
                if (deleteContent && containsOnlyProjects(resourcesToDelete)) {
                    // We must compute the execution status first so that any user prompting
                    // or validation checking occurs. Do it in a syncExec because
                    // we are calling this from a Job.
                    WorkbenchJob statusJob = new //$NON-NLS-1$
                    WorkbenchJob(//$NON-NLS-1$
                    "Status checking") {

                        /*
							 * (non-Javadoc)
							 * 
							 * @see
							 * org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor)
							 */
                        public IStatus runInUIThread(IProgressMonitor monitor) {
                            return op.computeExecutionStatus(monitor);
                        }
                    };
                    statusJob.setSystem(true);
                    statusJob.schedule();
                    try {
                        // block until the status is ready
                        statusJob.join();
                    } catch (InterruptedException e) {
                    // Do nothing as status will be a cancel
                    }
                    if (statusJob.getResult().isOK()) {
                        return op.execute(monitor, WorkspaceUndoUtil.getUIInfoAdapter(shellProvider.getShell()));
                    }
                    return statusJob.getResult();
                }
                return PlatformUI.getWorkbench().getOperationSupport().getOperationHistory().execute(op, monitor, WorkspaceUndoUtil.getUIInfoAdapter(shellProvider.getShell()));
            } catch (ExecutionException e) {
                if (e.getCause() instanceof CoreException) {
                    return ((CoreException) e.getCause()).getStatus();
                }
                return new Status(IStatus.ERROR, IDEWorkbenchPlugin.IDE_WORKBENCH, e.getMessage(), e);
            }
        }

        /*
			 * (non-Javadoc)
			 * 
			 * @see org.eclipse.core.runtime.jobs.Job#belongsTo(java.lang.Object)
			 */
        public boolean belongsTo(Object family) {
            if (IDEWorkbenchMessages.DeleteResourceAction_jobName.equals(family)) {
                return true;
            }
            return super.belongsTo(family);
        }
    };
    deleteJob.setUser(true);
    deleteJob.schedule();
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) WorkbenchJob(org.eclipse.ui.progress.WorkbenchJob) WorkbenchJob(org.eclipse.ui.progress.WorkbenchJob) Job(org.eclipse.core.runtime.jobs.Job) ExecutionException(org.eclipse.core.commands.ExecutionException) DeleteResourcesOperation(org.eclipse.ui.ide.undo.DeleteResourcesOperation)

Example 2 with DeleteResourcesOperation

use of org.eclipse.ui.ide.undo.DeleteResourcesOperation in project tdi-studio-se by Talend.

the class ExportProjectsAsAction method clearExternalLibraries.

/**
     * DOC zwang Comment method "clearExternalLibraries".
     */
private void clearExternalLibraries() {
    List<IResource> resourcesToDelete = new ArrayList<IResource>();
    IResource[] resourceArray = null;
    try {
        IProxyRepositoryFactory repositoryFactory = ProxyRepositoryFactory.getInstance();
        // fix for bug 15454
        Project[] projects = repositoryFactory.readProject(true);
        for (Project project : projects) {
            IProject fsProject = ResourceUtils.getProject(project);
            IFolder libJavaFolder = fsProject.getFolder(ExportProjectsAsAction.LIB);
            if (!libJavaFolder.exists()) {
                continue;
            }
            // final DeleteResourcesOperation operation = new DeleteResourcesOperation(new IResource[] {
            // libJavaFolder },
            // IDEWorkbenchMessages.DeleteResourceAction_operationLabel, true);
            final DeleteResourcesOperation operation = new DeleteResourcesOperation(new IResource[] { libJavaFolder }, Messages.getString("IDEWorkbenchMessages.DeleteResourceAction_operationLabel"), //$NON-NLS-1$
            true);
            PlatformUI.getWorkbench().getOperationSupport().getOperationHistory().execute(operation, null, WorkspaceUndoUtil.getUIInfoAdapter(window.getShell()));
        }
    } catch (Exception e) {
        // e.printStackTrace();
        ExceptionHandler.process(e);
    }
}
Also used : IProject(org.eclipse.core.resources.IProject) Project(org.talend.core.model.general.Project) ArrayList(java.util.ArrayList) IResource(org.eclipse.core.resources.IResource) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) IProject(org.eclipse.core.resources.IProject) DeleteResourcesOperation(org.eclipse.ui.ide.undo.DeleteResourcesOperation) CoreException(org.eclipse.core.runtime.CoreException) ExecutionException(org.eclipse.core.commands.ExecutionException) PersistenceException(org.talend.commons.exception.PersistenceException) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

ExecutionException (org.eclipse.core.commands.ExecutionException)2 CoreException (org.eclipse.core.runtime.CoreException)2 DeleteResourcesOperation (org.eclipse.ui.ide.undo.DeleteResourcesOperation)2 ArrayList (java.util.ArrayList)1 IFolder (org.eclipse.core.resources.IFolder)1 IProject (org.eclipse.core.resources.IProject)1 IResource (org.eclipse.core.resources.IResource)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 Job (org.eclipse.core.runtime.jobs.Job)1 WorkbenchJob (org.eclipse.ui.progress.WorkbenchJob)1 PersistenceException (org.talend.commons.exception.PersistenceException)1 Project (org.talend.core.model.general.Project)1 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)1