Source Code Cross Referenced for ToolProxy.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) 


001:        /*
002:         *    uDig - User Friendly Desktop Internet GIS client
003:         *    http://udig.refractions.net
004:         *    (C) 2004, Refractions Research Inc.
005:         *
006:         *    This library is free software; you can redistribute it and/or
007:         *    modify it under the terms of the GNU Lesser General Public
008:         *    License as published by the Free Software Foundation;
009:         *    version 2.1 of the License.
010:         *
011:         *    This library is distributed in the hope that it will be useful,
012:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         *    Lesser General Public License for more details.
015:         *
016:         */
017:        package net.refractions.udig.project.ui.internal.tool.display;
018:
019:        import java.util.ArrayList;
020:        import java.util.List;
021:        import java.util.Map;
022:        import java.util.concurrent.locks.Lock;
023:        import java.util.concurrent.locks.ReentrantLock;
024:
025:        import net.refractions.udig.internal.ui.UiPlugin;
026:        import net.refractions.udig.internal.ui.operations.OperationCategory;
027:        import net.refractions.udig.project.ui.ApplicationGIS;
028:        import net.refractions.udig.project.ui.internal.MapEditorSelectionProvider;
029:        import net.refractions.udig.project.ui.internal.Messages;
030:        import net.refractions.udig.project.ui.internal.ProjectUIPlugin;
031:        import net.refractions.udig.project.ui.tool.ActionTool;
032:        import net.refractions.udig.project.ui.tool.IMapEditorSelectionProvider;
033:        import net.refractions.udig.project.ui.tool.IToolContext;
034:        import net.refractions.udig.project.ui.tool.ModalTool;
035:        import net.refractions.udig.project.ui.tool.Tool;
036:        import net.refractions.udig.project.ui.tool.ToolConstants;
037:        import net.refractions.udig.project.ui.tool.ToolLifecycleListener;
038:        import net.refractions.udig.ui.PlatformGIS;
039:        import net.refractions.udig.ui.operations.EnablementUtil;
040:        import net.refractions.udig.ui.operations.LazyOpFilter;
041:        import net.refractions.udig.ui.operations.OpFilter;
042:
043:        import org.eclipse.core.commands.IHandler;
044:        import org.eclipse.core.runtime.CoreException;
045:        import org.eclipse.core.runtime.IConfigurationElement;
046:        import org.eclipse.core.runtime.IExtension;
047:        import org.eclipse.core.runtime.ISafeRunnable;
048:        import org.eclipse.jface.action.IAction;
049:        import org.eclipse.jface.resource.ImageDescriptor;
050:        import org.eclipse.swt.SWT;
051:        import org.eclipse.swt.custom.BusyIndicator;
052:        import org.eclipse.swt.graphics.Cursor;
053:        import org.eclipse.swt.widgets.Display;
054:        import org.eclipse.ui.PlatformUI;
055:        import org.eclipse.ui.plugin.AbstractUIPlugin;
056:
057:        /**
058:         * The tool proxy allows tools to be loaded lazily. It acts as a proxy for a tool as far as the Map
059:         * editors are concerned.
060:         * 
061:         * @author Jesse Eichar
062:         * @version $Revision: 1.9 $
063:         */
064:        public class ToolProxy extends ModalItem implements  ModalTool,
065:                ActionTool {
066:            /**
067:             * Handles lazy cursor loading.
068:             * 
069:             * @author jeichar
070:             * @since 0.9.0
071:             * 
072:             * @deprecated use {@link CursorProxy} class instead.
073:             */
074:            public static class CursorLoader {
075:
076:                private volatile Cursor cursor;
077:                private String imagePath;
078:                private String hotspotX;
079:                private String hotspotY;
080:                private String cursorId;
081:                private String pluginID;
082:
083:                /**
084:                 * Construct <code>ToolProxy.CursorLoader</code>.
085:                 */
086:                public CursorLoader(IConfigurationElement cursorDef) {
087:                    if (cursorDef != null) {
088:                        imagePath = cursorDef.getAttribute("image"); //$NON-NLS-1$
089:                        hotspotX = cursorDef.getAttribute("hotspotX"); //$NON-NLS-1$
090:                        hotspotY = cursorDef.getAttribute("hotspotY"); //$NON-NLS-1$
091:                        cursorId = cursorDef.getAttribute("id"); //$NON-NLS-1$
092:                        pluginID = cursorDef.getNamespace();
093:                    } else {
094:                        cursorId = ModalTool.DEFAULT_CURSOR;
095:                    }
096:                }
097:
098:                /**
099:                 * @return Returns the cursor.
100:                 */
101:                public Cursor getCursor() {
102:                    if (cursor == null) {
103:                        synchronized (this ) {
104:                            if (cursor == null) {
105:                                if (imagePath == null) {
106:                                    cursor = parseCursorId(cursorId);
107:                                } else {
108:                                    ImageDescriptor imageDescriptor = AbstractUIPlugin
109:                                            .imageDescriptorFromPlugin(
110:                                                    pluginID, imagePath);
111:                                    int x;
112:                                    try {
113:                                        x = Integer.parseInt(hotspotX);
114:                                    } catch (Exception e) {
115:                                        x = 0;
116:                                    }
117:                                    int y;
118:                                    try {
119:                                        y = Integer.parseInt(hotspotY);
120:                                    } catch (Exception e) {
121:                                        y = 0;
122:                                    }
123:                                    if (imageDescriptor == null
124:                                            || imageDescriptor.getImageData() == null)
125:                                        cursor = parseCursorId(cursorId);
126:                                    else
127:                                        cursor = new Cursor(Display
128:                                                .getDefault(), imageDescriptor
129:                                                .getImageData(), x, y);
130:                                }
131:                            }
132:                        }
133:                    }
134:
135:                    return cursor;
136:                }
137:
138:                Cursor parseCursorId(String cursor) {
139:                    Display display = PlatformUI.getWorkbench().getDisplay();
140:                    if (cursor == null)
141:                        return display.getSystemCursor(SWT.CURSOR_ARROW);
142:                    if (cursor.equals(ModalTool.CROSSHAIR_CURSOR))
143:                        return display.getSystemCursor(SWT.CURSOR_CROSS);
144:                    if (cursor.equals(ModalTool.E_RESIZE_CURSOR))
145:                        return display.getSystemCursor(SWT.CURSOR_SIZEE);
146:                    if (cursor.equals(ModalTool.HAND_CURSOR))
147:                        return display.getSystemCursor(SWT.CURSOR_HAND);
148:                    if (cursor.equals(ModalTool.MOVE_CURSOR))
149:                        return display.getSystemCursor(SWT.CURSOR_SIZEALL);
150:                    if (cursor.equals(ModalTool.N_RESIZE_CURSOR))
151:                        return display.getSystemCursor(SWT.CURSOR_SIZEN);
152:                    if (cursor.equals(ModalTool.NE_RESIZE_CURSOR))
153:                        return display.getSystemCursor(SWT.CURSOR_SIZENE);
154:                    if (cursor.equals(ModalTool.NW_RESIZE_CURSOR))
155:                        return display.getSystemCursor(SWT.CURSOR_SIZENW);
156:                    if (cursor.equals(ModalTool.S_RESIZE_CURSOR))
157:                        return display.getSystemCursor(SWT.CURSOR_SIZES);
158:                    if (cursor.equals(ModalTool.SE_RESIZE_CURSOR))
159:                        return display.getSystemCursor(SWT.CURSOR_SIZESE);
160:                    if (cursor.equals(ModalTool.SW_RESIZE_CURSOR))
161:                        return display.getSystemCursor(SWT.CURSOR_SIZESW);
162:                    if (cursor.equals(ModalTool.TEXT_CURSOR))
163:                        return display.getSystemCursor(SWT.CURSOR_IBEAM);
164:                    if (cursor.equals(ModalTool.W_RESIZE_CURSOR))
165:                        return display.getSystemCursor(SWT.CURSOR_SIZESW);
166:                    if (cursor.equals(ModalTool.WAIT_CURSOR))
167:                        return display.getSystemCursor(SWT.CURSOR_WAIT);
168:                    return display.getSystemCursor(SWT.CURSOR_ARROW);
169:                }
170:
171:                /**
172:                 * Dispose the cursor.
173:                 */
174:                public void dispose() {
175:                    if (cursor != null)
176:                        cursor.dispose();
177:                    cursor = null;
178:                }
179:
180:            }
181:
182:            /**
183:             * The actual tool implementation. To be lazily loaded.
184:             */
185:            Tool tool = null;
186:
187:            /**
188:             * The current tool context.
189:             */
190:            IToolContext toolContext = null;
191:
192:            /**
193:             * Configuration from extension registry for this tool.
194:             */
195:            IConfigurationElement element = null;
196:
197:            //TODO make use of this.
198:            boolean hasControl = false;
199:
200:            /*
201:             * The tool cursor ID if <code>toolCursorId</code> is specified in tool extension.
202:             */
203:            String defaultCursorID;
204:
205:            private boolean onToolbar = true;
206:            int type = -1;
207:            static final int MODAL = 1;
208:            static final int BACKGROUND = 2;
209:            static final int ACTION = 3;
210:
211:            /**
212:             * The tool category ID. It is configured in extension registry.
213:             */
214:            private String categoryId;
215:
216:            /**
217:             * The ID of the default tool: Zoom
218:             */
219:            private static final String DEFAULT_ID = "net.refractions.udig.tools.Zoom"; //$NON-NLS-1$
220:
221:            /**
222:             * The action object in UI for this tool proxy. It is lazy created.
223:             */
224:            private volatile IAction action;
225:            private String menuPath;
226:            private boolean disposed = false;
227:            private volatile IMapEditorSelectionProvider selectionProviderInstance;
228:
229:            /**
230:             * The tool manager.
231:             */
232:            private ToolManager toolManager;
233:
234:            /**
235:             * Creates an new instance of MapViewport.ToolAction
236:             * 
237:             * @param extension The Tool extension
238:             * @param tool The configuration element which describes the tool
239:             * @param newParam TODO
240:             */
241:            public ToolProxy(IExtension extension, IConfigurationElement tool,
242:                    ToolManager toolManager) {
243:                super ();
244:
245:                this .toolManager = toolManager;
246:
247:                categoryId = tool.getAttribute("categoryId"); //$NON-NLS-1$
248:                String type = tool.getName();
249:                String pluginid = extension.getNamespaceIdentifier();
250:                String id = tool.getAttribute("id"); //$NON-NLS-1$
251:                String name = tool.getAttribute("name"); //$NON-NLS-1$
252:                if (name == null)
253:                    name = Messages.ToolProxy_unnamed;
254:                String toolTip = tool.getAttribute("tooltip"); //$NON-NLS-1$
255:                String iconID = tool.getAttribute("icon"); //$NON-NLS-1$
256:
257:                defaultCursorID = tool.getAttribute("toolCursorId"); //$NON-NLS-1$
258:
259:                //FIXME For compatibility. To BE REMOVED later.
260:                if (defaultCursorID == null) {
261:                    IConfigurationElement[] children = tool
262:                            .getChildren("cursor"); //$NON-NLS-1$
263:                    if (children.length > 0) {
264:                        CursorProxy cursorProxy = new CursorProxy(children[0]);
265:                        toolManager.cursorsCache.put(cursorProxy.getID(),
266:                                cursorProxy);
267:                        defaultCursorID = cursorProxy.getID();
268:                    } else {
269:                        defaultCursorID = ModalTool.DEFAULT_CURSOR;
270:                    }
271:                }
272:
273:                OpFilter parseEnablement = EnablementUtil
274:                        .parseEnablement(
275:                                extension.getNamespaceIdentifier()
276:                                        + "." + tool.getName(), tool.getChildren("enablement")); //$NON-NLS-1$ //$NON-NLS-2$;
277:                enablement = new LazyOpFilter(this , parseEnablement);
278:                operationCategories = parseOperationCategories(tool);
279:
280:                String bool = tool.getAttribute("hasCustomControl"); //$NON-NLS-1$
281:                hasControl = ((bool != null) && bool.equalsIgnoreCase("true")) ? true : false; //$NON-NLS-1$
282:                bool = tool.getAttribute("onToolbar"); //$NON-NLS-1$
283:                onToolbar = ((bool != null) && bool.equalsIgnoreCase("true")) ? true : false; //$NON-NLS-1$
284:                menuPath = tool.getAttribute("menuPath"); //$NON-NLS-1$
285:                ImageDescriptor icon;
286:                if (iconID == null) {
287:                    icon = null;
288:                } else {
289:                    icon = AbstractUIPlugin.imageDescriptorFromPlugin(pluginid,
290:                            iconID);
291:                }
292:                setImageDescriptor(icon);
293:
294:                this .element = tool;
295:                setName(name);
296:                setToolTipText(toolTip);
297:                setId(id);
298:                if (type.equals("modalTool")) //$NON-NLS-1$
299:                    this .type = MODAL;
300:                else if (type.equals("backgroundTool")) //$NON-NLS-1$
301:                    this .type = BACKGROUND;
302:                else if (type.equals("actionTool")) //$NON-NLS-1$
303:                    this .type = ACTION;
304:                handlerType = tool.getAttribute(HandlerProxy.ID);
305:
306:                String unparsedCommandIds = tool.getAttribute("commandIds"); //$NON-NLS-1$
307:                if (unparsedCommandIds != null
308:                        && unparsedCommandIds.length() > 0)
309:                    commandIds = unparsedCommandIds.split(","); //$NON-NLS-1$
310:                else
311:                    commandIds = new String[0];
312:
313:                if (id.equals(DEFAULT_ID)) {
314:                    toolManager.defaultModalToolProxy = this ;
315:                }
316:            }
317:
318:            private List<OperationCategory> parseOperationCategories(
319:                    IConfigurationElement toolElement) {
320:                IConfigurationElement[] children = toolElement
321:                        .getChildren("operationCategory"); //$NON-NLS-1$
322:
323:                if (children == null || children.length == 0) {
324:                    return null;
325:                }
326:
327:                Map<String, OperationCategory> categories = UiPlugin
328:                        .getDefault().getOperationMenuFactory().getCategories();
329:                ArrayList<OperationCategory> results = new ArrayList<OperationCategory>();
330:
331:                for (IConfigurationElement element : children) {
332:                    String opCategoryID = element.getAttribute("categoryID"); //$NON-NLS-1$
333:
334:                    if (opCategoryID == null || opCategoryID.length() == 0) {
335:                        ProjectUIPlugin
336:                                .log(
337:                                        "Warning: CategoryID attribute of operationCategory element in tool '" + id + "' is empty.", null); //$NON-NLS-1$ //$NON-NLS-2$
338:                        continue;
339:                    }
340:
341:                    OperationCategory opCategory = categories.get(opCategoryID);
342:                    if (opCategory == null) {
343:                        ProjectUIPlugin
344:                                .log(
345:                                        "Warning: CategoryID attribute of operationCategory element in tool '" + id + "' cannot be found. Does it actually exist?", null); //$NON-NLS-1$ //$NON-NLS-2$
346:                        continue;
347:                    }
348:
349:                    results.add(opCategory);
350:                }
351:                return results;
352:            }
353:
354:            CursorLoader parseCursor(IConfigurationElement toolDef) {
355:
356:                // should only be one
357:                IConfigurationElement[] children = toolDef
358:                        .getChildren("cursor"); //$NON-NLS-1$
359:
360:                return new CursorLoader(children.length > 0 ? children[0]
361:                        : null);
362:
363:            }
364:
365:            /**
366:             * @see org.eclipse.jface.action.Action#getStyle()
367:             */
368:            public int getStyle() {
369:                if (type == MODAL)
370:                    return IAction.AS_RADIO_BUTTON;
371:                return IAction.AS_PUSH_BUTTON;
372:            }
373:
374:            /**
375:             * @see net.refractions.udig.project.ui.tool.Tool#setContext(net.refractions.udig.project.ui.tool.IToolContext)
376:             */
377:            public void setContext(IToolContext toolContext) {
378:                this .toolContext = toolContext;
379:
380:                if (type == BACKGROUND) {
381:                    getTool().setContext(toolContext);
382:
383:                } else if (type == MODAL
384:                        && toolManager.activeModalToolProxy == this ) {
385:                    ModalTool modalTool = getModalTool();
386:
387:                    modalTool.setContext(toolContext);
388:                    String currentCursorID = modalTool.getCursorID();
389:                    toolContext.getViewportPane().setCursor(
390:                            ApplicationGIS.getToolManager().findToolCursor(
391:                                    currentCursorID));
392:
393:                } else if (tool != null) {
394:                    getTool().setContext(toolContext);
395:                }
396:            }
397:
398:            /**
399:             * @see java.lang.Object#toString()
400:             */
401:            public String toString() {
402:                return getId();
403:            }
404:
405:            ModalTool getModalTool() {
406:                return (ModalTool) getTool();
407:            }
408:
409:            ActionTool getModelessTool() {
410:                return (ActionTool) getTool();
411:            }
412:
413:            /**
414:             * Returns proxy
415:             * 
416:             * @return
417:             */
418:            public Tool getTool() {
419:                if (tool == null) {
420:                    Display display = Display.getCurrent();
421:                    if (display == null)
422:                        display = Display.getDefault();
423:                    final Display finalDisplay = display;
424:                    Runnable runnable = new Runnable() {
425:                        public void run() {
426:                            BusyIndicator.showWhile(finalDisplay,
427:                                    new Runnable() {
428:                                        public void run() {
429:                                            String klassName = element
430:                                                    .getAttribute("class"); //$NON-NLS-1$
431:                                            if (klassName != null) {
432:                                                try {
433:                                                    Object o = element
434:                                                            .createExecutableExtension("class"); //$NON-NLS-1$
435:                                                    tool = (Tool) o;
436:
437:                                                    /* Tool cursors framework */
438:                                                    if (tool instanceof  ModalTool) {
439:                                                        if (defaultCursorID != null) {
440:                                                            ((ModalTool) tool)
441:                                                                    .setCursorID(defaultCursorID);
442:                                                            tool
443:                                                                    .setProperty(
444:                                                                            ToolConstants.DEFAULT_CURSOR_ID_KEY,
445:                                                                            defaultCursorID);
446:                                                        }
447:                                                    }
448:
449:                                                    tool
450:                                                            .setContext(toolContext);
451:                                                    tool
452:                                                            .setEnabled(isEnabled());
453:
454:                                                    if (tool instanceof  ModalTool) {
455:                                                        IMapEditorSelectionProvider selectionProvider = getSelectionProvider();
456:                                                        ((ModalTool) tool)
457:                                                                .setSelectionProvider(selectionProvider);
458:                                                    }
459:
460:                                                } catch (CoreException e) {
461:                                                    ProjectUIPlugin
462:                                                            .log(
463:                                                                    "Error loading tool", e); //$NON-NLS-1$
464:                                                }
465:                                            }
466:
467:                                        }
468:                                    });
469:                        }
470:                    };
471:
472:                    PlatformGIS.syncInDisplayThread(runnable);
473:                }
474:                return tool;
475:            }
476:
477:            /**
478:             * @return Returns the type.
479:             */
480:            public int getType() {
481:                return type;
482:            }
483:
484:            /**
485:             * If the current action is a ActionTool then the menu path of the tool action is returned
486:             * 
487:             * @return the menu path of the tool action or null if the current tool is not an ActionTool.
488:             */
489:            public String getMenuPath() {
490:                return menuPath;
491:            }
492:
493:            /**
494:             * @return Returns the onToolbar.
495:             */
496:            public boolean isOnToolbar() {
497:                return onToolbar;
498:            }
499:
500:            /**
501:             * @see net.refractions.udig.project.ui.tool.Tool#getContext()
502:             */
503:            public IToolContext getContext() {
504:                return toolContext;
505:            }
506:
507:            /**
508:             * Returns ID of tool category from  extention registry.
509:             * 
510:             * @return
511:             */
512:            public String getCategoryId() {
513:                return categoryId;
514:            }
515:
516:            /**
517:             * Creates an action that will run the tool referenced by this proxy
518:             * 
519:             * @return an action that will run the tool referenced by this proxy
520:             */
521:            public IAction getAction() {
522:                if (action == null) {
523:                    synchronized (this ) {
524:                        if (action == null) {
525:                            action = new ToolAction(this );
526:                        }
527:                        action.setEnabled(isEnabled());
528:                    }
529:                }
530:                return action;
531:            }
532:
533:            /**
534:             *  (non-Javadoc)
535:             * @see net.refractions.udig.project.ui.tool.Tool#isEnabled()
536:             */
537:            @Override
538:            public boolean isEnabled() {
539:                if (tool == null)
540:                    return super .isEnabled();
541:
542:                return tool.isEnabled();
543:            }
544:
545:            Lock enabledLock = new ReentrantLock(true);
546:
547:            /**
548:             *  (non-Javadoc)
549:             * @see net.refractions.udig.project.ui.tool.ModalTool#setEnabled(boolean)
550:             */
551:            @Override
552:            public void setEnabled(final boolean enabled) {
553:                PlatformGIS.syncInDisplayThread(new Runnable() {
554:                    public void run() {
555:                        toolProxySetEnabled(enabled);
556:                    }
557:                });
558:            }
559:
560:            protected void toolProxySetEnabled(boolean enabled) {
561:                enabledLock.lock();
562:                try {
563:
564:                    super .setEnabled(enabled);
565:
566:                    if (tool != null) {
567:                        tool.setEnabled(enabled);
568:                    }
569:
570:                    if (action != null)
571:                        action.setEnabled(enabled);
572:                } finally {
573:                    enabledLock.unlock();
574:                }
575:            }
576:
577:            /** 
578:             * (non-Javadoc)
579:             * @see net.refractions.udig.project.ui.tool.ActionTool#run()
580:             */
581:            @Override
582:            public void run() {
583:                if (runModeless() && isEnabled)
584:                    return;
585:
586:                PlatformGIS.syncInDisplayThread(new Runnable() {
587:                    public void run() {
588:                        enableModalTool();
589:                    }
590:                });
591:            }
592:
593:            private void enableModalTool() {
594:                ToolProxy activeToolProxy = (ToolProxy) getActiveItem();
595:                if (activeToolProxy != null)
596:                    activeToolProxy.setActive(false);
597:
598:                setActive(true);
599:                setActiveItem(this );
600:            }
601:
602:            /**
603:             * @see net.refractions.udig.project.ui.internal.tool.display.ModalItem#runModeless()
604:             */
605:            protected boolean runModeless() {
606:                if (type == ACTION) {
607:                    PlatformGIS.run(new ISafeRunnable() {
608:
609:                        public void run() throws Exception {
610:                            getModelessTool().run();
611:                        }
612:
613:                        public void handleException(Throwable exception) {
614:                            ProjectUIPlugin
615:                                    .log(
616:                                            "Error occured while executing tool: " + getId(), exception); //$NON-NLS-1$
617:                        }
618:
619:                    });
620:                    return true;
621:                }
622:
623:                return false;
624:            }
625:
626:            /**
627:             * @see net.refractions.udig.project.ui.internal.tool.display.ModalItem#setActive(boolean)
628:             */
629:            public void setActive(boolean active) {
630:                if (toolContext == null)
631:                    return;
632:
633:                setChecked(active);
634:
635:                if (getTool() instanceof  ModalTool) {
636:                    ModalTool modalTool = (ModalTool) getTool();
637:
638:                    getModalTool().setActive(active);
639:
640:                    if (active) {
641:                        String currentCursorID = modalTool.getCursorID();
642:                        toolContext.getViewportPane().setCursor(
643:                                ApplicationGIS.getToolManager().findToolCursor(
644:                                        currentCursorID));
645:                    }
646:                }
647:            }
648:
649:            /**
650:             * @see net.refractions.udig.project.ui.internal.tool.display.ModalItem#dispose()
651:             */
652:            public void dispose() {
653:                disposed = true;
654:                if (tool != null) {
655:                    tool.dispose();
656:                }
657:
658:                //        if (this == toolManager.activeModalToolProxy)
659:                //        	toolManager.activeModalToolProxy = null;
660:
661:            }
662:
663:            /**
664:             * @see net.refractions.udig.project.ui.internal.tool.display.ModalItem#getHandler(java.lang.String)
665:             */
666:            public IHandler getHandler(String commandId) {
667:                if (handlerType != null && handlerType.length() > 0)
668:                    return new HandlerProxy(element, this , commandId);
669:                return null;
670:            }
671:
672:            /**
673:             * @see net.refractions.udig.project.ui.internal.tool.display.ModalItem#getDefaultItem()
674:             */
675:            protected ModalItem getDefaultItem() {
676:                return toolManager.defaultModalToolProxy;
677:            }
678:
679:            /**
680:             * @see net.refractions.udig.project.ui.internal.tool.display.ModalItem#getActiveItem()
681:             */
682:            protected ModalItem getActiveItem() {
683:                return toolManager.activeModalToolProxy;
684:            }
685:
686:            /**
687:             * @see net.refractions.udig.project.ui.internal.tool.display.ModalItem#setActiveItem(net.refractions.udig.project.ui.internal.tool.display.ModalItem)
688:             */
689:            protected void setActiveItem(ModalItem modalItem) {
690:                toolManager.activeModalToolProxy = (ToolProxy) modalItem;
691:            }
692:
693:            /** (non-Javadoc)
694:             * @see net.refractions.udig.project.ui.tool.ModalTool#isActive()
695:             */
696:            public boolean isActive() {
697:                return getModalTool().isActive();
698:            }
699:
700:            @Override
701:            public boolean isDisposed() {
702:                return disposed;
703:            }
704:
705:            private Lock selectionProviderLock = new ReentrantLock();
706:
707:            public IMapEditorSelectionProvider getSelectionProvider() {
708:                if (selectionProviderInstance == null) {
709:                    selectionProviderLock.lock();
710:                    try {
711:                        if (selectionProviderInstance != null) {
712:                            return selectionProviderInstance;
713:                        }
714:                        if (element.getAttribute("selectionProvider") != null) { //$NON-NLS-1$
715:                            try {
716:                                selectionProviderInstance = (IMapEditorSelectionProvider) element
717:                                        .createExecutableExtension("selectionProvider"); //$NON-NLS-1$
718:                            } catch (CoreException e) {
719:                                ProjectUIPlugin
720:                                        .log(
721:                                                "Error instantiating selection provider for " + element.getNamespace() + "/" + element.getName(), e); //$NON-NLS-1$//$NON-NLS-2$
722:                            }
723:                            if (selectionProviderInstance != null)
724:                                return selectionProviderInstance;
725:                        }
726:                        ToolManager m = (ToolManager) ApplicationGIS
727:                                .getToolManager();
728:                        ModalToolCategory cat = m
729:                                .findModalCategory(getCategoryId());
730:                        if (cat != null)
731:                            selectionProviderInstance = cat
732:                                    .getSelectionProvider();
733:                        else
734:                            selectionProviderInstance = new MapEditorSelectionProvider();
735:                    } finally {
736:                        selectionProviderLock.unlock();
737:                    }
738:                }
739:                return selectionProviderInstance;
740:            }
741:
742:            /** (non-Javadoc)
743:             * @see net.refractions.udig.project.ui.tool.ModalTool#getCursorID()
744:             */
745:            public String getCursorID() {
746:                throw new UnsupportedOperationException(
747:                        "Call ToolProxy.getTool().getCursorID() method instead"); //$NON-NLS-1$
748:            }
749:
750:            /**
751:             * Empty implementation
752:             * 
753:             * @see net.refractions.udig.project.ui.tool.ModalTool#setCursorID(java.lang.String)
754:             */
755:            public void setCursorID(String id) {
756:                throw new UnsupportedOperationException(
757:                        "Call ToolProxy.getTool().setCursorID(String) method instead"); //$NON-NLS-1$
758:            }
759:
760:            /** (non-Javadoc)
761:             * @see net.refractions.udig.project.ui.tool.Tool#getProperty(java.lang.String)
762:             */
763:            public Object getProperty(String key) {
764:                throw new UnsupportedOperationException(
765:                        "Call ToolProxy.getTool().getProperty(String) method instead"); //$NON-NLS-1$
766:            }
767:
768:            /** (non-Javadoc)
769:             * @see net.refractions.udig.project.ui.tool.Tool#setProperty(java.lang.String, java.lang.Object)
770:             */
771:            public void setProperty(String key, Object value) {
772:                throw new UnsupportedOperationException(
773:                        "Call ToolProxy.getTool().setProperty(String, String) method instead"); //$NON-NLS-1$
774:
775:            }
776:
777:            public void addListener(ToolLifecycleListener listener) {
778:                throw new UnsupportedOperationException(
779:                        "Call ToolProxy.getTool().addListener(ToolLifecycleListener) method instead"); //$NON-NLS-1$
780:
781:            }
782:
783:            public void removeListener(ToolLifecycleListener listener) {
784:                throw new UnsupportedOperationException(
785:                        "Call ToolProxy.getTool().removeListener(ToolLifecycleListener) method instead"); //$NON-NLS-1$
786:            }
787:
788:            public void notifyResultObtained(boolean result) {
789:                setEnabled(result);
790:            }
791:
792:            public void setSelectionProvider(
793:                    IMapEditorSelectionProvider selectionProvider) {
794:                throw new UnsupportedOperationException(
795:                        "Call ToolProxy.getTool().setSelectionProvider(IMapEditorSelectionProvider) method instead"); //$NON-NLS-1$
796:
797:            }
798:
799:        }
w_w__w__.ja__v_a__2__s__.___c___o___m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.