Search in sources :

Example 6 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 7 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 8 with IProgressMonitor

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

the class LiveEditConnector method dispose.

public void dispose() {
    this.liveEditCoordinator.removeLiveEditConnector(liveEditConnector);
    this.repository.removeRepositoryListener(repositoryListener);
    FileBuffers.getTextFileBufferManager().removeFileBufferListener(fileBufferListener);
    ResourcesPlugin.getWorkspace().removeResourceChangeListener(workspaceListener);
    WorkbenchJob jw = new WorkbenchJob("Removing listener") {

        @Override
        public IStatus runInUIThread(IProgressMonitor monitor) {
            IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
            if (window != null) {
                window.getActivePage().removePartListener(partListener);
            }
            return Status.OK_STATUS;
        }
    };
    jw.setSystem(true);
    jw.schedule();
    for (IDocument document : documentMappings.values()) {
        if (document != null) {
            document.removeDocumentListener(documentListener);
        }
    }
    resourceMappings.clear();
    documentMappings.clear();
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) WorkbenchJob(org.eclipse.ui.progress.WorkbenchJob) IDocument(org.eclipse.jface.text.IDocument)

Example 9 with IProgressMonitor

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

the class AuthFailureReporter method newValue.

@Override
public void newValue(Observable<ConnectionStatus> o, ConnectionStatus v) {
    if (v.isAuthFailure()) {
        UIJob job = new UIJob("Flux Error Reporter") {

            @Override
            public IStatus runInUIThread(IProgressMonitor monitor) {
                MessageDialog.openError(null, "Flux Connection Failed", "Flux Web Socket handshake failed. Most likely this means " + "your Flux credentials are invalid.");
                return Status.OK_STATUS;
            }
        };
        job.schedule();
    //We only report this error once. 
    // since this error is all we handle... there's no point to continue listening  
    } else if (v.isConnected()) {
        //This means credentials must be valid and this listener now useless.
        dispose();
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) UIJob(org.eclipse.ui.progress.UIJob)

Example 10 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)392 InvocationTargetException (java.lang.reflect.InvocationTargetException)152 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)144 CoreException (org.eclipse.core.runtime.CoreException)104 IStatus (org.eclipse.core.runtime.IStatus)85 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)74 ArrayList (java.util.ArrayList)73 Status (org.eclipse.core.runtime.Status)65 Job (org.eclipse.core.runtime.jobs.Job)57 IOException (java.io.IOException)54 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)53 ITask (com.cubrid.common.core.task.ITask)49 IFile (org.eclipse.core.resources.IFile)46 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)43 File (java.io.File)42 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)41 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)37 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)37 PersistenceException (org.talend.commons.exception.PersistenceException)36 IProject (org.eclipse.core.resources.IProject)33