public void setSubTask(int template, String subtask[]) { if (m_monitor != null) { switch (template) { case STASK_SCANNING: if (subtask.length == 1) m_monitor.subTask(subtask[0]); break; case STASK_PREPARE: m_monitor.subTask("Preparing to transfer"); break; case STASK_TRANSFER: if (subtask.length == 5) { // need percentage // need time remaining // need data transfer rate String text = ""; text += subtask[0] + "\t" + subtask[1] + "\n"; text += subtask[2] + "\t" + subtask[3] + "\t" + subtask[4]; m_monitor.subTask(text); } else { m_monitor.subTask("Starting transfer...."); } break; } } }
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; } } }
private void initialize(final IRefreshSubscriberListener listener) { final GotoActionWrapper actionWrapper = new GotoActionWrapper(); IProgressMonitor group = Job.getJobManager().createProgressGroup(); group.beginTask(taskName, 100); setProgressGroup(group, 80); handleProgressGroupSet(group, 20); setProperty(IProgressConstants.ICON_PROPERTY, participant.getImageDescriptor()); setProperty(IProgressConstants.ACTION_PROPERTY, actionWrapper); setProperty(IProgressConstants.KEEPONE_PROPERTY, Boolean.valueOf(!isJobModal())); // Listener delegate IRefreshSubscriberListener autoListener = new IRefreshSubscriberListener() { @Override public void refreshStarted(IRefreshEvent event) { if (listener != null) { listener.refreshStarted(event); } } @Override public ActionFactory.IWorkbenchAction refreshDone(IRefreshEvent event) { if (listener != null) { boolean isModal = isJobModal(); event.setIsLink(!isModal); final ActionFactory.IWorkbenchAction runnable = listener.refreshDone(event); if (runnable != null) { // If the job is being run modally then simply prompt the user immediately if (isModal) { if (runnable != null) { Job update = new UIJob("") { // $NON-NLS-1$ @Override public IStatus runInUIThread(IProgressMonitor monitor) { runnable.run(); return Status.OK_STATUS; } }; update.setSystem(true); update.schedule(); } } else { // If the job is being run in the background, don't interrupt the user and simply // update the goto action // to perform the results. actionWrapper.setGotoAction(runnable); } } RefreshParticipantJob.removeRefreshListener(this); } return null; } }; if (listener != null) { RefreshParticipantJob.addRefreshListener(autoListener); } }
public String getPercentComplete() { double p = ((double) m_bytes / m_bytesTotal) * 100.0f; m_monitor.worked((int) ((p - m_percent) * 100)); m_percent = p; DecimalFormat df = new DecimalFormat("0.##"); return PaddedString.rpad((df.format(m_percent) + " % Complete"), 25); }
public void update(long bytes, long bytesTotal) { if (m_monitor.isCanceled()) { cancelTransfer(); } else { setTransferSpeed(bytes, bytesTotal); setSubTask( TASK_TRANSFER, new String[] { getNumberFiles(), getTransferSize(), getPercentComplete(), getTransferSpeed(), getTimeLeft() }); } }
/** * 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(); } }
protected IStatus TransferItems(String mode) { IStatus s = Status.OK_STATUS; // Grab the number of items to transfer m_fileCount = m_fileList.getNumItems(); // Now you have a list of files/folders and the server is opened, // set the local and remote directories if (setDirectories() == false) { setTask( TASK_ERROR, new String[] { m_errorPrefix + "Failed to change remote directory to the Site root, or failed to create it" }); return Status.CANCEL_STATUS; } // Start the monitor /* 10,000 means that you can track <1% updates * if you have completed 0.04% of the workload, eclipse * doesnt let you update by 0.04%, cause it's less than 1 * you can't update at all. So what I've done, is multiply each * unit by 100, which means 0.04 becomes 4, but therefore * to accomodate all 100% you have to also multiply that by 100 * so 100% complete becomes 10,000 units of work, each 1% of the * work becomes 100 units, so therefore you can track <1% updates * (IS THIS A SHIT EXPLANATION? tell me a better one) */ m_monitor.beginTask("Transferring files", 10000); // Set the monitor to show preparation step setSubTask(STASK_PREPARE, null); // Create a new sftp monitor createMonitor(); // grab the full number of bytes to transfer m_bytesTotal = m_fileList.getSize(); System.out.println("Number of bytes to transfer: " + m_bytesTotal); String item = null; for (m_count = 0; m_count < m_fileCount; m_count++) { // Pull an item from the list to transfer it item = m_fileList.getFile(m_count); // Set the task and subtask strings to show transfer information setTask(TASK_TRANSFER, new String[] {mode, item}); int i; // Build the necessary directories String dir = ""; while ((i = item.indexOf("/")) > 0) { // Get the directory to create (attempt to) dir += item.substring(0, i) + "/"; // Remove that directory from the item being created item = item.substring(i + 1); // Create either a local or remote directory if (m_fileList.getMode() == TransferDetails.GET) { createLocalDirectory(dir); } else { createRemoteDirectory(dir); } } // If the item is left with a trailing string, it'll be a file, create it if (!item.equals("/") && item.length() > 0) { try { transfer(dir, item); // if no exception, means we are ok m_fileList.setStatus(m_count, FileList.OK); } catch (Exception e) { // System.out.println("transfer exception: "+e.getMessage()+": cause: "+e.getCause()); // If exception, failed to put the file m_fileList.setStatus(m_count, FileList.FAILED); } } else { // If the item was a directory it will set a status whether it created // or not, however if we have no status information for this directory // something unknown happened, so set DUNKNOWN // say it, D unknown, Dee unknown, the unknown (get it?) if (m_fileList.getStatus(m_count).equals(FileList.NOSTATUS)) { m_fileList.setStatus(m_count, FileList.DUNKNOWN); } } // If the monitor is cancelled, you return // here, you don't want to continue if (m_monitor.isCanceled()) { m_fileList.setStatus(m_count, FileList.CANCEL); return Status.CANCEL_STATUS; } } return s; }