KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 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.jface.dialogs.MessageDialog;
25 import org.eclipse.pde.internal.core.ibundle.IBundlePluginModelBase;
26 import org.eclipse.pde.internal.ui.PDEPlugin;
27 import org.eclipse.pde.internal.ui.PDEPluginImages;
28 import org.eclipse.pde.internal.ui.PDEUIMessages;
29 import org.eclipse.swt.widgets.Display;
30 import org.eclipse.ui.progress.IProgressConstants;
31
32 public class AddNewDependenciesAction extends Action {
33     
34     protected class AddDependenciesOperation extends AddNewDependenciesOperation {
35         public AddDependenciesOperation(IProject project, IBundlePluginModelBase base) {
36             super(project, base);
37         }
38         
39         protected void handleNewDependencies(final Map JavaDoc additionalDeps, final boolean useRequireBundle, IProgressMonitor monitor) {
40             if (!additionalDeps.isEmpty())
41                 Display.getDefault().asyncExec(new Runnable JavaDoc() {
42                     public void run() {
43                         addDependencies(additionalDeps, useRequireBundle);
44                     }
45                 });
46             monitor.done();
47         }
48     }
49     
50     private IProject fProject;
51     private IBundlePluginModelBase fBase;
52     
53     public AddNewDependenciesAction(IProject project, IBundlePluginModelBase base) {
54         fProject = project;
55         fBase = base;
56     }
57     
58     public void run() {
59         Job job = new WorkspaceJob(PDEUIMessages.DependencyManagementSection_jobName) {
60             
61             public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
62                 try {
63                     AddNewDependenciesOperation op = getOperation();
64                     op.run(monitor);
65                     if (!op.foundNewDependencies())
66                         Display.getDefault().asyncExec(new Runnable JavaDoc() {
67                             public void run() {
68                                 MessageDialog.openInformation(PDEPlugin.getActiveWorkbenchShell(),
69                                         PDEUIMessages.AddNewDependenciesAction_title,
70                                 PDEUIMessages.AddNewDependenciesAction_notFound);
71                             }
72                         });
73                 } catch (InvocationTargetException JavaDoc e) {
74                 } catch (InterruptedException JavaDoc e) {
75                 } finally {
76                     monitor.done();
77                 }
78                 return new Status(IStatus.OK, PDEPlugin.getPluginId(), IStatus.OK, "", null); //$NON-NLS-1$
79
}
80         };
81         job.setUser(true);
82         job.setProperty(IProgressConstants.ICON_PROPERTY, PDEPluginImages.DESC_PSEARCH_OBJ.createImage());
83         job.schedule();
84     }
85     
86     protected AddNewDependenciesOperation getOperation() {
87         return new AddDependenciesOperation(fProject, fBase);
88     }
89
90 }
91
Popular Tags