Source Code Cross Referenced for ToolManager.java in  » GIS » udig-1.1 » net » refractions » udig » project » ui » internal » tool » display » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » GIS » udig 1.1 » net.refractions.udig.project.ui.internal.tool.display 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * uDig - User Friendly Desktop Internet GIS client http://udig.refractions.net (C) 2004,
0003:         * Refractions Research Inc. This library is free software; you can redistribute it and/or modify it
0004:         * under the terms of the GNU Lesser General Public License as published by the Free Software
0005:         * Foundation; version 2.1 of the License. This library is distributed in the hope that it will be
0006:         * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
0007:         * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
0008:         */
0009:        package net.refractions.udig.project.ui.internal.tool.display;
0010:
0011:        import java.io.Serializable;
0012:        import java.util.ArrayList;
0013:        import java.util.Collection;
0014:        import java.util.Collections;
0015:        import java.util.Comparator;
0016:        import java.util.HashMap;
0017:        import java.util.HashSet;
0018:        import java.util.Iterator;
0019:        import java.util.LinkedList;
0020:        import java.util.List;
0021:        import java.util.Set;
0022:        import java.util.concurrent.locks.Lock;
0023:        import java.util.concurrent.locks.ReentrantLock;
0024:
0025:        import net.refractions.udig.core.internal.ExtensionPointList;
0026:        import net.refractions.udig.internal.ui.FilterTextTransfer;
0027:        import net.refractions.udig.internal.ui.UDIGDNDProcessor;
0028:        import net.refractions.udig.internal.ui.UDIGDropHandler;
0029:        import net.refractions.udig.internal.ui.UDigByteAndLocalTransfer;
0030:        import net.refractions.udig.internal.ui.UiPlugin;
0031:        import net.refractions.udig.internal.ui.operations.OperationCategory;
0032:        import net.refractions.udig.internal.ui.operations.OperationMenuFactory;
0033:        import net.refractions.udig.internal.ui.operations.RunOperationsAction;
0034:        import net.refractions.udig.project.EditManagerEvent;
0035:        import net.refractions.udig.project.IEditManagerListener;
0036:        import net.refractions.udig.project.ILayer;
0037:        import net.refractions.udig.project.IMap;
0038:        import net.refractions.udig.project.internal.Map;
0039:        import net.refractions.udig.project.internal.ProjectPackage;
0040:        import net.refractions.udig.project.ui.ApplicationGIS;
0041:        import net.refractions.udig.project.ui.internal.AdaptingFilter;
0042:        import net.refractions.udig.project.ui.internal.ApplicationGISInternal;
0043:        import net.refractions.udig.project.ui.internal.MapEditor;
0044:        import net.refractions.udig.project.ui.internal.Messages;
0045:        import net.refractions.udig.project.ui.internal.ProjectUIPlugin;
0046:        import net.refractions.udig.project.ui.internal.actions.Delete;
0047:        import net.refractions.udig.project.ui.internal.tool.ToolContext;
0048:        import net.refractions.udig.project.ui.internal.tool.impl.ToolContextImpl;
0049:        import net.refractions.udig.project.ui.tool.IContextMenuContributionTool;
0050:        import net.refractions.udig.project.ui.tool.IToolManager;
0051:        import net.refractions.udig.project.ui.tool.Tool;
0052:        import net.refractions.udig.project.ui.tool.ToolConstants;
0053:        import net.refractions.udig.ui.UDIGDragDropUtilities;
0054:        import net.refractions.udig.ui.ViewerDropLocation;
0055:        import net.refractions.udig.ui.operations.LazyOpFilter;
0056:        import net.refractions.udig.ui.operations.OpAction;
0057:        import net.refractions.udig.ui.operations.OpFilter;
0058:
0059:        import org.eclipse.core.commands.Command;
0060:        import org.eclipse.core.runtime.IConfigurationElement;
0061:        import org.eclipse.core.runtime.IExtension;
0062:        import org.eclipse.emf.common.notify.Adapter;
0063:        import org.eclipse.emf.common.notify.Notification;
0064:        import org.eclipse.emf.common.notify.impl.AdapterImpl;
0065:        import org.eclipse.jface.action.Action;
0066:        import org.eclipse.jface.action.GroupMarker;
0067:        import org.eclipse.jface.action.IAction;
0068:        import org.eclipse.jface.action.IContributionItem;
0069:        import org.eclipse.jface.action.IMenuCreator;
0070:        import org.eclipse.jface.action.IMenuManager;
0071:        import org.eclipse.jface.action.IToolBarManager;
0072:        import org.eclipse.jface.action.MenuManager;
0073:        import org.eclipse.jface.action.Separator;
0074:        import org.eclipse.jface.action.SubCoolBarManager;
0075:        import org.eclipse.jface.action.ToolBarManager;
0076:        import org.eclipse.jface.resource.ImageDescriptor;
0077:        import org.eclipse.jface.util.IPropertyChangeListener;
0078:        import org.eclipse.jface.util.PropertyChangeEvent;
0079:        import org.eclipse.jface.viewers.ISelection;
0080:        import org.eclipse.jface.viewers.IStructuredSelection;
0081:        import org.eclipse.swt.SWT;
0082:        import org.eclipse.swt.dnd.Clipboard;
0083:        import org.eclipse.swt.dnd.Transfer;
0084:        import org.eclipse.swt.events.HelpListener;
0085:        import org.eclipse.swt.graphics.Cursor;
0086:        import org.eclipse.swt.widgets.Event;
0087:        import org.eclipse.ui.IActionBars;
0088:        import org.eclipse.ui.IKeyBindingService;
0089:        import org.eclipse.ui.ISharedImages;
0090:        import org.eclipse.ui.IWorkbenchActionConstants;
0091:        import org.eclipse.ui.IWorkbenchPart;
0092:        import org.eclipse.ui.IWorkbenchPartSite;
0093:        import org.eclipse.ui.IWorkbenchWindow;
0094:        import org.eclipse.ui.PlatformUI;
0095:        import org.eclipse.ui.SubActionBars2;
0096:        import org.eclipse.ui.actions.ActionFactory;
0097:        import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
0098:        import org.eclipse.ui.commands.ICommandService;
0099:        import org.geotools.filter.Filter;
0100:
0101:        /**
0102:         * Manages Edit tools activation and registration.
0103:         * 
0104:         * @author jeichar
0105:         * @since 0.6.0
0106:         */
0107:        public class ToolManager implements  IToolManager {
0108:
0109:            /**
0110:             * This is a list of all tool actions(buttons) that are not part of the editor toolbar. For
0111:             * example the info view may have a tool as part of its toolbar which is a proxy for the real
0112:             * tool on the editor view.
0113:             */
0114:            Set<IAction> registeredToolActions = new HashSet<IAction>();
0115:
0116:            protected List<String> categoryIds = new ArrayList<String>();
0117:
0118:            List<ModalToolCategory> modalCategories = new LinkedList<ModalToolCategory>();
0119:            List<ActionToolCategory> actionCategories = new LinkedList<ActionToolCategory>();
0120:            List<MenuToolCategory> menuCategories = new LinkedList<MenuToolCategory>();
0121:            List<ToolProxy> backgroundTools = new LinkedList<ToolProxy>();
0122:            ISharedImages sharedImages = PlatformUI.getWorkbench()
0123:                    .getSharedImages();
0124:
0125:            /**
0126:             * Cache of all configured cursors.
0127:             */
0128:            protected java.util.Map<String, CursorProxy> cursorsCache = new HashMap<String, CursorProxy>();
0129:
0130:            /**
0131:             * Current active tool.
0132:             */
0133:            protected ToolProxy activeModalToolProxy;
0134:
0135:            /**
0136:             * Default modal tool. This tool is set during
0137:             * initialization of tools by ToolProxy.DEFAULT_ID.
0138:             */
0139:            ToolProxy defaultModalToolProxy;
0140:
0141:            Lock redoLock = new ReentrantLock();
0142:            Lock undoLock = new ReentrantLock();
0143:            Lock forwardLock = new ReentrantLock();
0144:            Lock backwardLock = new ReentrantLock();
0145:            Lock deleteLock = new ReentrantLock();
0146:            Lock pasteLock = new ReentrantLock();
0147:            Lock copyLock = new ReentrantLock();
0148:            Lock cutLock = new ReentrantLock();
0149:
0150:            private volatile IAction redoAction;
0151:            private volatile IAction undoAction;
0152:            private volatile IAction forwardAction;
0153:            private volatile IAction backwardAction;
0154:            private volatile IAction deleteAction;
0155:            private volatile IAction pasteAction;
0156:            private volatile IAction copyAction;
0157:            private volatile IAction cutAction;
0158:
0159:            private AdapterImpl commandListener;
0160:
0161:            /**
0162:             * Construct <code>ToolManager</code>.
0163:             */
0164:            public ToolManager() {
0165:
0166:                //    	instance = this;
0167:
0168:                processCategories();
0169:                processTools();
0170:                removeEmptyCategories();
0171:                Collections.sort(categoryIds, new CategorySorter());
0172:                setCommandHandlers();
0173:
0174:            }
0175:
0176:            //    protected ToolManager getInstance(){
0177:            //    	return instance;
0178:            //    }
0179:
0180:            /**
0181:             * Populates the categories with their associated tools
0182:             */
0183:            private void processTools() {
0184:                List<IConfigurationElement> extensionList = ExtensionPointList
0185:                        .getExtensionPointList(Tool.EXTENSION_ID);
0186:                for (IConfigurationElement element : extensionList) {
0187:                    IExtension extension = element.getDeclaringExtension();
0188:                    String type = element.getName();
0189:
0190:                    if (type.equals("backgroundTool")) { //$NON-NLS-1$
0191:
0192:                        ToolProxy proxy = new ToolProxy(extension, element,
0193:                                this );
0194:                        backgroundTools.add(proxy);
0195:                    } else if (type.equals("modalTool")) { //$NON-NLS-1$
0196:                        String categoryId = element.getAttribute("categoryId"); //$NON-NLS-1$
0197:                        ToolProxy proxy = new ToolProxy(extension, element,
0198:                                this );
0199:
0200:                        addToModalCategory(categoryId, proxy);
0201:                    } else if (type.equals("actionTool")) { //$NON-NLS-1$
0202:                        String categoryId = element.getAttribute("categoryId"); //$NON-NLS-1$
0203:                        ToolProxy proxy = new ToolProxy(extension, element,
0204:                                this );
0205:
0206:                        addToActionCategory(categoryId, proxy);
0207:                        addToMenuCategory(categoryId, proxy);
0208:                    } else if (type.equals("toolCursor")) { //$NON-NLS-1$
0209:                        CursorProxy cursorProxy = new CursorProxy(element);
0210:                        cursorsCache.put(cursorProxy.getID(), cursorProxy);
0211:                    }
0212:                }
0213:
0214:                if (activeModalToolProxy == null)
0215:                    activeModalToolProxy = defaultModalToolProxy;
0216:            }
0217:
0218:            /**
0219:             * Finds cursor proxy by ID in cache.
0220:             */
0221:            public Cursor findToolCursor(String cursorID) {
0222:
0223:                CursorProxy cursorProxy = cursorsCache.get(cursorID);
0224:                if (cursorProxy != null)
0225:                    return cursorProxy.getCursor();
0226:
0227:                Cursor systemCursor = CursorProxy.getSystemCursor(cursorID);
0228:                if (systemCursor != null)
0229:                    return systemCursor;
0230:
0231:                return null;
0232:
0233:            }
0234:
0235:            /**
0236:             * 
0237:             * In the current implementation finds only among modal tools.
0238:             * 
0239:             * TODO Add necessary functionality
0240:             */
0241:            public Tool findTool(String toolID) {
0242:                for (ModalToolCategory category : modalCategories) {
0243:                    for (ModalItem item : category) {
0244:                        if (toolID.equals(item.getId())) {
0245:                            return ((ToolProxy) item).getTool();
0246:                        }
0247:                    }
0248:                }
0249:                return null;
0250:            }
0251:
0252:            private void addToModalCategory(String categoryId, ToolProxy proxy) {
0253:                ModalToolCategory modalCategory = findModalCategory(categoryId);
0254:                if (modalCategory == null) {
0255:                    modalCategory = findModalCategory(Messages.ToolCategory_other);
0256:                    if (modalCategory == null) {
0257:                        modalCategory = new ModalToolCategory(this );
0258:                        modalCategories.add(modalCategory);
0259:                        if (!categoryIds.contains(Messages.ToolCategory_other))
0260:                            categoryIds.add(Messages.ToolCategory_other);
0261:                    }
0262:                }
0263:                modalCategory.add(proxy);
0264:            }
0265:
0266:            private void addToMenuCategory(String categoryId, ToolProxy proxy) {
0267:                MenuToolCategory category = findMenuCategory(categoryId);
0268:                if (category == null) {
0269:                    category = findMenuCategory(Messages.ToolCategory_other);
0270:
0271:                    if (category == null) {
0272:                        category = new MenuToolCategory(this );
0273:                        menuCategories.add(category);
0274:                        if (!categoryIds.contains(Messages.ToolCategory_other))
0275:                            categoryIds.add(Messages.ToolCategory_other);
0276:                    }
0277:                }
0278:                category.add(proxy);
0279:            }
0280:
0281:            private void addToActionCategory(String categoryId, ToolProxy proxy) {
0282:                ActionToolCategory category = findActionCategory(categoryId);
0283:                if (category == null) {
0284:                    category = findActionCategory(Messages.ToolCategory_other);
0285:
0286:                    if (category == null) {
0287:                        category = new ActionToolCategory(this );
0288:                        actionCategories.add(category);
0289:                        if (!categoryIds.contains(Messages.ToolCategory_other))
0290:                            categoryIds.add(Messages.ToolCategory_other);
0291:                    }
0292:                }
0293:                category.add(proxy);
0294:            }
0295:
0296:            /**
0297:             * Processes the extension point and creates all the categories.
0298:             */
0299:            private void processCategories() {
0300:                List<IConfigurationElement> extension = ExtensionPointList
0301:                        .getExtensionPointList(Tool.EXTENSION_ID);
0302:                for (IConfigurationElement element : extension) {
0303:                    if (!element.getName().equals("category")) //$NON-NLS-1$
0304:                        continue;
0305:                    ModalToolCategory modalCategory;
0306:                    String id = element.getAttribute("id"); //$NON-NLS-1$
0307:                    categoryIds.add(id);
0308:                    modalCategory = findModalCategory(id);
0309:                    if (modalCategory == null) {
0310:                        modalCategory = new ModalToolCategory(element,
0311:                                ToolManager.this );
0312:                        modalCategories.add(modalCategory);
0313:                    }
0314:                    ActionToolCategory actionCategory;
0315:                    actionCategory = findActionCategory(id);
0316:                    if (actionCategory == null) {
0317:                        actionCategory = new ActionToolCategory(element,
0318:                                ToolManager.this );
0319:                        actionCategories.add(actionCategory);
0320:                    }
0321:                    MenuToolCategory category;
0322:                    category = findMenuCategory(id);
0323:                    if (category == null) {
0324:                        category = new MenuToolCategory(element,
0325:                                ToolManager.this );
0326:                        menuCategories.add(category);
0327:                    }
0328:                }
0329:            }
0330:
0331:            private void removeEmptyCategories() {
0332:                List<ToolCategory> toRemove = new ArrayList<ToolCategory>();
0333:                for (ActionToolCategory category : actionCategories) {
0334:                    if (category.items.size() == 0)
0335:                        toRemove.add(category);
0336:                }
0337:                actionCategories.removeAll(toRemove);
0338:                for (ModalToolCategory category : modalCategories) {
0339:                    if (category.items.size() == 0)
0340:                        toRemove.add(category);
0341:                }
0342:                modalCategories.removeAll(toRemove);
0343:                for (MenuToolCategory category : menuCategories) {
0344:                    if (category.items.size() == 0)
0345:                        toRemove.add(category);
0346:                }
0347:                menuCategories.removeAll(toRemove);
0348:            }
0349:
0350:            private void setCommandHandlers() {
0351:                Set<String> ids = new HashSet<String>();
0352:                ICommandService service = (ICommandService) PlatformUI
0353:                        .getWorkbench().getAdapter(ICommandService.class);
0354:                for (ModalToolCategory category : modalCategories) {
0355:                    if (!ids.contains(category.getId())) {
0356:                        ids.add(category.getId());
0357:                        category.setCommandHandlers(service);
0358:                    }
0359:                    registerCommands(ids, service, category);
0360:                }
0361:                for (ActionToolCategory category : actionCategories) {
0362:                    if (!ids.contains(category.getId())) {
0363:                        ids.add(category.getId());
0364:                        category.setCommandHandlers(service);
0365:                    }
0366:                    registerCommands(ids, service, category);
0367:                }
0368:                for (MenuToolCategory category : menuCategories) {
0369:                    if (!ids.contains(category.getId())) {
0370:                        ids.add(category.getId());
0371:                        category.setCommandHandlers(service);
0372:                    }
0373:                    registerCommands(ids, service, category);
0374:                }
0375:
0376:            }
0377:
0378:            /**
0379:             *
0380:             * @param ids
0381:             * @param service
0382:             * @param category
0383:             */
0384:            private void registerCommands(Set<String> ids,
0385:                    ICommandService service, ToolCategory category) {
0386:                for (ModalItem tool : category) {
0387:                    if (!ids.contains(tool.getId())) {
0388:                        ids.add(category.getId());
0389:
0390:                        for (String currentId : tool.getCommandIds()) {
0391:                            currentId = currentId.trim();
0392:                            Command command = service.getCommand(currentId);
0393:                            if (command != null)
0394:                                command.setHandler(tool.getHandler(currentId));
0395:                        }
0396:                    }
0397:                }
0398:            }
0399:
0400:            MapEditor currentEditor;
0401:
0402:            /**
0403:             * This method is called to perform tools initialization when
0404:             * the map editor is selected.
0405:             * 
0406:             */
0407:            public void setCurrentEditor(MapEditor editor) {
0408:
0409:                if (editor == currentEditor)
0410:                    return;
0411:
0412:                currentEditor = editor;
0413:                if (editor != null) {
0414:                    if (editor != null) {
0415:                        setActiveTool(editor);
0416:                        setEnabled(editor.getMap(), actionCategories);
0417:                        setEnabled(editor.getMap(), menuCategories);
0418:                        setEnabled(editor.getMap(), modalCategories);
0419:                    }
0420:                } else {
0421:                    disable(actionCategories);
0422:                    disable(menuCategories);
0423:                    disable(modalCategories);
0424:                }
0425:
0426:            }
0427:
0428:            private void disable(List<? extends ToolCategory> categories) {
0429:                for (ToolCategory category : categories) {
0430:                    for (ModalItem item : category) {
0431:                        OpFilter enablesFor = item.getEnablesFor();
0432:                        if (enablesFor instanceof  LazyOpFilter)
0433:                            ((LazyOpFilter) enablesFor).disable();
0434:                    }
0435:                }
0436:            }
0437:
0438:            EditManagerListener selectedLayerListener;
0439:
0440:            /**
0441:             * Listener for EditManager.
0442:             * 
0443:             * @author Vitalus
0444:             *
0445:             */
0446:            class EditManagerListener implements  IEditManagerListener {
0447:
0448:                public void setCurrentMap(IMap map) {
0449:                }
0450:
0451:                public void changed(EditManagerEvent event) {
0452:                    if (selectedLayerListener != this ) {
0453:                        event.getSource().removeListener(this );
0454:                        return;
0455:                    }
0456:                    if (event.getType() == EditManagerEvent.SELECTED_LAYER) {
0457:                        setEnabled(event.getSource().getMap(), actionCategories);
0458:                        setEnabled(event.getSource().getMap(), menuCategories);
0459:                        setEnabled(event.getSource().getMap(), modalCategories);
0460:                    }
0461:                }
0462:            }
0463:
0464:            private void setEnabled(IMap map,
0465:                    Collection<? extends ToolCategory> categories) {
0466:
0467:                if (selectedLayerListener == null)
0468:                    selectedLayerListener = new EditManagerListener();
0469:
0470:                selectedLayerListener.setCurrentMap(map);
0471:
0472:                //One listener is enough. Say NO to listeners hell:)
0473:                if (!map.getEditManager().containsListener(
0474:                        selectedLayerListener))
0475:                    map.getEditManager().addListener(selectedLayerListener);
0476:
0477:                for (ToolCategory cat : categories) {
0478:                    for (ModalItem item : cat) {
0479:                        OpFilter enablesFor = item.getEnablesFor();
0480:                        ILayer selectedLayer = map.getEditManager()
0481:                                .getSelectedLayer();
0482:
0483:                        assert enablesFor instanceof  LazyOpFilter;
0484:
0485:                        if (!(enablesFor instanceof  LazyOpFilter)) {
0486:                            enablesFor = new LazyOpFilter(item, enablesFor);
0487:                        }
0488:
0489:                        boolean accept = enablesFor.accept(selectedLayer);
0490:                        item.setEnabled(accept);
0491:                    }
0492:                }
0493:            }
0494:
0495:            /**
0496:             * Sets the context of the currently active tool and ensures that all tools are enabled. This is
0497:             * a small hack so that tools are active even when the editor is not in focus.
0498:             * 
0499:             * @param editor
0500:             */
0501:            @SuppressWarnings("unchecked")
0502:            void setActiveTool(MapEditor editor) {
0503:                if (!editor.getMap().eAdapters().contains(
0504:                        getCommandListener(editor)))
0505:                    editor.getMap().eAdapters().add(getCommandListener(editor));
0506:                ToolContext tools = new ToolContextImpl();
0507:                tools.setMapInternal(editor.getMap());
0508:
0509:                setContext(modalCategories, tools);
0510:                setContext(actionCategories, tools);
0511:                setContext(menuCategories, tools);
0512:
0513:                for (ToolProxy tool : backgroundTools) {
0514:                    tool.setContext(tools);
0515:                }
0516:                for (Iterator iter = registeredToolActions.iterator(); iter
0517:                        .hasNext();)
0518:                    ((IAction) iter.next()).setEnabled(true);
0519:
0520:                setCommandActions(editor.getMap(), editor);
0521:                editor.setSelectionProvider(activeModalToolProxy
0522:                        .getSelectionProvider());
0523:            }
0524:
0525:            private void setContext(List categories, ToolContext tools) {
0526:                for (Iterator iter = categories.iterator(); iter.hasNext();) {
0527:                    ToolCategory category = (ToolCategory) iter.next();
0528:                    for (Iterator titer = category.iterator(); titer.hasNext();) {
0529:                        ToolProxy tool = (ToolProxy) titer.next();
0530:                        tool.setContext(tools);
0531:                    }
0532:                }
0533:            }
0534:
0535:            /**
0536:             * Adds an Action that executes a tool to the toolbar.
0537:             * 
0538:             * @param action
0539:             */
0540:            public void addToolAction(IAction action) {
0541:                registeredToolActions.add(action);
0542:                action.setEnabled(ApplicationGIS.getActiveMap() != null);
0543:            }
0544:
0545:            /**
0546:             * Creates a action that acts as a proxy for the tool in the editor toolbar.
0547:             * <p>
0548:             * The client code must set the name image descriptor etc... of the Action
0549:             * </p>
0550:             * 
0551:             * @param toolID the id of the tool
0552:             * @param categoryID the category the tool is part of
0553:             * @return a proxy action that can be put in other toolbars
0554:             */
0555:            public IAction createToolAction(final String toolID,
0556:                    final String categoryID) {
0557:                final IAction toolAction = new Action() {
0558:                    @Override
0559:                    public void runWithEvent(Event event) {
0560:                        IAction action = getTool(toolID, categoryID);
0561:                        if (action != null && action.isEnabled()) {
0562:                            action.runWithEvent(event);
0563:                        }
0564:                    }
0565:                };
0566:                toolAction
0567:                        .addPropertyChangeListener(new IPropertyChangeListener() {
0568:
0569:                            public void propertyChange(PropertyChangeEvent event) {
0570:                                if (event.getProperty().equals(IAction.ENABLED)) {
0571:                                    toolAction.setEnabled((Boolean) event
0572:                                            .getNewValue());
0573:                                }
0574:                            }
0575:
0576:                        });
0577:                toolAction.setEnabled(getTool(toolID, categoryID).isEnabled());
0578:                addToolAction(toolAction);
0579:                return toolAction;
0580:            }
0581:
0582:            /**
0583:             * 
0584:             */
0585:            public ActionToolCategory findActionCategory(String id) {
0586:                for (ActionToolCategory category : actionCategories) {
0587:                    if (category.getId().equals(id))
0588:                        return category;
0589:                }
0590:                return null;
0591:            }
0592:
0593:            MenuToolCategory findMenuCategory(String id) {
0594:                for (MenuToolCategory category : menuCategories) {
0595:                    if (category.getId().equals(id))
0596:                        return category;
0597:                }
0598:                return null;
0599:            }
0600:
0601:            protected ModalToolCategory findModalCategory(String id) {
0602:                for (ModalToolCategory category : modalCategories) {
0603:                    String id2 = category.getId();
0604:                    if (id2.equals(id))
0605:                        return category;
0606:                }
0607:                return null;
0608:            }
0609:
0610:            /**
0611:             * 
0612:             */
0613:            public void contributeToMenu(IMenuManager manager) {
0614:                String navKey = IWorkbenchActionConstants.M_NAVIGATE;
0615:                IMenuManager nav = manager.findMenuUsingPath(navKey);
0616:                if (nav == null) {
0617:                    MenuManager tmp = new MenuManager(
0618:                            Messages.ToolManager_menu_manager_title, navKey);
0619:                    nav = tmp;
0620:                    manager.appendToGroup(
0621:                            IWorkbenchActionConstants.MB_ADDITIONS, nav);
0622:                    nav
0623:                            .add(new GroupMarker(
0624:                                    IWorkbenchActionConstants.NAV_START));
0625:                }
0626:                IWorkbenchWindow window = PlatformUI.getWorkbench()
0627:                        .getActiveWorkbenchWindow();
0628:                nav.appendToGroup(IWorkbenchActionConstants.NAV_START,
0629:                        ActionFactory.BACK.create(window));
0630:                nav.appendToGroup(IWorkbenchActionConstants.NAV_START,
0631:                        ActionFactory.FORWARD.create(window));
0632:                if (!manager.isVisible())
0633:                    manager.setVisible(true);
0634:                for (MenuToolCategory category : menuCategories) {
0635:                    category.contribute(manager);
0636:                }
0637:            }
0638:
0639:            /** (non-Javadoc)
0640:             * 
0641:             * @see net.refractions.udig.project.ui.tool.IToolManager#contributeActiveModalTool(org.eclipse.jface.action.IMenuManager)
0642:             */
0643:            public void contributeActiveModalTool(IMenuManager manager) {
0644:
0645:                Tool activeTool = getActiveTool();
0646:                if (activeTool instanceof  IContextMenuContributionTool) {
0647:                    IContextMenuContributionTool contributionTool = (IContextMenuContributionTool) activeTool;
0648:                    ArrayList<IContributionItem> contributions = new ArrayList<IContributionItem>();
0649:                    contributionTool.contributeContextMenu(contributions);
0650:
0651:                    if (!contributions.isEmpty()) {
0652:                        manager.add(new Separator());
0653:                        for (IContributionItem item : contributions) {
0654:                            manager.add(item);
0655:                        }
0656:                    }
0657:                }
0658:            }
0659:
0660:            /**
0661:             * Retrieves the redo action that is used by much of the map components such as the MapEditor
0662:             * and the LayersView. redoes the last undone command sent to the currently active map.
0663:             */
0664:            public IAction getREDOAction() {
0665:                Map activeMap = ApplicationGISInternal.getActiveMap();
0666:                redoLock.lock();
0667:                try {
0668:                    if (redoAction == null) {
0669:                        redoAction = new Action() {
0670:                            /**
0671:                             * @see org.eclipse.jface.action.Action#run()
0672:                             */
0673:                            public void run() {
0674:                                Map activeMap = ApplicationGISInternal
0675:                                        .getActiveMap();
0676:                                if (activeMap != null)
0677:                                    activeMap.redo();
0678:                            }
0679:                        };
0680:                        redoAction
0681:                                .setImageDescriptor(sharedImages
0682:                                        .getImageDescriptor(ISharedImages.IMG_TOOL_REDO));
0683:                        redoAction.setText(Messages.ToolManager_redoAction);
0684:                        redoAction
0685:                                .setActionDefinitionId("org.eclipse.ui.edit.redo"); //$NON-NLS-1$
0686:                    }
0687:                    if (activeMap != null)
0688:                        redoAction.setEnabled(activeMap.getCommandStack()
0689:                                .canRedo());
0690:                    else
0691:                        redoAction.setEnabled(false);
0692:
0693:                    return redoAction;
0694:                } finally {
0695:                    redoLock.unlock();
0696:                }
0697:            }
0698:
0699:            /**
0700:             * 
0701:             */
0702:            public void setREDOAction(IAction action, IWorkbenchPart part) {
0703:                if (action == null)
0704:                    throw new NullPointerException("action must not be null"); //$NON-NLS-1$
0705:                if (part == null)
0706:                    throw new NullPointerException("part must not be null"); //$NON-NLS-1$
0707:                redoLock.lock();
0708:                try {
0709:                    redoAction = action;
0710:                    redoAction
0711:                            .setActionDefinitionId("org.eclipse.ui.edit.redo"); //$NON-NLS-1$
0712:                    IKeyBindingService service = part.getSite()
0713:                            .getKeyBindingService();
0714:                    service.registerAction(redoAction);
0715:                } finally {
0716:                    redoLock.unlock();
0717:                }
0718:            }
0719:
0720:            /**
0721:             * Retrieves the undo action that is used by much of the map components such as the MapEditor
0722:             * and the LayersView. Undoes the last command sent to the currently active map.
0723:             * 
0724:             * @param part
0725:             */
0726:            public IAction getUNDOAction() {
0727:                Map activeMap = ApplicationGISInternal.getActiveMap();
0728:                undoLock.lock();
0729:                try {
0730:                    if (undoAction == null) {
0731:                        undoAction = new Action() {
0732:                            /**
0733:                             * @see org.eclipse.jface.action.Action#run()
0734:                             */
0735:                            public void run() {
0736:                                Map activeMap = ApplicationGISInternal
0737:                                        .getActiveMap();
0738:                                if (activeMap != null)
0739:                                    activeMap.undo();
0740:                            }
0741:                        };
0742:                        undoAction
0743:                                .setImageDescriptor(sharedImages
0744:                                        .getImageDescriptor(ISharedImages.IMG_TOOL_UNDO));
0745:                        undoAction.setText(Messages.ToolManager_undoAction);
0746:                        undoAction
0747:                                .setActionDefinitionId("org.eclipse.ui.edit.undo"); //$NON-NLS-1$
0748:                    }
0749:                    if (activeMap != null)
0750:                        undoAction.setEnabled(activeMap.getCommandStack()
0751:                                .canUndo());
0752:                    else
0753:                        undoAction.setEnabled(false);
0754:                    return undoAction;
0755:                } finally {
0756:                    undoLock.unlock();
0757:                }
0758:            }
0759:
0760:            /**
0761:             * 
0762:             */
0763:            public void setUNDOAction(IAction action, IWorkbenchPart part) {
0764:                if (action == null)
0765:                    throw new NullPointerException("action must not be null"); //$NON-NLS-1$
0766:                if (part == null)
0767:                    throw new NullPointerException("part must not be null"); //$NON-NLS-1$
0768:                undoLock.lock();
0769:                try {
0770:                    undoAction = action;
0771:                    undoAction
0772:                            .setActionDefinitionId("org.eclipse.ui.edit.undo"); //$NON-NLS-1$
0773:                    IKeyBindingService service = part.getSite()
0774:                            .getKeyBindingService();
0775:                    service.registerAction(undoAction);
0776:                } finally {
0777:                    undoLock.unlock();
0778:                }
0779:            }
0780:
0781:            /**
0782:             * Retrieves the forward navigation action that is used by much of the map components such as
0783:             * the MapEditor and the LayersView. Executes the last undone Nav command on the current map.
0784:             */
0785:            public IAction getFORWARD_HISTORYAction() {
0786:                Map activeMap = ApplicationGISInternal.getActiveMap();
0787:                forwardLock.lock();
0788:                try {
0789:                    if (forwardAction == null) {
0790:                        forwardAction = new Action() {
0791:                            /**
0792:                             * @see org.eclipse.jface.action.Action#run()
0793:                             */
0794:                            public void run() {
0795:                                Map activeMap = ApplicationGISInternal
0796:                                        .getActiveMap();
0797:                                if (activeMap != null)
0798:                                    activeMap.forwardHistory();
0799:                            }
0800:                        };
0801:                        forwardAction
0802:                                .setImageDescriptor(sharedImages
0803:                                        .getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD));
0804:                        forwardAction.setText(Messages.ToolManager_forward);
0805:                        forwardAction
0806:                                .setToolTipText(Messages.ToolManager_forward_tooltip);
0807:                        forwardAction
0808:                                .setActionDefinitionId("org.eclipse.ui.navigate.forward"); //$NON-NLS-1$
0809:                    }
0810:                    if (activeMap != null)
0811:                        forwardAction.setEnabled(activeMap.getCommandStack()
0812:                                .canRedo());
0813:                    else
0814:                        forwardAction.setEnabled(false);
0815:                    return forwardAction;
0816:                } finally {
0817:                    forwardLock.unlock();
0818:                }
0819:
0820:            }
0821:
0822:            /**
0823:             * 
0824:             */
0825:            public void setFORWARDAction(IAction action, IWorkbenchPart part) {
0826:                if (action == null)
0827:                    throw new NullPointerException("action must not be null"); //$NON-NLS-1$
0828:                if (part == null)
0829:                    throw new NullPointerException("part must not be null"); //$NON-NLS-1$
0830:                forwardLock.lock();
0831:                try {
0832:                    forwardAction = action;
0833:                    forwardAction
0834:                            .setActionDefinitionId("org.eclipse.ui.navigate.forward"); //$NON-NLS-1$
0835:                    IKeyBindingService service = part.getSite()
0836:                            .getKeyBindingService();
0837:                    service.registerAction(forwardAction);
0838:                } finally {
0839:                    forwardLock.unlock();
0840:                }
0841:            }
0842:
0843:            public void registerActionsWithPart(IWorkbenchPart part) {
0844:
0845:                IKeyBindingService service = part.getSite()
0846:                        .getKeyBindingService();
0847:                service.registerAction(getBACKWARD_HISTORYAction());
0848:                service.registerAction(getFORWARD_HISTORYAction());
0849:                service.registerAction(getCOPYAction(part));
0850:                service.registerAction(getCUTAction(part));
0851:                service.registerAction(getDELETEAction());
0852:                service.registerAction(getPASTEAction(part));
0853:                service.registerAction(getREDOAction());
0854:                service.registerAction(getUNDOAction());
0855:
0856:                addToolScope(part.getSite());
0857:            }
0858:
0859:            public void unregisterActions(IWorkbenchPart part) {
0860:
0861:                IKeyBindingService service = part.getSite()
0862:                        .getKeyBindingService();
0863:
0864:                service.unregisterAction(getBACKWARD_HISTORYAction());
0865:                service.unregisterAction(getFORWARD_HISTORYAction());
0866:                service.unregisterAction(getCOPYAction(part));
0867:                service.unregisterAction(getCUTAction(part));
0868:                service.unregisterAction(getDELETEAction());
0869:                service.unregisterAction(getPASTEAction(part));
0870:                service.unregisterAction(getREDOAction());
0871:                service.unregisterAction(getUNDOAction());
0872:
0873:                service.setScopes(new String[0]);
0874:            }
0875:
0876:            /**
0877:             * Retrieves the backward navigation action that is used by much of the map components such as
0878:             * the MapEditor and the LayersView. Undoes the last Nav command set to the current map.
0879:             * 
0880:             * @param part
0881:             */
0882:            public IAction getBACKWARD_HISTORYAction() {
0883:                Map activeMap = ApplicationGISInternal.getActiveMap();
0884:                backwardLock.lock();
0885:                try {
0886:                    if (backwardAction == null) {
0887:                        backwardAction = new Action() {
0888:                            /**
0889:                             * @see org.eclipse.jface.action.Action#run()
0890:                             */
0891:                            public void run() {
0892:                                Map activeMap = ApplicationGISInternal
0893:                                        .getActiveMap();
0894:                                if (activeMap != null)
0895:                                    activeMap.backwardHistory();
0896:                            }
0897:
0898:                        };
0899:                        backwardAction
0900:                                .setImageDescriptor(sharedImages
0901:                                        .getImageDescriptor(ISharedImages.IMG_TOOL_BACK));
0902:                        backwardAction.setText(Messages.ToolManager_back);
0903:                        backwardAction
0904:                                .setToolTipText(Messages.ToolManager_back_tooltip);
0905:                        backwardAction
0906:                                .setActionDefinitionId("org.eclipse.ui.navigate.back"); //$NON-NLS-1$
0907:                    }
0908:                    if (activeMap != null)
0909:                        backwardAction.setEnabled(activeMap.getCommandStack()
0910:                                .canUndo());
0911:                    else
0912:                        backwardAction.setEnabled(false);
0913:                } finally {
0914:                    backwardLock.unlock();
0915:                }
0916:
0917:                return backwardAction;
0918:            }
0919:
0920:            /**
0921:             * 
0922:             */
0923:            public void setBACKAction(IAction action, IWorkbenchPart part) {
0924:                if (action == null)
0925:                    throw new NullPointerException("action must not be null"); //$NON-NLS-1$
0926:                if (part == null)
0927:                    throw new NullPointerException("part must not be null"); //$NON-NLS-1$
0928:                backwardLock.lock();
0929:                try {
0930:                    backwardAction = action;
0931:                    backwardAction
0932:                            .setActionDefinitionId("org.eclipse.ui.navigate.back"); //$NON-NLS-1$
0933:                    IKeyBindingService service = part.getSite()
0934:                            .getKeyBindingService();
0935:                    service.registerAction(backwardAction);
0936:                } finally {
0937:                    backwardLock.unlock();
0938:                }
0939:
0940:            }
0941:
0942:            /**
0943:             * 
0944:             */
0945:            public IAction getCUTAction(IWorkbenchPart part) {
0946:                cutLock.lock();
0947:                try {
0948:                    if (cutAction == null) {
0949:                        cutAction = new Action() {
0950:
0951:                        };
0952:                    }
0953:                    // JONES
0954:                    return cutAction;
0955:                } finally {
0956:                    cutLock.unlock();
0957:                }
0958:            }
0959:
0960:            public void setCUTAction(IAction action, IWorkbenchPart part) {
0961:                if (action == null)
0962:                    throw new NullPointerException("action must not be null"); //$NON-NLS-1$
0963:                if (part == null)
0964:                    throw new NullPointerException("part must not be null"); //$NON-NLS-1$
0965:                cutLock.lock();
0966:                try {
0967:                    cutAction = action;
0968:                    cutAction.setActionDefinitionId("org.eclipse.ui.edit.cut"); //$NON-NLS-1$
0969:                    IKeyBindingService service = part.getSite()
0970:                            .getKeyBindingService();
0971:                    service.registerAction(cutAction);
0972:                } finally {
0973:                    cutLock.unlock();
0974:                }
0975:            }
0976:
0977:            public IAction getCOPYAction(final IWorkbenchPart part) {
0978:                copyLock.lock();
0979:                try {
0980:                    if (copyAction == null) {
0981:                        if (copyAction == null) {
0982:                            copyAction = new CopyAction();
0983:                            IAction template = ActionFactory.COPY.create(part
0984:                                    .getSite().getWorkbenchWindow());
0985:                            copyAction.setText(template.getText());
0986:                            copyAction
0987:                                    .setToolTipText(template.getToolTipText());
0988:                            copyAction.setImageDescriptor(template
0989:                                    .getImageDescriptor());
0990:                            copyAction.setId(template.getId());
0991:                            copyAction
0992:                                    .setActionDefinitionId("org.eclipse.ui.edit.copy"); //$NON-NLS-1$
0993:                        }
0994:                    }
0995:                    if (copyAction instanceof  CopyAction) {
0996:                        ((CopyAction) copyAction).setPart(part);
0997:                    }
0998:                    IKeyBindingService service = part.getSite()
0999:                            .getKeyBindingService();
1000:                    service.registerAction(copyAction);
1001:                    return copyAction;
1002:                } finally {
1003:                    copyLock.unlock();
1004:                }
1005:            }
1006:
1007:            public void setCOPYAction(IAction action, IWorkbenchPart part) {
1008:                if (action == null)
1009:                    throw new NullPointerException("action must not be null"); //$NON-NLS-1$
1010:                if (part == null)
1011:                    throw new NullPointerException("part must not be null"); //$NON-NLS-1$
1012:                copyLock.lock();
1013:                try {
1014:                    copyAction = action;
1015:                    copyAction
1016:                            .setActionDefinitionId("org.eclipse.ui.edit.copy"); //$NON-NLS-1$
1017:                    IKeyBindingService service = part.getSite()
1018:                            .getKeyBindingService();
1019:                    service.registerAction(copyAction);
1020:                } finally {
1021:                    copyLock.unlock();
1022:                }
1023:            }
1024:
1025:            public IAction getPASTEAction(IWorkbenchPart part) {
1026:                pasteLock.lock();
1027:                try {
1028:                    if (pasteAction == null) {
1029:                        pasteAction = new PasteAction();
1030:                        IAction template = ActionFactory.PASTE.create(part
1031:                                .getSite().getWorkbenchWindow());
1032:                        pasteAction.setText(template.getText());
1033:                        pasteAction.setToolTipText(template.getToolTipText());
1034:                        pasteAction.setImageDescriptor(template
1035:                                .getImageDescriptor());
1036:                        pasteAction.setId(template.getId());
1037:                        pasteAction
1038:                                .setActionDefinitionId("org.eclipse.ui.edit.paste"); //$NON-NLS-1$
1039:                    }
1040:                    if (pasteAction instanceof  PasteAction) {
1041:                        ((PasteAction) pasteAction).setPart(part);
1042:                    }
1043:
1044:                    IKeyBindingService service = part.getSite()
1045:                            .getKeyBindingService();
1046:                    service.registerAction(pasteAction);
1047:                    return pasteAction;
1048:                } finally {
1049:                    pasteLock.unlock();
1050:                }
1051:            }
1052:
1053:            public void setPASTEAction(IAction action, IWorkbenchPart part) {
1054:                if (action == null)
1055:                    throw new NullPointerException("action must not be null"); //$NON-NLS-1$
1056:                if (part == null)
1057:                    throw new NullPointerException("part must not be null"); //$NON-NLS-1$
1058:                pasteLock.lock();
1059:                try {
1060:                    pasteAction = action;
1061:                    pasteAction
1062:                            .setActionDefinitionId("org.eclipse.ui.edit.paste"); //$NON-NLS-1$
1063:                    IKeyBindingService service = part.getSite()
1064:                            .getKeyBindingService();
1065:                    service.registerAction(pasteAction);
1066:                } finally {
1067:                    pasteLock.unlock();
1068:                }
1069:            }
1070:
1071:            public synchronized IAction getDELETEAction() {
1072:                deleteLock.lock();
1073:                try {
1074:                    if (deleteAction == null) {
1075:                        deleteAction = new Action() {
1076:                            @Override
1077:                            public void run() {
1078:                                Delete delete = new Delete();
1079:                                ISelection s = PlatformUI.getWorkbench()
1080:                                        .getActiveWorkbenchWindow()
1081:                                        .getSelectionService().getSelection();
1082:                                delete.selectionChanged(this , s);
1083:                                delete.run(this );
1084:                            }
1085:                        };
1086:                        deleteAction
1087:                                .setActionDefinitionId("org.eclipse.ui.edit.delete"); //$NON-NLS-1$
1088:                        IWorkbenchAction actionTemplate = ActionFactory.DELETE
1089:                                .create(PlatformUI.getWorkbench()
1090:                                        .getActiveWorkbenchWindow());
1091:                        deleteAction.setText(actionTemplate.getText());
1092:                        deleteAction.setToolTipText(actionTemplate
1093:                                .getToolTipText());
1094:                        deleteAction.setImageDescriptor(actionTemplate
1095:                                .getImageDescriptor());
1096:                        deleteAction.setDescription(actionTemplate
1097:                                .getDescription());
1098:                        deleteAction.setDisabledImageDescriptor(actionTemplate
1099:                                .getDisabledImageDescriptor());
1100:                    }
1101:
1102:                    return deleteAction;
1103:                } finally {
1104:                    deleteLock.unlock();
1105:                }
1106:            }
1107:
1108:            public synchronized void setDELETEAction(IAction action,
1109:                    IWorkbenchPart part) {
1110:                if (action == null)
1111:                    throw new NullPointerException("action must not be null"); //$NON-NLS-1$
1112:                if (part == null)
1113:                    throw new NullPointerException("part must not be null"); //$NON-NLS-1$
1114:                deleteLock.lock();
1115:                try {
1116:                    deleteAction = action;
1117:                    deleteAction
1118:                            .setActionDefinitionId("org.eclipse.ui.edit.delete"); //$NON-NLS-1$
1119:                    IKeyBindingService service = part.getSite()
1120:                            .getKeyBindingService();
1121:                    service.registerAction(deleteAction);
1122:                } finally {
1123:                    deleteLock.unlock();
1124:                }
1125:            }
1126:
1127:            private void createModalToolToolbar(SubCoolBarManager cbmanager) {
1128:                ToolBarManager manager = new ToolBarManager(SWT.FLAT);
1129:
1130:                for (String id : categoryIds) {
1131:                    ModalToolCategory modalCategory = findModalCategory(id);
1132:                    if (modalCategory != null) {
1133:                        modalCategory.contribute(manager);
1134:                    }
1135:                }
1136:                if (manager != null && manager.getItems().length > 0)
1137:                    cbmanager.add(manager);
1138:            }
1139:
1140:            private void createActionToolToolbar(SubCoolBarManager cbmanager) {
1141:                ToolBarManager manager = new ToolBarManager(SWT.FLAT);
1142:
1143:                manager.add(getBACKWARD_HISTORYAction());
1144:                manager.add(getFORWARD_HISTORYAction());
1145:                for (String id : categoryIds) {
1146:                    ActionToolCategory category = findActionCategory(id);
1147:                    if (category != null)
1148:                        category.contribute(manager);
1149:                }
1150:                if (manager != null && manager.getItems().length > 0)
1151:                    cbmanager.add(manager);
1152:            }
1153:
1154:            /**
1155:             * Adds both action tools and modal tools to the manager
1156:             * 
1157:             * @deprecated
1158:             * 
1159:             * @see contributeActionTools(IToolBarManager toolBarManager, IActionBars bars )
1160:             * @see contributeModalTools(IToolBarManager toolBarManager, IActionBars bars )
1161:             * 
1162:             * @param cbmanager
1163:             * @param bars
1164:             * @see net.refractions.udig.project.ui.tool.ModalTool
1165:             * @see net.refractions.udig.project.ui.tool.ActionTool
1166:             */
1167:            public void contributeToCoolBar(SubCoolBarManager cbmanager,
1168:                    IActionBars bars) {
1169:                cbmanager.setVisible(true);
1170:                createActionToolToolbar(cbmanager);
1171:                createModalToolToolbar(cbmanager);
1172:            }
1173:
1174:            /* (non-Javadoc)
1175:             * @see net.refractions.udig.project.ui.tool.IToolManager#contributeActionTools(org.eclipse.jface.action.IToolBarManager, org.eclipse.ui.IActionBars)
1176:             */
1177:            public void contributeActionTools(IToolBarManager toolBarManager,
1178:                    IActionBars bars) {
1179:                toolBarManager.add(getBACKWARD_HISTORYAction());
1180:                toolBarManager.add(getFORWARD_HISTORYAction());
1181:                for (String id : categoryIds) {
1182:                    ActionToolCategory category = findActionCategory(id);
1183:                    if (category != null)
1184:                        category.contribute(toolBarManager);
1185:                }
1186:            }
1187:
1188:            /* (non-Javadoc)
1189:             * @see net.refractions.udig.project.ui.tool.IToolManager#contributeModalTools(org.eclipse.jface.action.IToolBarManager, org.eclipse.ui.IActionBars)
1190:             */
1191:            public void contributeModalTools(IToolBarManager toolBarManager,
1192:                    IActionBars bars) {
1193:                for (String id : categoryIds) {
1194:                    ModalToolCategory modalCategory = findModalCategory(id);
1195:                    if (modalCategory != null) {
1196:                        modalCategory.contribute(toolBarManager);
1197:                    }
1198:                }
1199:            }
1200:
1201:            SubActionBars2 getActionBars() {
1202:                if (ApplicationGISInternal.getActiveMap() == null)
1203:                    return null;
1204:                return ApplicationGISInternal.getActiveEditor().getActionbar();
1205:            }
1206:
1207:            private IAction actionCLOSE;
1208:            private IAction actionSAVE;
1209:            private IAction actionCLOSE_ALL;
1210:
1211:            /**
1212:             * Contributes the common global actions.
1213:             * 
1214:             * @param bars
1215:             */
1216:            public void contributeGlobalActions(IWorkbenchPart part,
1217:                    IActionBars bars) {
1218:                IKeyBindingService service = part.getSite()
1219:                        .getKeyBindingService();
1220:                bars.setGlobalActionHandler(ActionFactory.BACK.getId(),
1221:                        getBACKWARD_HISTORYAction());
1222:                bars.setGlobalActionHandler(ActionFactory.FORWARD.getId(),
1223:                        getFORWARD_HISTORYAction());
1224:                bars.setGlobalActionHandler(ActionFactory.UNDO.getId(),
1225:                        getUNDOAction());
1226:                bars.setGlobalActionHandler(ActionFactory.REDO.getId(),
1227:                        getREDOAction());
1228:                bars.setGlobalActionHandler(ActionFactory.CUT.getId(),
1229:                        getCUTAction(part));
1230:                bars.setGlobalActionHandler(ActionFactory.COPY.getId(),
1231:                        getCOPYAction(part));
1232:                bars.setGlobalActionHandler(ActionFactory.PASTE.getId(),
1233:                        getPASTEAction(part));
1234:                bars.setGlobalActionHandler(ActionFactory.DELETE.getId(),
1235:                        getDELETEAction());
1236:                if (actionCLOSE == null)
1237:                    actionCLOSE = ActionFactory.CLOSE.create(part.getSite()
1238:                            .getWorkbenchWindow());
1239:                service.registerAction(actionCLOSE);
1240:                bars.setGlobalActionHandler(ActionFactory.CLOSE.getId(),
1241:                        actionCLOSE);
1242:
1243:                if (actionSAVE == null)
1244:                    actionSAVE = ActionFactory.SAVE.create(part.getSite()
1245:                            .getWorkbenchWindow());
1246:                service.registerAction(actionSAVE);
1247:                bars.setGlobalActionHandler(ActionFactory.SAVE.getId(),
1248:                        actionSAVE);
1249:
1250:                if (actionCLOSE_ALL == null)
1251:                    actionCLOSE_ALL = ActionFactory.CLOSE_ALL.create(part
1252:                            .getSite().getWorkbenchWindow());
1253:                bars.setGlobalActionHandler(ActionFactory.CLOSE_ALL.getId(),
1254:                        actionCLOSE_ALL);
1255:
1256:            }
1257:
1258:            void dispose() {
1259:                for (ToolCategory category : modalCategories) {
1260:                    category.dispose(ApplicationGISInternal.getActiveEditor()
1261:                            .getEditorSite().getActionBars());
1262:                }
1263:                for (ToolCategory category : actionCategories) {
1264:                    category.dispose(ApplicationGISInternal.getActiveEditor()
1265:                            .getEditorSite().getActionBars());
1266:                }
1267:                for (ToolCategory category : menuCategories) {
1268:                    category.dispose(ApplicationGISInternal.getActiveEditor()
1269:                            .getEditorSite().getActionBars());
1270:                }
1271:                for (ToolProxy tool : backgroundTools) {
1272:                    tool.dispose();
1273:                }
1274:
1275:            }
1276:
1277:            Adapter getCommandListener(final MapEditor editor) {
1278:                if (commandListener == null) {
1279:                    commandListener = new AdapterImpl() {
1280:                        /**
1281:                         * @see org.eclipse.emf.common.notify.impl.AdapterImpl#notifyChanged(org.eclipse.emf.common.notify.Notification)
1282:                         */
1283:                        public void notifyChanged(Notification msg) {
1284:                            // Map map = (Map) getTarget();
1285:                            /*
1286:                             * While this adapter is a singlton and added to all opened maps, each time
1287:                             * target variable is reset.
1288:                             */
1289:                            Map map = null;
1290:                            switch (msg.getFeatureID(msg.getNotifier()
1291:                                    .getClass())) {
1292:                            case ProjectPackage.MAP__COMMAND_STACK:
1293:                                map = (Map) msg.getNotifier();
1294:                                setCommandActions(map, editor);
1295:                                break;
1296:                            case ProjectPackage.MAP__NAV_COMMAND_STACK:
1297:                                map = (Map) msg.getNotifier();
1298:                                setCommandActions(map, editor);
1299:                                break;
1300:                            }
1301:
1302:                        }
1303:                    };
1304:                }
1305:                return commandListener;
1306:            }
1307:
1308:            void setCommandActions(Map map, MapEditor editor) {
1309:                if (map.getCommandStack().canRedo())
1310:                    getREDOAction().setEnabled(true);
1311:                else
1312:                    getREDOAction().setEnabled(false);
1313:                if (map.getCommandStack().canUndo())
1314:                    getUNDOAction().setEnabled(true);
1315:                else
1316:                    getUNDOAction().setEnabled(false);
1317:                if (map.getNavCommandStack().hasBackHistory())
1318:                    getBACKWARD_HISTORYAction().setEnabled(true);
1319:                else
1320:                    getBACKWARD_HISTORYAction().setEnabled(false);
1321:                if (map.getNavCommandStack().hasForwardHistory())
1322:                    getFORWARD_HISTORYAction().setEnabled(true);
1323:                else
1324:                    getFORWARD_HISTORYAction().setEnabled(false);
1325:            }
1326:
1327:            public IAction getTool(String toolID, String categoryID) {
1328:                return getToolAction(toolID, categoryID);
1329:            }
1330:
1331:            public IAction getToolAction(String toolID, String categoryID) {
1332:                final IAction tool = getToolInteral(toolID, categoryID);
1333:
1334:                if (tool == null)
1335:                    return null;
1336:
1337:                return new IAction() {
1338:                    IAction wrapped = tool;
1339:
1340:                    public void addPropertyChangeListener(
1341:                            IPropertyChangeListener listener) {
1342:                        wrapped.addPropertyChangeListener(listener);
1343:                    }
1344:
1345:                    public int getAccelerator() {
1346:                        return wrapped.getAccelerator();
1347:                    }
1348:
1349:                    public String getActionDefinitionId() {
1350:                        return wrapped.getActionDefinitionId();
1351:                    }
1352:
1353:                    public String getDescription() {
1354:                        return wrapped.getDescription();
1355:                    }
1356:
1357:                    public ImageDescriptor getDisabledImageDescriptor() {
1358:                        return wrapped.getDisabledImageDescriptor();
1359:                    }
1360:
1361:                    public HelpListener getHelpListener() {
1362:                        return wrapped.getHelpListener();
1363:                    }
1364:
1365:                    public ImageDescriptor getHoverImageDescriptor() {
1366:                        return wrapped.getHoverImageDescriptor();
1367:                    }
1368:
1369:                    public String getId() {
1370:                        return wrapped.getId();
1371:                    }
1372:
1373:                    public ImageDescriptor getImageDescriptor() {
1374:                        return wrapped.getImageDescriptor();
1375:                    }
1376:
1377:                    public IMenuCreator getMenuCreator() {
1378:                        return wrapped.getMenuCreator();
1379:                    }
1380:
1381:                    public int getStyle() {
1382:                        return wrapped.getStyle();
1383:                    }
1384:
1385:                    public String getText() {
1386:                        return wrapped.getText();
1387:                    }
1388:
1389:                    public String getToolTipText() {
1390:                        return wrapped.getToolTipText();
1391:                    }
1392:
1393:                    public boolean isChecked() {
1394:                        return wrapped.isChecked();
1395:                    }
1396:
1397:                    public boolean isEnabled() {
1398:                        return wrapped.isEnabled();
1399:                    }
1400:
1401:                    public boolean isHandled() {
1402:                        return wrapped.isHandled();
1403:                    }
1404:
1405:                    public void removePropertyChangeListener(
1406:                            IPropertyChangeListener listener) {
1407:                        wrapped.removePropertyChangeListener(listener);
1408:                    }
1409:
1410:                    public void runWithEvent(Event event) {
1411:                        wrapped.runWithEvent(event);
1412:                    }
1413:
1414:                    public void run() {
1415:                        wrapped.run();
1416:                    }
1417:
1418:                    public void setAccelerator(int keycode) {
1419:                        throw new UnsupportedOperationException(
1420:                                "This is an unmodifiable action"); //$NON-NLS-1$
1421:                    }
1422:
1423:                    public void setActionDefinitionId(String id) {
1424:                        throw new UnsupportedOperationException(
1425:                                "This is an unmodifiable action"); //$NON-NLS-1$
1426:                    }
1427:
1428:                    public void setChecked(boolean checked) {
1429:                        throw new UnsupportedOperationException(
1430:                                "This is an unmodifiable action"); //$NON-NLS-1$
1431:                    }
1432:
1433:                    public void setDescription(String text) {
1434:                        throw new UnsupportedOperationException(
1435:                                "This is an unmodifiable action"); //$NON-NLS-1$
1436:                    }
1437:
1438:                    public void setDisabledImageDescriptor(
1439:                            ImageDescriptor newImage) {
1440:                        throw new UnsupportedOperationException(
1441:                                "This is an unmodifiable action"); //$NON-NLS-1$
1442:                    }
1443:
1444:                    public void setEnabled(boolean enabled) {
1445:                        throw new UnsupportedOperationException(
1446:                                "This is an unmodifiable action"); //$NON-NLS-1$
1447:                    }
1448:
1449:                    public void setHelpListener(HelpListener listener) {
1450:                        throw new UnsupportedOperationException(
1451:                                "This is an unmodifiable action"); //$NON-NLS-1$
1452:                    }
1453:
1454:                    public void setHoverImageDescriptor(ImageDescriptor newImage) {
1455:                        throw new UnsupportedOperationException(
1456:                                "This is an unmodifiable action"); //$NON-NLS-1$
1457:                    }
1458:
1459:                    public void setId(String id) {
1460:                        throw new UnsupportedOperationException(
1461:                                "This is an unmodifiable action"); //$NON-NLS-1$
1462:                    }
1463:
1464:                    public void setImageDescriptor(ImageDescriptor newImage) {
1465:                        throw new UnsupportedOperationException(
1466:                                "This is an unmodifiable action"); //$NON-NLS-1$
1467:                    }
1468:
1469:                    public void setMenuCreator(IMenuCreator creator) {
1470:                        throw new UnsupportedOperationException(
1471:                                "This is an unmodifiable action"); //$NON-NLS-1$
1472:                    }
1473:
1474:                    public void setText(String text) {
1475:                        throw new UnsupportedOperationException(
1476:                                "This is an unmodifiable action"); //$NON-NLS-1$
1477:                    }
1478:
1479:                    public void setToolTipText(String text) {
1480:                        throw new UnsupportedOperationException(
1481:                                "This is an unmodifiable action"); //$NON-NLS-1$
1482:                    }
1483:                };
1484:            }
1485:
1486:            /**
1487:             * returns the actual tool action.  
1488:             */
1489:            private IAction getToolInteral(String toolID, String categoryID) {
1490:                ToolCategory category = findModalCategory(categoryID);
1491:                if (category != null) {
1492:                    IAction tool = searchCategoryForTool(toolID, category);
1493:                    if (tool != null)
1494:                        return tool;
1495:                }
1496:
1497:                category = findActionCategory(categoryID);
1498:                if (category != null) {
1499:                    IAction tool = searchCategoryForTool(toolID, category);
1500:                    if (tool != null)
1501:                        return tool;
1502:                }
1503:
1504:                category = findMenuCategory(categoryID);
1505:                if (category != null) {
1506:                    IAction tool = searchCategoryForTool(toolID, category);
1507:                    if (tool != null)
1508:                        return tool;
1509:                }
1510:                return null;
1511:            }
1512:
1513:            /**
1514:             *
1515:             * @param toolID
1516:             * @param category
1517:             * @return 
1518:             */
1519:            private IAction searchCategoryForTool(String toolID,
1520:                    ToolCategory category) {
1521:                for (Iterator iter2 = category.iterator(); iter2.hasNext();) {
1522:                    ToolProxy tool = (ToolProxy) iter2.next();
1523:                    String id = tool.getId();
1524:                    if (id.equals(toolID))
1525:                        return tool.getAction();
1526:                }
1527:                return null;
1528:            }
1529:
1530:            /**
1531:             * Returns the list of categories containing modal tools.
1532:             * 
1533:             * @return the list of categories containing modal tools.
1534:             */
1535:            public List<ModalToolCategory> getModalToolCategories() {
1536:                return modalCategories;
1537:            }
1538:
1539:            //    
1540:            //    public Tool getActiveModalTool(){
1541:            //    	
1542:            //    }
1543:
1544:            /**
1545:             * Returns the tool category that is currently active.
1546:             * 
1547:             * @return the tool category that is currently active.
1548:             */
1549:            public ToolCategory getActiveCategory() {
1550:                return findModalCategory(activeModalToolProxy.getCategoryId());
1551:            }
1552:
1553:            private static class CategorySorter implements  Comparator<String>,
1554:                    Serializable {
1555:
1556:                /** long serialVersionUID field */
1557:                private static final long serialVersionUID = 1L;
1558:                private final static java.util.Map<String, Integer> values = new HashMap<String, Integer>();
1559:                static {
1560:                    values.put(ToolConstants.RENDER_CA, 5);
1561:                    values.put(ToolConstants.ZOOM_CA, 4);
1562:                    values.put(ToolConstants.PAN_CA, 3);
1563:                    values.put(ToolConstants.SELECTION_CA, 2);
1564:                    values.put(ToolConstants.INFO_CA, 1);
1565:                    values.put(ToolConstants.EDIT_CA, 0);
1566:                }
1567:
1568:                private static final int max = -1;
1569:                private static final int min = 1;
1570:
1571:                /**
1572:                 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
1573:                 */
1574:                public int compare(String arg0, String arg1) {
1575:                    Integer value0 = values.get(arg0);
1576:                    Integer value1 = values.get(arg1);
1577:                    if (value0 == null && value1 == null)
1578:                        return 0;
1579:                    if (value1 == null)
1580:                        return max;
1581:                    if (value0 == null)
1582:                        return min;
1583:                    if (value0.equals(value1))
1584:                        return 0;
1585:
1586:                    return value0.intValue() > value1.intValue() ? max : min;
1587:                }
1588:
1589:            }
1590:
1591:            /**
1592:             * This method enables the context that allows tool keybinding to work.
1593:             * 
1594:             * @param site
1595:             */
1596:            public void addToolScope(IWorkbenchPartSite site) {
1597:                String[] scopes = site.getKeyBindingService().getScopes();
1598:                String[] newScopes = new String[scopes.length + 1];
1599:                System.arraycopy(scopes, 0, newScopes, 1, scopes.length);
1600:                newScopes[0] = "net.refractions.udig.project.ui.tool"; //$NON-NLS-1$
1601:                site.getKeyBindingService().setScopes(newScopes);
1602:            }
1603:
1604:            /*
1605:             * This allows for customized operation menus that are based on the currently selected tool.
1606:             */
1607:            public MenuManager createOperationsContextMenu(ISelection selection) {
1608:                try {
1609:                    MenuManager contextManager = getOperationMenuFactory()
1610:                            .createMenuManager();
1611:
1612:                    List<OperationCategory> primaryCategories = activeModalToolProxy
1613:                            .getOperationCategories();
1614:                    Collection<OperationCategory> secondaryCategories = getOperationMenuFactory()
1615:                            .getCategories().values();
1616:
1617:                    for (int i = 0; i < primaryCategories.size(); i++) {
1618:                        OperationCategory category = primaryCategories.get(i);
1619:
1620:                        // Limit the size of the context menu to 20, but don't ever display a portion of
1621:                        // a category, only always the entire thing.
1622:                        if (contextManager.getItems().length >= 15
1623:                                && category.getActions().size() > 5) {
1624:                            break;
1625:                        }
1626:
1627:                        MenuManager menu = category.createContextMenu();
1628:
1629:                        if ((i != 0 && menu.getItems().length != 0)
1630:                                && (secondaryCategories.size() != 0 || getOperationMenuFactory()
1631:                                        .getActions().size() != 0)) {
1632:
1633:                            contextManager.add(new Separator());
1634:                        }
1635:
1636:                        for (IContributionItem item : menu.getItems()) {
1637:                            contextManager.add(item);
1638:                        }
1639:                    }
1640:
1641:                    // if primaryCategories are present, create an "Other" submenu
1642:                    if (contextManager.getItems().length != 0) {
1643:                        RunOperationsAction action = new RunOperationsAction();
1644:                        action.setText(Messages.ToolCategory_other);
1645:
1646:                        contextManager.add(new Separator());
1647:                        contextManager.add(action);
1648:                    } else {
1649:                        Iterator iter = secondaryCategories.iterator();
1650:                        while (iter.hasNext()) {
1651:                            OperationCategory category = (OperationCategory) iter
1652:                                    .next();
1653:
1654:                            for (OpAction action : category.getActions()) {
1655:                                if (selection instanceof  IStructuredSelection)
1656:                                    action.updateEnablement(
1657:                                            (IStructuredSelection) selection,
1658:                                            true);
1659:                                if (action.isEnabled())
1660:                                    contextManager.add(action);
1661:                            }
1662:                            if (iter.hasNext())
1663:                                contextManager.add(new Separator());
1664:                        }
1665:
1666:                        if (getOperationMenuFactory().getActions().size() != 0) {
1667:                            contextManager.add(new Separator());
1668:                        }
1669:                        for (OpAction action : getOperationMenuFactory()
1670:                                .getActions()) {
1671:                            if (selection instanceof  IStructuredSelection)
1672:                                action.updateEnablement(
1673:                                        (IStructuredSelection) selection, true);
1674:                            if (action.isEnabled()) {
1675:                                contextManager.add(action);
1676:                            }
1677:                        }
1678:                    }
1679:
1680:                    return contextManager;
1681:                } catch (Throwable e) {
1682:                    ProjectUIPlugin.log(
1683:                            "error creating the Operations ContextMenu", e);//$NON-NLS-1$
1684:                    return new MenuManager();
1685:                }
1686:            }
1687:
1688:            private OperationMenuFactory getOperationMenuFactory() {
1689:                return UiPlugin.getDefault().getOperationMenuFactory();
1690:            }
1691:
1692:            /**
1693:             *  (non-Javadoc)
1694:             * @see net.refractions.udig.project.ui.tool.IToolManager#getActiveTool()
1695:             */
1696:            public Tool getActiveTool() {
1697:                return activeModalToolProxy.getTool();
1698:            }
1699:
1700:            /**
1701:             * Returns active tool proxy object.
1702:             * 
1703:             * @return
1704:             */
1705:            protected ToolProxy getActiveToolProxy() {
1706:                return activeModalToolProxy;
1707:            }
1708:
1709:            //    
1710:            //    static class CopyAction extends Action {
1711:            //        final Set<Transfer> transfers = UDIGDragDropUtilities.getTransfers();
1712:            //        IWorkbenchPart part;
1713:            //        public IWorkbenchPart getPart() {
1714:            //            return part;
1715:            //        }
1716:            //        public void setPart( IWorkbenchPart part ) {
1717:            //            this.part = part;
1718:            //        }
1719:            //        @Override
1720:            //        public void runWithEvent( Event event ) {
1721:            //            Clipboard clipBoard = new Clipboard(event.display);
1722:            //            try {
1723:            //                IStructuredSelection selection = (IStructuredSelection) part.getSite()
1724:            //                        .getSelectionProvider().getSelection();
1725:            //                if (selection.isEmpty())
1726:            //                    return;
1727:            //                List<Object> data = new ArrayList<Object>();
1728:            //                List<Transfer> dataTransfers = new ArrayList<Transfer>();
1729:            //                Object[] testData = new Object[1];
1730:            //                Transfer[] testTransfer = new Transfer[1];
1731:            //                for( Iterator iter = selection.iterator(); iter.hasNext(); ) {
1732:            //                    Object element = iter.next();
1733:            //                    for( Transfer transfer : transfers ) {
1734:            //                        try {
1735:            //                            testData[0] = element;
1736:            //                            testTransfer[0] = transfer;
1737:            //                            clipBoard.setContents(testData, testTransfer);
1738:            //                        } catch (Exception e) {
1739:            //                            continue;
1740:            //                        }
1741:            //                        data.add(element);
1742:            //                        dataTransfers.add(transfer);
1743:            //                    }
1744:            //                }
1745:            //                clipBoard.setContents(data.toArray(), dataTransfers
1746:            //                        .toArray(new Transfer[dataTransfers.size()]));
1747:            //            } finally {
1748:            //                clipBoard.dispose();
1749:            //            }
1750:            //
1751:            //        }
1752:            //    }
1753:
1754:            static class CopyAction extends Action {
1755:                final Set<Transfer> transfers = UDIGDragDropUtilities
1756:                        .getTransfers();
1757:                IWorkbenchPart part;
1758:
1759:                public IWorkbenchPart getPart() {
1760:                    return part;
1761:                }
1762:
1763:                public void setPart(IWorkbenchPart part) {
1764:                    this .part = part;
1765:                }
1766:
1767:                @Override
1768:                public void runWithEvent(Event event) {
1769:                    Clipboard clipBoard = new Clipboard(event.display);
1770:                    try {
1771:                        IMap map = ApplicationGIS.getActiveMap();
1772:                        if (map == null)
1773:                            return;
1774:                        ILayer selectedLayer = map.getEditManager()
1775:                                .getSelectedLayer();
1776:                        if (selectedLayer == null)
1777:                            return;
1778:
1779:                        if (selectedLayer.getFilter() == Filter.ALL) {
1780:                            return;
1781:                        }
1782:                        AdaptingFilter filter = new AdaptingFilter(
1783:                                selectedLayer.getFilter(), selectedLayer);
1784:                        clipBoard.setContents(new Object[] { filter },
1785:                                new Transfer[] { UDigByteAndLocalTransfer
1786:                                        .getInstance() });
1787:                    } finally {
1788:                        clipBoard.dispose();
1789:                    }
1790:
1791:                }
1792:            }
1793:
1794:            //    static class PasteAction extends Action {
1795:            //        IWorkbenchPart part;
1796:            //        public IWorkbenchPart getPart() {
1797:            //            return part;
1798:            //        }
1799:            //        public void setPart( IWorkbenchPart part ) {
1800:            //            this.part = part;
1801:            //        }
1802:            //        @Override
1803:            //        public void run() {
1804:            //            MapEditor activeEditor = ApplicationGISInternal.getActiveEditor();
1805:            //            Object targetObject = activeEditor;
1806:            //            IStructuredSelection selection = (IStructuredSelection) part.getSite()
1807:            //                    .getSelectionProvider().getSelection();
1808:            //            if (!selection.isEmpty()) {
1809:            //                targetObject = selection.iterator().next();
1810:            //
1811:            //            }
1812:            //            Clipboard clipboard = new Clipboard(activeEditor.getSite().getShell().getDisplay());
1813:            //            Set<Transfer> transfers = UDIGDNDProcessor.getTransfers();
1814:            //            Object contents = null;
1815:            //            for( Transfer transfer : transfers ) {
1816:            //                contents = clipboard.getContents(transfer);
1817:            //                if (contents != null)
1818:            //                    break;
1819:            //            }
1820:            //            if (contents != null) {
1821:            //                UDIGDropHandler dropHandler = activeEditor.getDropHandler();
1822:            //                dropHandler.setTarget(targetObject);
1823:            //                dropHandler.setViewerLocation(ViewerDropLocation.NONE);
1824:            //                dropHandler.performDrop(contents, null);
1825:            //            }
1826:            //        }
1827:            //    }
1828:
1829:            static class PasteAction extends Action {
1830:                IWorkbenchPart part;
1831:
1832:                public IWorkbenchPart getPart() {
1833:                    return part;
1834:                }
1835:
1836:                public void setPart(IWorkbenchPart part) {
1837:                    this .part = part;
1838:                }
1839:
1840:                @Override
1841:                public void run() {
1842:                    Clipboard clipboard = new Clipboard(part.getSite()
1843:                            .getShell().getDisplay());
1844:                    Set<Transfer> transfers = UDIGDNDProcessor.getTransfers();
1845:                    Object contents = null;
1846:                    for (Transfer transfer : transfers) {
1847:                        contents = clipboard.getContents(transfer);
1848:                        if (contents != null)
1849:                            break;
1850:                    }
1851:
1852:                    if (contents != null) {
1853:                        MapEditor activeEditor = ApplicationGISInternal
1854:                                .getActiveEditor();
1855:                        UDIGDropHandler dropHandler = activeEditor
1856:                                .getDropHandler();
1857:                        ILayer selectedLayer = activeEditor.getMap()
1858:                                .getEditManager().getSelectedLayer();
1859:                        if (selectedLayer == null) {
1860:                            dropHandler.setTarget(activeEditor.getMap());
1861:                        } else {
1862:                            dropHandler.setTarget(selectedLayer);
1863:                        }
1864:                        dropHandler.setViewerLocation(ViewerDropLocation.NONE);
1865:                        dropHandler.performDrop(contents, null);
1866:                    }
1867:                }
1868:            }
1869:
1870:            public List<ActionToolCategory> getActiveToolCategories() {
1871:                return actionCategories;
1872:            }
1873:
1874:        }
w_w__w__._j___a__va2s.__co_m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.