01: /*
02: * uDig - User Friendly Desktop Internet GIS client http://udig.refractions.net (C) 2004, Refractions Research Inc. This
03: * library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
04: * License as published by the Free Software Foundation; version 2.1 of the License. This library is distributed in the
05: * hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
07: */
08: package net.refractions.udig.project.ui.internal.actions;
09:
10: import java.util.ArrayList;
11: import java.util.Collection;
12:
13: import net.refractions.udig.catalog.IGeoResource;
14: import net.refractions.udig.project.ui.ApplicationGIS;
15:
16: import org.eclipse.jface.action.IAction;
17: import org.eclipse.jface.viewers.ISelection;
18: import org.eclipse.jface.viewers.IStructuredSelection;
19: import org.eclipse.ui.IObjectActionDelegate;
20: import org.eclipse.ui.IWorkbenchPart;
21:
22: /**
23: * This class is a ActionDelegate for AbstractContext menus with RegistryEntry objects When the
24: * runWithEvent call is made (by eclipse) wizards should open and allow the use to add the selected
25: * items to the Currently selected map.
26: *
27: * @author Jesse Eichar
28: * @version $Revision: 1.9 $
29: */
30: public class AddToCurrentMap implements IObjectActionDelegate {
31: IStructuredSelection current;
32:
33: /**
34: * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
35: */
36: @SuppressWarnings("unchecked")
37: public void run(IAction action) {
38: Collection<IGeoResource> resources = AddToNewMap
39: .getResources(current.toList());
40: ApplicationGIS.addLayersToMap(ApplicationGIS.getActiveMap(),
41: new ArrayList<IGeoResource>(resources), -1);
42: }
43:
44: /**
45: * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction,
46: * org.eclipse.jface.viewers.ISelection)
47: */
48: public void selectionChanged(IAction action, ISelection selection) {
49: if (!selection.isEmpty()) {
50: if (selection instanceof IStructuredSelection) {
51: current = (IStructuredSelection) selection;
52: }
53: }
54: }
55:
56: /**
57: * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction,
58: * org.eclipse.ui.IWorkbenchPart)
59: */
60: public void setActivePart(IAction action, IWorkbenchPart targetPart) {
61: }
62:
63: }
|