public void setTask(int template, String task[]) { if (m_monitor != null) { switch (template) { case TASK_CONNECT: m_monitor.setTaskName("Connecting to SFTP Site"); break; case TASK_SCANNING: m_monitor.setTaskName("Scanning directories"); break; case TASK_TRANSFER: if (task.length == 2) { m_monitor.setTaskName(task[0] + ":\t" + task[1]); } break; case TASK_COMPLETE: m_monitor.setTaskName("Transfer completed"); break; case TASK_ERROR: if (task.length >= 1) { m_monitor.setTaskName("ERROR: " + task[0]); for (int a = 0; a < task.length; a++) { m_output.append(task[a] + "\n"); System.out.println(task[a]); } } break; } } }
protected IResource[] checkOverwriteOfDirtyResources( IResource[] resources, IProgressMonitor monitor) throws CVSException, InterruptedException { List dirtyResources = new ArrayList(); IResource[] selectedResources = getSelectedResources(); try { monitor = Policy.monitorFor(monitor); monitor.beginTask(null, selectedResources.length * 100); monitor.setTaskName(CVSUIMessages.ReplaceWithAction_calculatingDirtyResources); for (int i = 0; i < selectedResources.length; i++) { IResource resource = selectedResources[i]; ICVSResource cvsResource = getCVSResourceFor(resource); if (cvsResource.isModified(Policy.subMonitorFor(monitor, 100))) { dirtyResources.add(resource); } } } finally { monitor.done(); } PromptingDialog dialog = new PromptingDialog( getShell(), selectedResources, getPromptCondition( (IResource[]) dirtyResources.toArray(new IResource[dirtyResources.size()])), CVSUIMessages.ReplaceWithAction_confirmOverwrite); return dialog.promptForMultiple(); }
/** * Set task name. * * @see IProgressMonitor#setTaskName(String) * @since 2.0 */ public void setTaskName(String name) { this.taskString = name; this.subTaskString = ""; // $NON-NLS-1$ this.showDetails = false; this.totalCopyCount = 0; monitor.subTask(""); // $NON-NLS-1$ monitor.setTaskName(name); }
/** * The worker method. It will find the container, create the file if missing or just replace its * contents, and open the editor on the newly created file. */ private void doFinish(String containerName, String fileName, IProgressMonitor monitor) throws CoreException { // create a sample file monitor.beginTask("Creating " + fileName, 2); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IResource resource = root.findMember(new Path(containerName)); if (!resource.exists() || !(resource instanceof IContainer)) { throwCoreException("Container \"" + containerName + "\" does not exist."); } IContainer container = (IContainer) resource; final IFile file = container.getFile(new Path(fileName)); try { InputStream stream = openContentStream(); if (file.exists()) { file.setContents(stream, true, true, monitor); } else { file.create(stream, true, monitor); } stream.close(); } catch (IOException e) { } monitor.worked(1); monitor.setTaskName("Opening file for editing..."); getShell() .getDisplay() .asyncExec( new Runnable() { public void run() { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); try { IDE.openEditor(page, file, true); } catch (PartInitException e) { } } }); monitor.worked(1); }
/** * This is run by the job scheduler. A list of subscribers will be refreshed, errors will not stop * the job and it will continue to refresh the other subscribers. */ @Override public IStatus run(IProgressMonitor monitor) { // Perform a pre-check for auto-build or manual build jobs // when auto-refreshing if (shouldReschedule() && (isJobInFamilyRunning(ResourcesPlugin.FAMILY_AUTO_BUILD) || isJobInFamilyRunning(ResourcesPlugin.FAMILY_MANUAL_BUILD))) { return POSTPONED; } // Only allow one refresh job at a time // NOTE: It would be cleaner if this was done by a scheduling // rule but at the time of writing, it is not possible due to // the scheduling rule containment rules. // Acquiring lock to ensure only one refresh job is running at a particular time boolean acquired = false; try { while (!acquired) { try { acquired = lock.acquire(1000); } catch (InterruptedException e1) { acquired = false; } Policy.checkCanceled(monitor); } IChangeDescription changeDescription = createChangeDescription(); RefreshEvent event = new RefreshEvent( reschedule ? IRefreshEvent.SCHEDULED_REFRESH : IRefreshEvent.USER_REFRESH, participant, changeDescription); IStatus status = null; NonblockingProgressMonitor wrappedMonitor = null; try { event.setStartTime(System.currentTimeMillis()); if (monitor.isCanceled()) { return Status.CANCEL_STATUS; } // Pre-Notify notifyListeners(STARTED, event); // Perform the refresh monitor.setTaskName(getName()); wrappedMonitor = new NonblockingProgressMonitor(monitor, this); doRefresh(changeDescription, wrappedMonitor); // Prepare the results setProperty(IProgressConstants.KEEPONE_PROPERTY, Boolean.valueOf(!isJobModal())); } catch (OperationCanceledException e2) { if (monitor.isCanceled()) { // The refresh was canceled by the user status = Status.CANCEL_STATUS; } else { // The refresh was canceled due to a blockage or a canceled authentication if (wrappedMonitor != null && wrappedMonitor.wasBlocking()) { status = POSTPONED; } else { status = Status.CANCEL_STATUS; } } } catch (CoreException e) { // Determine the status to be returned and the GOTO action status = e.getStatus(); if (!isUser()) { // Use the GOTO action to show the error and return OK Object prop = getProperty(IProgressConstants.ACTION_PROPERTY); if (prop instanceof GotoActionWrapper) { GotoActionWrapper wrapper = (GotoActionWrapper) prop; wrapper.setStatus(e.getStatus()); status = new Status(IStatus.OK, TeamUIPlugin.ID, IStatus.OK, e.getStatus().getMessage(), e); } } if (!isUser() && status.getSeverity() == IStatus.ERROR) { // Never prompt for errors on non-user jobs setProperty(IProgressConstants.NO_IMMEDIATE_ERROR_PROMPT_PROPERTY, Boolean.TRUE); } } finally { event.setStopTime(System.currentTimeMillis()); } // Post-Notify if (status == null) { status = calculateStatus(event); } event.setStatus(status); notifyListeners(DONE, event); if (event.getChangeDescription().getChangeCount() > 0) { if (participant instanceof AbstractSynchronizeParticipant) { AbstractSynchronizeParticipant asp = (AbstractSynchronizeParticipant) participant; asp.firePropertyChange( participant, ISynchronizeParticipant.P_CONTENT, null, event.getChangeDescription()); } } return event.getStatus(); } finally { if (acquired) lock.release(); monitor.done(); } }