KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > search > dependencies > CalculateUsesAction


1 /*******************************************************************************
2  * Copyright (c) 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.search.dependencies;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
14 import java.util.Map JavaDoc;
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 JavaDoc e) {
56                 } catch (InterruptedException JavaDoc e) {
57                 } finally {
58                     monitor.done();
59                 }
60                 return new Status(IStatus.OK, PDEPlugin.getPluginId(), IStatus.OK, "", null); //$NON-NLS-1$
61
}
62         };
63     }
64     
65     protected CalculateUsesOperation getOperation() {
66         return new CalculateUsesOperation(fProject, fModel) {
67
68             protected void handleSetUsesDirectives(final Map JavaDoc pkgsAndUses) {
69                 Display.getDefault().asyncExec(new Runnable JavaDoc() {
70                     public void run() {
71                         if (pkgsAndUses.isEmpty())
72                             return;
73                         setUsesDirectives(pkgsAndUses);
74                     }
75                 });
76             }
77             
78         };
79     }
80
81 }
82
Popular Tags