001: /*******************************************************************************
002: * Copyright (c) 2005, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.search.dependencies;
011:
012: import java.lang.reflect.InvocationTargetException;
013: import java.util.Map;
014:
015: import org.eclipse.core.resources.IProject;
016: import org.eclipse.core.resources.WorkspaceJob;
017: import org.eclipse.core.runtime.CoreException;
018: import org.eclipse.core.runtime.IProgressMonitor;
019: import org.eclipse.core.runtime.IStatus;
020: import org.eclipse.core.runtime.Status;
021: import org.eclipse.core.runtime.jobs.Job;
022: import org.eclipse.jface.action.Action;
023: import org.eclipse.jface.dialogs.MessageDialog;
024: import org.eclipse.pde.internal.core.ibundle.IBundlePluginModelBase;
025: import org.eclipse.pde.internal.ui.PDEPlugin;
026: import org.eclipse.pde.internal.ui.PDEPluginImages;
027: import org.eclipse.pde.internal.ui.PDEUIMessages;
028: import org.eclipse.swt.widgets.Display;
029: import org.eclipse.ui.progress.IProgressConstants;
030:
031: public class AddNewDependenciesAction extends Action {
032:
033: protected class AddDependenciesOperation extends
034: AddNewDependenciesOperation {
035: public AddDependenciesOperation(IProject project,
036: IBundlePluginModelBase base) {
037: super (project, base);
038: }
039:
040: protected void handleNewDependencies(final Map additionalDeps,
041: final boolean useRequireBundle, IProgressMonitor monitor) {
042: if (!additionalDeps.isEmpty())
043: Display.getDefault().asyncExec(new Runnable() {
044: public void run() {
045: addDependencies(additionalDeps,
046: useRequireBundle);
047: }
048: });
049: monitor.done();
050: }
051: }
052:
053: private IProject fProject;
054: private IBundlePluginModelBase fBase;
055:
056: public AddNewDependenciesAction(IProject project,
057: IBundlePluginModelBase base) {
058: fProject = project;
059: fBase = base;
060: }
061:
062: public void run() {
063: Job job = new WorkspaceJob(
064: PDEUIMessages.DependencyManagementSection_jobName) {
065:
066: public IStatus runInWorkspace(IProgressMonitor monitor)
067: throws CoreException {
068: try {
069: AddNewDependenciesOperation op = getOperation();
070: op.run(monitor);
071: if (!op.foundNewDependencies())
072: Display.getDefault().asyncExec(new Runnable() {
073: public void run() {
074: MessageDialog
075: .openInformation(
076: PDEPlugin
077: .getActiveWorkbenchShell(),
078: PDEUIMessages.AddNewDependenciesAction_title,
079: PDEUIMessages.AddNewDependenciesAction_notFound);
080: }
081: });
082: } catch (InvocationTargetException e) {
083: } catch (InterruptedException e) {
084: } finally {
085: monitor.done();
086: }
087: return new Status(IStatus.OK, PDEPlugin.getPluginId(),
088: IStatus.OK, "", null); //$NON-NLS-1$
089: }
090: };
091: job.setUser(true);
092: job.setProperty(IProgressConstants.ICON_PROPERTY,
093: PDEPluginImages.DESC_PSEARCH_OBJ.createImage());
094: job.schedule();
095: }
096:
097: protected AddNewDependenciesOperation getOperation() {
098: return new AddDependenciesOperation(fProject, fBase);
099: }
100:
101: }
|