Search in sources :

Example 41 with IProgressMonitor

use of org.eclipse.core.runtime.IProgressMonitor in project che by eclipse.

the class JavaMoveProcessor method createChange.

@Override
public Change createChange(IProgressMonitor pm) throws CoreException {
    Assert.isTrue(fMovePolicy.getJavaElementDestination() == null || fMovePolicy.getResourceDestination() == null);
    Assert.isTrue(fMovePolicy.getJavaElementDestination() != null || fMovePolicy.getResourceDestination() != null);
    try {
        final DynamicValidationStateChange result = new DynamicValidationStateChange(RefactoringCoreMessages.JavaMoveProcessor_change_name) {

            @Override
            public ChangeDescriptor getDescriptor() {
                return fMovePolicy.getDescriptor();
            }

            @Override
            public Change perform(IProgressMonitor pm2) throws CoreException {
                Change change = super.perform(pm2);
                Change[] changes = getChildren();
                for (int index = 0; index < changes.length; index++) {
                    if (!(changes[index] instanceof TextEditBasedChange))
                        return null;
                }
                return change;
            }
        };
        CreateTargetExecutionLog log = null;
        if (fCreateTargetQueries instanceof MonitoringCreateTargetQueries) {
            final MonitoringCreateTargetQueries queries = (MonitoringCreateTargetQueries) fCreateTargetQueries;
            final ICreateTargetQueries delegate = queries.getDelegate();
            if (delegate instanceof LoggedCreateTargetQueries)
                log = queries.getCreateTargetExecutionLog();
        }
        if (log != null) {
            final Object[] selected = log.getSelectedElements();
            for (int index = 0; index < selected.length; index++) {
                result.add(new LoggedCreateTargetChange(selected[index], fCreateTargetQueries));
            }
        }
        Change change = fMovePolicy.createChange(pm);
        if (change instanceof CompositeChange) {
            CompositeChange subComposite = (CompositeChange) change;
            result.merge(subComposite);
        } else {
            result.add(change);
        }
        return result;
    } finally {
        pm.done();
    }
}
Also used : CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) TextEditBasedChange(org.eclipse.ltk.core.refactoring.TextEditBasedChange) Change(org.eclipse.ltk.core.refactoring.Change) DynamicValidationStateChange(org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange) DynamicValidationStateChange(org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TextEditBasedChange(org.eclipse.ltk.core.refactoring.TextEditBasedChange) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange)

Example 42 with IProgressMonitor

use of org.eclipse.core.runtime.IProgressMonitor in project che by eclipse.

the class PerformChangeOperation method executeChange.

/**
	 * Actually executes the change.
	 *
	 * @param pm a progress monitor to report progress
	 *
	 * @throws CoreException if an unexpected error occurs during
	 *  change execution
	 */
protected void executeChange(IProgressMonitor pm) throws CoreException {
    fChangeExecuted = false;
    if (!fChange.isEnabled())
        return;
    IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

        public void run(IProgressMonitor monitor) throws CoreException {
            boolean undoInitialized = false;
            try {
                //$NON-NLS-1$
                monitor.beginTask("", 10);
                fValidationStatus = fChange.isValid(new SubProgressMonitor(monitor, 1));
                if (fValidationStatus.hasFatalError())
                    return;
                boolean aboutToPerformChangeCalled = false;
                try {
                    if (fUndoManager != null) {
                        ResourcesPlugin.getWorkspace().checkpoint(false);
                        fUndoManager.aboutToPerformChange(fChange);
                        aboutToPerformChangeCalled = true;
                    }
                    fChangeExecutionFailed = true;
                    fUndoChange = fChange.perform(new SubProgressMonitor(monitor, 9));
                    fChangeExecutionFailed = false;
                    fChangeExecuted = true;
                } finally {
                    if (fUndoManager != null) {
                        ResourcesPlugin.getWorkspace().checkpoint(false);
                        if (aboutToPerformChangeCalled)
                            fUndoManager.changePerformed(fChange, !fChangeExecutionFailed);
                    }
                }
                fChange.dispose();
                if (fUndoChange != null) {
                    fUndoChange.initializeValidationData(new NotCancelableProgressMonitor(new SubProgressMonitor(monitor, 1)));
                    undoInitialized = true;
                }
                if (fUndoManager != null) {
                    if (fUndoChange != null) {
                        fUndoManager.addUndo(fUndoName, fUndoChange);
                    } else {
                        fUndoManager.flush();
                    }
                }
            } catch (CoreException e) {
                if (fUndoManager != null)
                    fUndoManager.flush();
                if (fUndoChange != null && undoInitialized) {
                    Change ch = fUndoChange;
                    fUndoChange = null;
                    ch.dispose();
                }
                fUndoChange = null;
                throw e;
            } catch (RuntimeException e) {
                if (fUndoManager != null)
                    fUndoManager.flush();
                if (fUndoChange != null && undoInitialized) {
                    Change ch = fUndoChange;
                    fUndoChange = null;
                    ch.dispose();
                }
                fUndoChange = null;
                throw e;
            } finally {
                monitor.done();
            }
        }
    };
    ResourcesPlugin.getWorkspace().run(runnable, fSchedulingRule, IWorkspace.AVOID_UPDATE, pm);
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) NotCancelableProgressMonitor(org.eclipse.ltk.internal.core.refactoring.NotCancelableProgressMonitor) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 43 with IProgressMonitor

use of org.eclipse.core.runtime.IProgressMonitor in project che by eclipse.

the class DynamicValidationStateChange method perform.

/**
	 * {@inheritDoc}
	 */
@Override
public Change perform(IProgressMonitor pm) throws CoreException {
    final Change[] result = new Change[1];
    IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

        public void run(IProgressMonitor monitor) throws CoreException {
            result[0] = DynamicValidationStateChange.super.perform(monitor);
        }
    };
    JavaCore.run(runnable, fSchedulingRule, pm);
    return result[0];
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) Change(org.eclipse.ltk.core.refactoring.Change)

Example 44 with IProgressMonitor

use of org.eclipse.core.runtime.IProgressMonitor in project generator by mybatis.

the class WorkspaceUtilities method createProject.

private static IProject createProject(String projectName) throws CoreException {
    final IProject project = getWorkspaceRoot().getProject(projectName);
    IWorkspaceRunnable create = new IWorkspaceRunnable() {

        public void run(IProgressMonitor monitor) throws CoreException {
            project.create(null);
            project.open(null);
        }
    };
    getWorkspace().run(create, null);
    return project;
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IProject(org.eclipse.core.resources.IProject)

Example 45 with IProgressMonitor

use of org.eclipse.core.runtime.IProgressMonitor in project generator by mybatis.

the class NewConfigFileWizard 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() {
    final String containerName = page.getLocation();
    final String fileName = page.getFileName();
    IRunnableWithProgress op = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            try {
                doFinish(containerName, fileName, monitor);
            } catch (CoreException e) {
                throw new InvocationTargetException(e);
            } finally {
                monitor.done();
            }
        }
    };
    try {
        getContainer().run(true, false, op);
    } catch (InterruptedException e) {
        return false;
    } catch (InvocationTargetException e) {
        Throwable realException = e.getTargetException();
        MessageDialog.openError(getShell(), "Error", realException.getMessage());
        return false;
    }
    return true;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Aggregations

IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)530 InvocationTargetException (java.lang.reflect.InvocationTargetException)181 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)162 CoreException (org.eclipse.core.runtime.CoreException)134 Job (org.eclipse.core.runtime.jobs.Job)133 IStatus (org.eclipse.core.runtime.IStatus)110 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)83 Status (org.eclipse.core.runtime.Status)81 ArrayList (java.util.ArrayList)80 IOException (java.io.IOException)69 IFile (org.eclipse.core.resources.IFile)60 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)58 File (java.io.File)56 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)54 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)50 ITask (com.cubrid.common.core.task.ITask)49 IProject (org.eclipse.core.resources.IProject)43 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)37 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)37 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)37