1 11 package org.eclipse.pde.internal.ui.search.dependencies; 12 13 import java.lang.reflect.InvocationTargetException ; 14 import java.util.Map ; 15 16 import org.eclipse.core.resources.IProject; 17 import org.eclipse.core.resources.WorkspaceJob; 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.core.runtime.IProgressMonitor; 20 import org.eclipse.core.runtime.IStatus; 21 import org.eclipse.core.runtime.Status; 22 import org.eclipse.core.runtime.jobs.Job; 23 import org.eclipse.jface.action.Action; 24 import org.eclipse.pde.internal.core.ibundle.IBundlePluginModelBase; 25 import org.eclipse.pde.internal.ui.PDEPlugin; 26 import org.eclipse.pde.internal.ui.PDEPluginImages; 27 import org.eclipse.pde.internal.ui.PDEUIMessages; 28 import org.eclipse.swt.widgets.Display; 29 import org.eclipse.ui.progress.IProgressConstants; 30 31 public class CalculateUsesAction extends Action { 32 33 private IProject fProject; 34 private IBundlePluginModelBase fModel; 35 36 public CalculateUsesAction(IProject project, IBundlePluginModelBase model) { 37 fProject = project; 38 fModel = model; 39 } 40 41 public void run() { 42 Job job = createJob(); 43 job.setUser(true); 44 job.setProperty(IProgressConstants.ICON_PROPERTY, PDEPluginImages.DESC_PSEARCH_OBJ.createImage()); 45 job.schedule(); 46 } 47 48 protected Job createJob() { 49 return new WorkspaceJob(PDEUIMessages.CalculateUsesAction_jobName) { 50 51 public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { 52 CalculateUsesOperation op = getOperation(); 53 try { 54 op.run(monitor); 55 } catch (InvocationTargetException e) { 56 } catch (InterruptedException e) { 57 } finally { 58 monitor.done(); 59 } 60 return new Status(IStatus.OK, PDEPlugin.getPluginId(), IStatus.OK, "", null); } 62 }; 63 } 64 65 protected CalculateUsesOperation getOperation() { 66 return new CalculateUsesOperation(fProject, fModel) { 67 68 protected void handleSetUsesDirectives(final Map pkgsAndUses) { 69 Display.getDefault().asyncExec(new Runnable () { 70 public void run() { 71 if (pkgsAndUses.isEmpty()) 72 return; 73 setUsesDirectives(pkgsAndUses); 74 } 75 }); 76 } 77 78 }; 79 } 80 81 } 82 | Popular Tags |