Search in sources :

Example 86 with SubProgressMonitor

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

the class RefactoringHistoryManager method writeIndexEntry.

/**
	 * Writes the specified index entry to the refactoring history.
	 *
	 * @param file
	 *            the history index file
	 * @param proxies
	 *            the refactoring descriptors
	 * @param flags
	 *            the flags to use (either {@link EFS#NONE} or
	 *            {@link EFS#APPEND})
	 * @param monitor
	 *            the progress monitor to use
	 * @param task
	 *            the task label
	 * @throws CoreException
	 *             if an error occurs while writing the index entry
	 * @throws IOException
	 *             if an input/output error occurs
	 */
private static void writeIndexEntry(final IFileStore file, final RefactoringDescriptorProxy[] proxies, final int flags, final IProgressMonitor monitor, final String task) throws CoreException, IOException {
    OutputStream output = null;
    try {
        monitor.beginTask(task, 2);
        file.getParent().mkdir(EFS.NONE, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
        output = new BufferedOutputStream(file.openOutputStream(flags, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)));
        writeRefactoringDescriptorProxies(output, proxies);
    } finally {
        monitor.done();
        if (output != null) {
            try {
                output.close();
            } catch (IOException exception) {
            // Do nothing
            }
        }
    }
}
Also used : BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 87 with SubProgressMonitor

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

the class RefactoringHistoryManager method readRefactoringHistory.

/**
	 * Reads the refactoring history from disk.
	 *
	 * @param start
	 *            the start time stamp, inclusive
	 * @param end
	 *            the end time stamp, inclusive
	 * @param monitor
	 *            the progress monitor to use
	 * @return the refactoring history
	 */
RefactoringHistory readRefactoringHistory(final long start, final long end, final IProgressMonitor monitor) {
    try {
        monitor.beginTask(RefactoringCoreMessages.RefactoringHistoryService_retrieving_history, 200);
        final Set set = new HashSet();
        try {
            if (fHistoryStore.fetchInfo(EFS.NONE, new SubProgressMonitor(monitor, 20, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)).exists())
                readRefactoringDescriptorProxies(fHistoryStore, fProjectName, set, start, end, new SubProgressMonitor(monitor, 80), RefactoringCoreMessages.RefactoringHistoryService_retrieving_history);
            final IFileStore store = EFS.getLocalFileSystem().getStore(RefactoringCorePlugin.getDefault().getStateLocation()).getChild(RefactoringHistoryService.NAME_HISTORY_FOLDER).getChild(RefactoringHistoryService.NAME_WORKSPACE_PROJECT);
            if (store.fetchInfo(EFS.NONE, new SubProgressMonitor(monitor, 20, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)).exists())
                readRefactoringDescriptorProxies(store, null, set, start, end, new SubProgressMonitor(monitor, 80), RefactoringCoreMessages.RefactoringHistoryService_retrieving_history);
        } catch (CoreException exception) {
            RefactoringCorePlugin.log(exception);
        }
        final RefactoringDescriptorProxy[] proxies = new RefactoringDescriptorProxy[set.size()];
        set.toArray(proxies);
        return new RefactoringHistoryImplementation(proxies);
    } finally {
        monitor.done();
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) CoreException(org.eclipse.core.runtime.CoreException) RefactoringDescriptorProxy(org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy) IFileStore(org.eclipse.core.filesystem.IFileStore) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) HashSet(java.util.HashSet)

Example 88 with SubProgressMonitor

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

the class MoveResourceChange method performSourceRestore.

private void performSourceRestore(IProgressMonitor monitor) throws CoreException {
    monitor.beginTask(RefactoringCoreMessages.MoveResourceChange_progress_restore_source, 3);
    try {
        fRestoreSourceChange.initializeValidationData(new SubProgressMonitor(monitor, 1));
        RefactoringStatus restoreStatus = fRestoreSourceChange.isValid(new SubProgressMonitor(monitor, 1));
        if (!restoreStatus.hasFatalError()) {
            fRestoreSourceChange.perform(new SubProgressMonitor(monitor, 1));
        }
    } finally {
        monitor.done();
    }
}
Also used : RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 89 with SubProgressMonitor

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

the class MoveResourceChange method perform.

/* (non-Javadoc)
	 * @see org.eclipse.ltk.core.refactoring.Change#perform(org.eclipse.core.runtime.IProgressMonitor)
	 */
public final Change perform(IProgressMonitor monitor) throws CoreException, OperationCanceledException {
    try {
        if (monitor == null)
            monitor = new NullProgressMonitor();
        monitor.beginTask(getName(), 4);
        Change deleteUndo = null;
        // delete destination if required
        IResource resourceAtDestination = fTarget.findMember(fSource.getName());
        if (resourceAtDestination != null && resourceAtDestination.exists()) {
            deleteUndo = performDestinationDelete(resourceAtDestination, new SubProgressMonitor(monitor, 1));
        } else {
            monitor.worked(1);
        }
        // move resource
        long currentStamp = fSource.getModificationStamp();
        IPath destinationPath = fTarget.getFullPath().append(fSource.getName());
        fSource.move(destinationPath, IResource.KEEP_HISTORY | IResource.SHALLOW, new SubProgressMonitor(monitor, 2));
        resourceAtDestination = ResourcesPlugin.getWorkspace().getRoot().findMember(destinationPath);
        // restore timestamp at destination
        if (fStampToRestore != IResource.NULL_STAMP) {
            resourceAtDestination.revertModificationStamp(fStampToRestore);
        }
        // restore file at source
        if (fRestoreSourceChange != null) {
            performSourceRestore(new SubProgressMonitor(monitor, 1));
        } else {
            monitor.worked(1);
        }
        return new MoveResourceChange(resourceAtDestination, fSource.getParent(), currentStamp, deleteUndo);
    } finally {
        monitor.done();
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPath(org.eclipse.core.runtime.IPath) Change(org.eclipse.ltk.core.refactoring.Change) IResource(org.eclipse.core.resources.IResource) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 90 with SubProgressMonitor

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

the class MultiStateUndoChange method perform.

/**
	 * {@inheritDoc}
	 */
public Change perform(IProgressMonitor pm) throws CoreException {
    if (fValidationState == null || fValidationState.isValid(needsSaving(), false).hasFatalError())
        return new NullChange();
    if (pm == null)
        pm = new NullProgressMonitor();
    ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
    //$NON-NLS-1$
    pm.beginTask("", 2);
    ITextFileBuffer buffer = null;
    try {
        manager.connect(fFile.getFullPath(), LocationKind.IFILE, new SubProgressMonitor(pm, 1));
        buffer = manager.getTextFileBuffer(fFile.getFullPath(), LocationKind.IFILE);
        IDocument document = buffer.getDocument();
        ContentStamp currentStamp = ContentStamps.get(fFile, document);
        // perform the changes
        LinkedList list = new LinkedList();
        for (int index = 0; index < fUndos.length; index++) {
            UndoEdit edit = fUndos[index];
            UndoEdit redo = edit.apply(document, TextEdit.CREATE_UNDO);
            list.addFirst(redo);
        }
        // try to restore the document content stamp
        boolean success = ContentStamps.set(document, fContentStampToRestore);
        if (needsSaving()) {
            buffer.commit(pm, false);
            if (!success) {
                // We weren't able to restore document stamp.
                // Since we save restore the file stamp instead
                ContentStamps.set(fFile, fContentStampToRestore);
            }
        }
        return createUndoChange((UndoEdit[]) list.toArray(new UndoEdit[list.size()]), currentStamp);
    } catch (BadLocationException e) {
        throw Changes.asCoreException(e);
    } finally {
        if (buffer != null)
            manager.disconnect(fFile.getFullPath(), LocationKind.IFILE, new SubProgressMonitor(pm, 1));
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) NullChange(org.eclipse.ltk.core.refactoring.NullChange) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) ContentStamp(org.eclipse.ltk.core.refactoring.ContentStamp) UndoEdit(org.eclipse.text.edits.UndoEdit) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IDocument(org.eclipse.jface.text.IDocument) LinkedList(java.util.LinkedList) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)217 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)54 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)53 CoreException (org.eclipse.core.runtime.CoreException)40 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)39 ArrayList (java.util.ArrayList)36 IFile (org.eclipse.core.resources.IFile)33 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)31 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)30 IOException (java.io.IOException)23 IType (org.eclipse.jdt.core.IType)19 HashSet (java.util.HashSet)17 IPath (org.eclipse.core.runtime.IPath)17 IResource (org.eclipse.core.resources.IResource)16 IProject (org.eclipse.core.resources.IProject)15 File (java.io.File)14 List (java.util.List)13 IMethod (org.eclipse.jdt.core.IMethod)13 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 HashMap (java.util.HashMap)12