Search in sources :

Example 26 with SubProgressMonitor

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

the class RefactoringHistoryManager method removeIndexTree.

/**
	 * Removes the refactoring history index tree spanned by the specified file
	 * store.
	 *
	 * @param store
	 *            the file store spanning the history index tree
	 * @param monitor
	 *            the progress monitor to use
	 * @param task
	 *            the task label to use
	 * @throws CoreException
	 *             if an error occurs while removing the index tree
	 */
private static void removeIndexTree(final IFileStore store, final IProgressMonitor monitor, final String task) throws CoreException {
    try {
        monitor.beginTask(task, 16);
        final IFileInfo info = store.fetchInfo(EFS.NONE, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
        if (info.isDirectory()) {
            if (info.getName().equalsIgnoreCase(RefactoringHistoryService.NAME_HISTORY_FOLDER))
                return;
            final IFileStore[] stores = store.childStores(EFS.NONE, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
            final IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL);
            try {
                subMonitor.beginTask(RefactoringCoreMessages.RefactoringHistoryService_updating_history, stores.length);
                for (int index = 0; index < stores.length; index++) {
                    final IFileInfo current = stores[index].fetchInfo(EFS.NONE, new SubProgressMonitor(subMonitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
                    if (current.isDirectory()) {
                        final char[] characters = stores[index].getName().toCharArray();
                        for (int offset = 0; offset < characters.length; offset++) {
                            if (Character.isDigit(characters[offset]))
                                return;
                            else
                                continue;
                        }
                    }
                }
            } finally {
                subMonitor.done();
            }
        }
        final IFileStore parent = store.getParent();
        store.delete(0, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
        removeIndexTree(parent, new SubProgressMonitor(monitor, 12, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL), task);
    } finally {
        monitor.done();
    }
}
Also used : IFileInfo(org.eclipse.core.filesystem.IFileInfo) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFileStore(org.eclipse.core.filesystem.IFileStore) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 27 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 28 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 29 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 30 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)

Aggregations

SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)213 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)53 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)53 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)39 CoreException (org.eclipse.core.runtime.CoreException)38 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)29 IOException (java.io.IOException)23 IType (org.eclipse.jdt.core.IType)19 HashSet (java.util.HashSet)17 IProject (org.eclipse.core.resources.IProject)14 IResource (org.eclipse.core.resources.IResource)14 File (java.io.File)13 List (java.util.List)13 IPath (org.eclipse.core.runtime.IPath)13 IMethod (org.eclipse.jdt.core.IMethod)13 HashMap (java.util.HashMap)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)11