Search in sources :

Example 26 with CoreException

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

the class ProcessorBasedRefactoring method createChange.

/**
	 * {@inheritDoc}
	 */
public Change createChange(IProgressMonitor pm) throws CoreException {
    if (pm == null)
        pm = new NullProgressMonitor();
    //$NON-NLS-1$
    pm.beginTask("", fParticipants.size() + 3);
    pm.setTaskName(RefactoringCoreMessages.ProcessorBasedRefactoring_create_change);
    Change processorChange = getProcessor().createChange(new SubProgressMonitor(pm, 1));
    if (pm.isCanceled())
        throw new OperationCanceledException();
    fTextChangeMap = new HashMap();
    addToTextChangeMap(processorChange);
    List /*<Change>*/
    changes = new ArrayList();
    List /*<Change>*/
    preChanges = new ArrayList();
    Map /*<Change, RefactoringParticipant>*/
    participantMap = new HashMap();
    for (Iterator iter = fParticipants.iterator(); iter.hasNext(); ) {
        final RefactoringParticipant participant = (RefactoringParticipant) iter.next();
        try {
            //$NON-NLS-1$
            final PerformanceStats stats = PerformanceStats.getStats(PERF_CREATE_CHANGES, getName() + ", " + participant.getName());
            stats.startRun();
            Change preChange = participant.createPreChange(new SubProgressMonitor(pm, 1));
            Change change = participant.createChange(new SubProgressMonitor(pm, 1));
            stats.endRun();
            if (preChange != null) {
                if (fPreChangeParticipants == null)
                    fPreChangeParticipants = new ArrayList();
                fPreChangeParticipants.add(participant);
                preChanges.add(preChange);
                participantMap.put(preChange, participant);
                addToTextChangeMap(preChange);
            }
            if (change != null) {
                changes.add(change);
                participantMap.put(change, participant);
                addToTextChangeMap(change);
            }
        } catch (CoreException e) {
            disableParticipant(participant, e);
            throw e;
        } catch (OperationCanceledException e) {
            throw e;
        } catch (RuntimeException e) {
            disableParticipant(participant, e);
            throw e;
        }
        if (pm.isCanceled())
            throw new OperationCanceledException();
    }
    fTextChangeMap = null;
    Change postChange = getProcessor().postCreateChange((Change[]) changes.toArray(new Change[changes.size()]), new SubProgressMonitor(pm, 1));
    ProcessorChange result = new ProcessorChange(getName());
    result.addAll((Change[]) preChanges.toArray(new Change[preChanges.size()]));
    result.add(processorChange);
    result.addAll((Change[]) changes.toArray(new Change[changes.size()]));
    result.setParticipantMap(participantMap);
    result.setPreChangeParticipants(fPreChangeParticipants);
    if (postChange != null)
        result.add(postChange);
    return result;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) HashMap(java.util.HashMap) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ArrayList(java.util.ArrayList) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) TextChange(org.eclipse.ltk.core.refactoring.TextChange) Change(org.eclipse.ltk.core.refactoring.Change) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) PerformanceStats(org.eclipse.core.runtime.PerformanceStats) CoreException(org.eclipse.core.runtime.CoreException) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 27 with CoreException

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

the class RefactoringHistoryService method moveHistory.

/**
	 * Moves the project history from the old project to the new one.
	 *
	 * @param oldProject
	 *            the old project, which does not exist anymore
	 * @param newProject
	 *            the new project, which already exists
	 * @param monitor
	 *            the progress monitor to use
	 */
private void moveHistory(final IProject oldProject, final IProject newProject, final IProgressMonitor monitor) {
    try {
        monitor.beginTask(RefactoringCoreMessages.RefactoringHistoryService_updating_history, 60);
        final IFileStore historyStore = EFS.getLocalFileSystem().getStore(RefactoringCorePlugin.getDefault().getStateLocation()).getChild(NAME_HISTORY_FOLDER);
        final String oldName = oldProject.getName();
        final String newName = newProject.getName();
        final IFileStore oldStore = historyStore.getChild(oldName);
        if (oldStore.fetchInfo(EFS.NONE, new SubProgressMonitor(monitor, 10, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)).exists()) {
            final IFileStore newStore = historyStore.getChild(newName);
            if (newStore.fetchInfo(EFS.NONE, new SubProgressMonitor(monitor, 10, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)).exists())
                newStore.delete(EFS.NONE, new SubProgressMonitor(monitor, 20, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
            oldStore.move(newStore, EFS.OVERWRITE, new SubProgressMonitor(monitor, 20, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
        }
    } catch (CoreException exception) {
        RefactoringCorePlugin.log(exception);
    } finally {
        monitor.done();
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IFileStore(org.eclipse.core.filesystem.IFileStore) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 28 with CoreException

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

the class UndoManager2 method performRedo.

public void performRedo(IValidationCheckResultQuery query, IProgressMonitor pm) throws CoreException {
    IUndoableOperation redo = fOperationHistory.getRedoOperation(RefactoringCorePlugin.getUndoContext());
    UndoableOperation2ChangeAdapter changeOperation = getUnwrappedOperation(redo);
    if (changeOperation == null)
        throw new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), IStatus.ERROR, RefactoringCoreMessages.UndoManager2_no_change, null));
    if (query == null)
        query = new NullQuery();
    try {
        fOperationHistory.redoOperation(redo, pm, new QueryAdapter(query));
    } catch (ExecutionException e) {
        handleException(e);
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) CoreException(org.eclipse.core.runtime.CoreException) IUndoableOperation(org.eclipse.core.commands.operations.IUndoableOperation) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 29 with CoreException

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

the class UndoManager2 method performUndo.

public void performUndo(IValidationCheckResultQuery query, IProgressMonitor pm) throws CoreException {
    IUndoableOperation undo = fOperationHistory.getUndoOperation(RefactoringCorePlugin.getUndoContext());
    UndoableOperation2ChangeAdapter changeOperation = getUnwrappedOperation(undo);
    if (changeOperation == null)
        throw new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), IStatus.ERROR, RefactoringCoreMessages.UndoManager2_no_change, null));
    if (query == null)
        query = new NullQuery();
    try {
        fOperationHistory.undoOperation(undo, pm, new QueryAdapter(query));
    } catch (ExecutionException e) {
        handleException(e);
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) CoreException(org.eclipse.core.runtime.CoreException) IUndoableOperation(org.eclipse.core.commands.operations.IUndoableOperation) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 30 with CoreException

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

the class UndoableOperation2ChangeAdapter method execute.

public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
    if (monitor == null)
        monitor = new NullProgressMonitor();
    try {
        ExecuteResult result = executeChange(getQuery(info, RefactoringCoreMessages.Refactoring_execute_label), monitor);
        if (!result.changeExecuted) {
            return createStatus(result);
        }
        fUndoChange = result.reverseChange;
        fActiveChange = fUndoChange;
        fExecuteChange = null;
        return Status.OK_STATUS;
    } catch (CoreException e) {
        throw new ExecutionException(e.getStatus().getMessage(), e);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ExecutionException(org.eclipse.core.commands.ExecutionException)

Aggregations

CoreException (org.eclipse.core.runtime.CoreException)569 IStatus (org.eclipse.core.runtime.IStatus)127 Status (org.eclipse.core.runtime.Status)124 IFile (org.eclipse.core.resources.IFile)119 IOException (java.io.IOException)96 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)93 IProject (org.eclipse.core.resources.IProject)90 IResource (org.eclipse.core.resources.IResource)84 ArrayList (java.util.ArrayList)71 InvocationTargetException (java.lang.reflect.InvocationTargetException)63 IPath (org.eclipse.core.runtime.IPath)63 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)60 File (java.io.File)56 IFolder (org.eclipse.core.resources.IFolder)45 InputStream (java.io.InputStream)42 IWorkspace (org.eclipse.core.resources.IWorkspace)40 PersistenceException (org.talend.commons.exception.PersistenceException)39 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)37 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)36 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)34