1 11 package org.eclipse.update.internal.ui.views; 12 13 import org.eclipse.core.runtime.IProgressMonitor; 14 import org.eclipse.core.runtime.IStatus; 15 import org.eclipse.core.runtime.ProgressMonitorWrapper; 16 import org.eclipse.core.runtime.jobs.Job; 17 import org.eclipse.jface.action.Action; 18 import org.eclipse.jface.dialogs.ErrorDialog; 19 import org.eclipse.jface.dialogs.MessageDialog; 20 import org.eclipse.osgi.util.NLS; 21 import org.eclipse.swt.widgets.Shell; 22 import org.eclipse.update.core.IFeature; 23 import org.eclipse.update.internal.ui.ConfigurationManagerWindow; 24 import org.eclipse.update.internal.ui.UpdateUIMessages; 25 import org.eclipse.update.internal.ui.wizards.InstallWizard; 26 import org.eclipse.update.internal.ui.wizards.InstallWizardOperation; 27 import org.eclipse.update.operations.OperationsManager; 28 import org.eclipse.update.ui.UpdateJob; 29 30 public class FindUpdatesAction extends Action { 31 32 private IFeature feature; 33 34 private ConfigurationManagerWindow window; 35 36 private class TrackingProgressMonitor extends ProgressMonitorWrapper { 37 private String name; 38 39 private String subname; 40 41 private int totalWork; 42 43 private double workSoFar; 44 45 protected TrackingProgressMonitor(IProgressMonitor monitor) { 46 super(monitor); 47 } 48 49 public void beginTask(String name, int totalWork) { 50 this.name = name; 51 this.totalWork = totalWork; 52 super.beginTask(name, totalWork); 53 updateStatus(); 54 } 55 56 public void internalWorked(double ticks) { 57 super.internalWorked(ticks); 58 workSoFar += ticks; 59 updateStatus(); 60 } 61 62 public void subTask(String subTask) { 63 subname = subTask; 64 super.subTask(subTask); 65 updateStatus(); 66 } 67 68 private void updateStatus() { 69 if (window.getShell()==null || window.getShell().isDisposed()) 70 return; 71 if (window.isProgressCanceled()) 72 setCanceled(true); 73 String perc = ((int) (workSoFar * 100.0) / totalWork) + ""; final String message = NLS.bind(UpdateUIMessages.FindUpdatesAction_trackedProgress, new String [] { 75 name, subname, perc }); 76 Shell shell = window.getShell(); 77 if (shell==null || shell.isDisposed()) return; 78 window.getShell().getDisplay().asyncExec(new Runnable () { 79 public void run() { 80 window.updateStatusLine(message, null); 81 } 82 }); 83 } 84 } 85 86 private class TrackedUpdateJob extends UpdateJob { 87 public TrackedUpdateJob(String name, boolean isAutomatic, 88 boolean download, IFeature[] features) { 89 super(name, isAutomatic, download, features); 90 } 91 92 public IStatus run(IProgressMonitor monitor) { 93 return super.run(new TrackingProgressMonitor(monitor)); 94 } 95 } 96 97 public FindUpdatesAction(ConfigurationManagerWindow window, String text) { 98 super(text); 99 this.window = window; 100 } 101 102 public void setFeature(IFeature feature) { 103 this.feature = feature; 104 } 105 106 public void run() { 107 108 IStatus status = OperationsManager.getValidator() 109 .validatePlatformConfigValid(); 110 if (status != null) { 111 ErrorDialog.openError(window.getShell(), null, null, status); 112 return; 113 } 114 115 if (OperationsManager.getValidator().validateCurrentState() != null 117 && !confirm(UpdateUIMessages.Actions_brokenConfigQuestion)) 118 return; 119 120 if (InstallWizard.isRunning()) { 121 MessageDialog.openInformation(window.getShell(), 122 UpdateUIMessages.InstallWizard_isRunningTitle, 123 UpdateUIMessages.InstallWizard_isRunningInfo); 124 return; 125 } 126 127 IFeature[] features = null; 128 if (feature != null) 129 features = new IFeature[] { feature }; 130 131 UpdateJob job = new TrackedUpdateJob( 132 UpdateUIMessages.InstallWizard_jobName, false, false, features); 133 134 job.setUser(true); 135 job.setPriority(Job.INTERACTIVE); 136 137 String name = feature!=null?feature.getLabel():UpdateUIMessages.FindUpdatesAction_allFeaturesSearch; 138 window.trackUpdateJob(job, name); 139 InstallWizardOperation operation = new InstallWizardOperation(); 140 141 operation.run(window.getShell(), job); 142 143 } 144 145 private boolean confirm(String message) { 146 return MessageDialog.openConfirm(window.getShell(), 147 UpdateUIMessages.FeatureStateAction_dialogTitle, message); 148 } 149 } 150 | Popular Tags |