01: /*******************************************************************************
02: * Copyright (c) 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.ui.search.dependencies;
11:
12: import java.lang.reflect.InvocationTargetException;
13: import java.util.Map;
14:
15: import org.eclipse.core.resources.IProject;
16: import org.eclipse.core.resources.WorkspaceJob;
17: import org.eclipse.core.runtime.CoreException;
18: import org.eclipse.core.runtime.IProgressMonitor;
19: import org.eclipse.core.runtime.IStatus;
20: import org.eclipse.core.runtime.Status;
21: import org.eclipse.core.runtime.jobs.Job;
22: import org.eclipse.jface.action.Action;
23: import org.eclipse.pde.internal.core.ibundle.IBundlePluginModelBase;
24: import org.eclipse.pde.internal.ui.PDEPlugin;
25: import org.eclipse.pde.internal.ui.PDEPluginImages;
26: import org.eclipse.pde.internal.ui.PDEUIMessages;
27: import org.eclipse.swt.widgets.Display;
28: import org.eclipse.ui.progress.IProgressConstants;
29:
30: public class CalculateUsesAction extends Action {
31:
32: private IProject fProject;
33: private IBundlePluginModelBase fModel;
34:
35: public CalculateUsesAction(IProject project,
36: 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,
45: PDEPluginImages.DESC_PSEARCH_OBJ.createImage());
46: job.schedule();
47: }
48:
49: protected Job createJob() {
50: return new WorkspaceJob(
51: PDEUIMessages.CalculateUsesAction_jobName) {
52:
53: public IStatus runInWorkspace(IProgressMonitor monitor)
54: throws CoreException {
55: CalculateUsesOperation op = getOperation();
56: try {
57: op.run(monitor);
58: } catch (InvocationTargetException e) {
59: } catch (InterruptedException e) {
60: } finally {
61: monitor.done();
62: }
63: return new Status(IStatus.OK, PDEPlugin.getPluginId(),
64: IStatus.OK, "", null); //$NON-NLS-1$
65: }
66: };
67: }
68:
69: protected CalculateUsesOperation getOperation() {
70: return new CalculateUsesOperation(fProject, fModel) {
71:
72: protected void handleSetUsesDirectives(final Map pkgsAndUses) {
73: Display.getDefault().asyncExec(new Runnable() {
74: public void run() {
75: if (pkgsAndUses.isEmpty())
76: return;
77: setUsesDirectives(pkgsAndUses);
78: }
79: });
80: }
81:
82: };
83: }
84:
85: }
|