diff --git a/plugins/org.locationtech.udig.project.ui/src/org/locationtech/udig/project/ui/internal/tool/display/ToolManager.java b/plugins/org.locationtech.udig.project.ui/src/org/locationtech/udig/project/ui/internal/tool/display/ToolManager.java index ba7d80e20..6485a1344 100644 --- a/plugins/org.locationtech.udig.project.ui/src/org/locationtech/udig/project/ui/internal/tool/display/ToolManager.java +++ b/plugins/org.locationtech.udig.project.ui/src/org/locationtech/udig/project/ui/internal/tool/display/ToolManager.java @@ -69,12 +69,10 @@ import org.eclipse.ui.IWorkbenchPartSite; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.SubActionBars2; import org.eclipse.ui.actions.ActionFactory; import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction; import org.eclipse.ui.commands.ICommandService; import org.eclipse.ui.dialogs.PropertyDialogAction; -import org.eclipse.ui.part.ViewPart; import org.locationtech.udig.catalog.IGeoResource; import org.locationtech.udig.core.filter.AdaptingFilter; import org.locationtech.udig.core.filter.AdaptingFilterFactory; @@ -123,7 +121,7 @@ /** * Manages Edit tools activation and registration. *

- * The tool manager is a used by the MapEditor to populate the + * The tool manager is used by the MapEditor to populate the * menu and action bars. It is responsible for processing the tools * extension point and making action contributions as needed. *

@@ -138,6 +136,9 @@ * @since 0.6.0 */ public class ToolManager implements IToolManager { + + private static final boolean FT_ACTION_TOOL_PREF_LINKS = true; + /** * This is a list of all tool actions(buttons) that are not part of the editor toolbar. For * example the info view may have a tool as part of its toolbar which is a proxy for the real @@ -170,10 +171,10 @@ public class ToolManager implements IToolManager { */ List backgroundTools = new LinkedList(); /** - * Shared images assoicated with these tools; used for everything from + * Shared images associated with these tools; used for everything from * cursors to button icons. */ - ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages(); + ISharedImages sharedImages; /** * Cache of all configured cursors. @@ -240,6 +241,16 @@ public ToolManager() { setCommandHandlers(); } + /** + * Retrieves shared images lazily from workbench. + */ + private ISharedImages getSharedImages() { + if (sharedImages == null) { + sharedImages = PlatformUI.getWorkbench().getSharedImages(); + } + return sharedImages; + } + /** * Populates the categories with their associated tools */ @@ -345,7 +356,7 @@ public ToolProxy findToolProxy(String toolID) { } for(ToolProxy item : backgroundTools){ if(toolID.equals(item.getId())){ - return (ToolProxy)item; + return item; } } return null; @@ -472,13 +483,13 @@ private void removeEmptyCategories() { } menuCategories.removeAll(toRemove); } + /** * Register commands handlers; so they can be used by the keyboard short cut system. */ private void setCommandHandlers() { Set ids = new HashSet(); - ICommandService service = (ICommandService) PlatformUI.getWorkbench().getAdapter( - ICommandService.class); + ICommandService service = PlatformUI.getWorkbench().getAdapter(ICommandService.class); for( ModalToolCategory category : modalCategories ) { if (!ids.contains(category.getId())) { ids.add(category.getId()); @@ -539,21 +550,19 @@ public void setCurrentEditor( MapPart editor ) { return; } currentEditor = editor; - if (editor != null) { - if (editor != null) { - setActiveTool(editor); - setEnabled(editor.getMap(), actionCategories); - setEnabled(editor.getMap(), menuCategories); - setEnabled(editor.getMap(), modalCategories); - } + if (editor != null && editor.getMap() != null) { + setActiveTool(editor); + setEnabled(editor.getMap(), actionCategories); + setEnabled(editor.getMap(), menuCategories); + setEnabled(editor.getMap(), modalCategories); } else { disable(actionCategories); disable(menuCategories); disable(modalCategories); } - } + /** * Churn through the category disabling all tools. * @@ -598,6 +607,7 @@ public void changed( EditManagerEvent event ) { } } } + /** * Heads through the categories giving each tool a chance to enable/disable itself. *

@@ -656,32 +666,31 @@ public void run() { *

* @param editor MapEditor associated with the support view (such as the Layers view) */ - @SuppressWarnings("unchecked") void setActiveTool( MapPart editor ) { // ensure we are listening to this MapPart's Map Map map = editor.getMap(); Adapter listener = getCommandListener(editor); - if (!map.eAdapters().contains(listener)){ + if (map.eAdapters() != null && !map.eAdapters().contains(listener)) { map.eAdapters().add(listener); } // Define the tool context allowing tools to interact with this map - ToolContext tools = new ToolContextImpl(); - tools.setMapInternal(map); + ToolContext toolContext = new ToolContextImpl(); + toolContext.setMapInternal(map); // Provide each tool with the new tool context // - setContext(modalCategories, tools); // if active a modal tool is supposed to register listeners - setContext(actionCategories, tools); - setContext(menuCategories, tools); - for( ToolProxy tool : backgroundTools ) { - tool.setContext(tools); + setContext(modalCategories, toolContext); // if active a modal tool is supposed to register listeners + setContext(actionCategories, toolContext); + setContext(menuCategories, toolContext); + for (ToolProxy tool : backgroundTools) { + tool.setContext(toolContext); } - for( IAction action : registeredToolActions){ + for (IAction action : registeredToolActions) { action.setEnabled(true); } - setCommandActions(map, editor); + setCommandActions(map); // wire in the current activeModalTool if( activeModalToolProxy != null ){ @@ -690,10 +699,14 @@ void setActiveTool( MapPart editor ) { if( activeTool == null ){ activeTool = activeModalToolProxy.getModalTool(); // add tool options to the status area - initToolOptionsContribution(editor.getStatusLineManager(), activeModalToolProxy); + if (FT_ACTION_TOOL_PREF_LINKS) { + initToolOptionsContribution(editor.getStatusLineManager(), + activeModalToolProxy); + } } activeModalToolProxy.getModalTool().setActive(true); } + activeModalToolProxy.setChecked(true); editor.setSelectionProvider(activeModalToolProxy.getSelectionProvider()); if( editor instanceof MapEditorWithPalette){ // temporary cast while we sort out if MapPart can own an MapEditDomain @@ -704,6 +717,7 @@ void setActiveTool( MapPart editor ) { } } + /** * Go through List of ToolCategory and update each Tool with the new tool context. * @param categories @@ -770,6 +784,7 @@ public final ActionToolCategory findActionCategory( String id ) { } return null; } + @Override public final MenuToolCategory findMenuCategory( String id ) { for( MenuToolCategory category : menuCategories ) { @@ -778,6 +793,7 @@ public final MenuToolCategory findMenuCategory( String id ) { } return null; } + @Override public final ModalToolCategory findModalCategory( String id ) { for( ModalToolCategory category : modalCategories ) { @@ -896,17 +912,13 @@ public void run() { activeMap.redo(); } }; - redoAction.setImageDescriptor(sharedImages - .getImageDescriptor(ISharedImages.IMG_TOOL_REDO)); + redoAction.setImageDescriptor( + getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_REDO)); redoAction.setText(Messages.ToolManager_redoAction); redoAction.setActionDefinitionId("org.eclipse.ui.edit.redo"); //$NON-NLS-1$ } - if (activeMap != ApplicationGIS.NO_MAP) - redoAction.setEnabled(activeMap.getCommandStack().canRedo()); - else - redoAction.setEnabled(false); - - return redoAction; + setActionEnabledState(activeMap, redoAction, true); + return redoAction; }finally{ redoLock.unlock(); } @@ -930,6 +942,7 @@ public void setREDOAction( IAction action, IWorkbenchPart part ) { redoLock.unlock(); } } + /** * Retrieves the undo action that is used by much of the map components such as the MapEditor * and the LayersView. Undoes the last command sent to the currently active map. @@ -951,15 +964,12 @@ public void run() { activeMap.undo(); } }; - undoAction.setImageDescriptor(sharedImages - .getImageDescriptor(ISharedImages.IMG_TOOL_UNDO)); + undoAction.setImageDescriptor( + getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_UNDO)); undoAction.setText(Messages.ToolManager_undoAction); undoAction.setActionDefinitionId("org.eclipse.ui.edit.undo"); //$NON-NLS-1$ } - if (activeMap != ApplicationGIS.NO_MAP) - undoAction.setEnabled(activeMap.getCommandStack().canUndo()); - else - undoAction.setEnabled(false); + setActionEnabledState(activeMap, undoAction, false); return undoAction; }finally{ undoLock.unlock(); @@ -984,6 +994,7 @@ public void setUNDOAction( IAction action, IWorkbenchPart part ) { undoLock.unlock(); } } + /** * Retrieves the forward navigation action that is used by much of the map components such as * the MapEditor and the LayersView. Executes the last undone Nav command on the current map. @@ -1003,16 +1014,13 @@ public void run() { activeMap.forwardHistory(); } }; - forwardAction.setImageDescriptor(sharedImages - .getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD)); + forwardAction.setImageDescriptor( + getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD)); forwardAction.setText(Messages.ToolManager_forward); forwardAction.setToolTipText(Messages.ToolManager_forward_tooltip); forwardAction.setActionDefinitionId("org.eclipse.ui.navigate.forward"); //$NON-NLS-1$ } - if (activeMap != ApplicationGIS.NO_MAP) - forwardAction.setEnabled(activeMap.getCommandStack().canRedo()); - else - forwardAction.setEnabled(false); + setNavActionEnabledState(activeMap, forwardAction, true); return forwardAction; }finally{ forwardLock.unlock(); @@ -1020,6 +1028,24 @@ public void run() { } + private void setActionEnabledState(Map activeMap, IAction action, boolean isRedoAction) { + if (activeMap != null && activeMap != ApplicationGIS.NO_MAP) { + action.setEnabled(isRedoAction ? activeMap.getCommandStack().canRedo() + : activeMap.getCommandStack().canUndo()); + } else { + action.setEnabled(false); + } + } + + private void setNavActionEnabledState(Map activeMap, IAction action, boolean isForwardAction) { + if (activeMap != null && activeMap != ApplicationGIS.NO_MAP) { + action.setEnabled(isForwardAction ? activeMap.getNavCommandStack().hasForwardHistory() + : activeMap.getNavCommandStack().hasBackHistory()); + } else { + action.setEnabled(false); + } + } + /** * */ @@ -1092,21 +1118,17 @@ public void run() { } }; - backwardAction.setImageDescriptor(sharedImages - .getImageDescriptor(ISharedImages.IMG_TOOL_BACK)); + backwardAction.setImageDescriptor( + getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_BACK)); backwardAction.setText(Messages.ToolManager_back); backwardAction.setToolTipText(Messages.ToolManager_back_tooltip); backwardAction.setActionDefinitionId("org.eclipse.ui.navigate.back"); //$NON-NLS-1$ } - if (activeMap != ApplicationGIS.NO_MAP) - backwardAction.setEnabled(activeMap.getCommandStack().canUndo()); - else - backwardAction.setEnabled(false); + setNavActionEnabledState(activeMap, backwardAction, false); + return backwardAction; }finally{ backwardLock.unlock(); } - - return backwardAction; } /** @@ -1201,6 +1223,7 @@ public void setCOPYAction( IAction action, IWorkbenchPart part ) { copyLock.unlock(); } } + // public IAction getPropertiesAction( IWorkbenchPart part, ISelectionProvider selectionProvider ) { propertiesLock.lock(); @@ -1390,6 +1413,21 @@ public void contributeToCoolBar( SubCoolBarManager cbmanager, IActionBars bars ) createModalToolToolbar(cbmanager); } + @Override + public void contributeTools(IToolBarManager toolBarManager, IActionBars bars) { + toolBarManager.add(getBACKWARD_HISTORYAction()); + toolBarManager.add(getFORWARD_HISTORYAction()); + for (String id : categoryIds) { + ActionToolCategory actionCategory = findActionCategory(id); + if (actionCategory != null) + actionCategory.contribute(toolBarManager); + ModalToolCategory modalCategory = findModalCategory(id); + if (modalCategory != null) { + modalCategory.contribute(toolBarManager); + } + } + } + /* (non-Javadoc) * @see org.locationtech.udig.project.ui.tool.IToolManager#contributeActionTools(org.eclipse.jface.action.IToolBarManager, org.eclipse.ui.IActionBars) */ @@ -1415,22 +1453,6 @@ public void contributeModalTools(IToolBarManager toolBarManager, IActionBars bar } } - SubActionBars2 getActionBars() { - if (ApplicationGISInternal.getActiveMap() == ApplicationGIS.NO_MAP) - return null; - MapPart active = ApplicationGISInternal.getActiveEditor(); - - if( active instanceof MapEditorPart){ - MapEditorPart editor = (MapEditorPart) active; - return (SubActionBars2) editor.getMapEditorSite().getActionBars(); - } - else if( active instanceof ViewPart){ - ViewPart view = (ViewPart) active; - return (SubActionBars2) view.getViewSite().getActionBars(); - } - return null; - } - private IAction actionCLOSE; private IAction actionSAVE; private IAction actionCLOSE_ALL; @@ -1473,25 +1495,6 @@ public void contributeGlobalActions( IWorkbenchPart part, IActionBars bars ) { } - void dispose() { - for( ToolCategory category : modalCategories ) { - category.dispose(ApplicationGISInternal.getActiveEditor().getMapEditorSite() - .getActionBars()); - } - for( ToolCategory category : actionCategories ) { - category.dispose(ApplicationGISInternal.getActiveEditor().getMapEditorSite() - .getActionBars()); - } - for( ToolCategory category : menuCategories ) { - category.dispose(ApplicationGISInternal.getActiveEditor().getMapEditorSite() - .getActionBars()); - } - for( ToolProxy tool : backgroundTools ) { - tool.dispose(); - } - - } - Adapter getCommandListener( final MapPart editor ) { if (commandListener == null) { commandListener = new AdapterImpl(){ @@ -1508,11 +1511,11 @@ public void notifyChanged( Notification msg ) { switch( msg.getFeatureID(msg.getNotifier().getClass()) ) { case ProjectPackage.MAP__COMMAND_STACK: map = (Map) msg.getNotifier(); - setCommandActions(map, editor); + setCommandActions(map); break; case ProjectPackage.MAP__NAV_COMMAND_STACK: map = (Map) msg.getNotifier(); - setCommandActions(map, editor); + setCommandActions(map); break; } @@ -1521,33 +1524,19 @@ public void notifyChanged( Notification msg ) { } return commandListener; } + /** - * Hook up the usual actions (UNDO,REDO,BACKWARDS_HISTORY,FORWARD_HISTORY) to the provided + * Hook up the usual actions (UNDO,REDO,BACKWARD_HISTORY,FORWARD_HISTORY) to the provided * editor. * * @param map * @param editor */ - void setCommandActions( Map map, MapPart editor ) { - if (map.getCommandStack().canRedo()) - getREDOAction().setEnabled(true); - else - getREDOAction().setEnabled(false); - - if (map.getCommandStack().canUndo()) - getUNDOAction().setEnabled(true); - else - getUNDOAction().setEnabled(false); - - if (map.getNavCommandStack().hasBackHistory()) - getBACKWARD_HISTORYAction().setEnabled(true); - else - getBACKWARD_HISTORYAction().setEnabled(false); - - if (map.getNavCommandStack().hasForwardHistory()) - getFORWARD_HISTORYAction().setEnabled(true); - else - getFORWARD_HISTORYAction().setEnabled(false); + void setCommandActions(Map map) { + setActionEnabledState(map, getREDOAction(), true); + setActionEnabledState(map, getUNDOAction(), false); + setNavActionEnabledState(map, getBACKWARD_HISTORYAction(), false); + setNavActionEnabledState(map, getFORWARD_HISTORYAction(), true); } public IAction getTool( String toolID, String categoryID ) { @@ -1763,36 +1752,46 @@ private static class CategorySorter implements Comparator, Serializable /** long serialVersionUID field */ private static final long serialVersionUID = 1L; - private static final java.util.Map values = new HashMap(); + private static final java.util.Map values = new HashMap(); static { - values.put(ToolConstants.RENDER_CA, 5); - values.put(ToolConstants.ZOOM_CA, 4); - values.put(ToolConstants.PAN_CA, 3); - values.put(ToolConstants.SELECTION_CA, 2); - values.put(ToolConstants.INFO_CA, 1); - values.put(ToolConstants.EDIT_CA, 0); - } - - private static final int max = -1; - private static final int min = 1; + values.put(ToolConstants.RENDER_CA, "0100"); + values.put(ToolConstants.ZOOM_CA, "0200"); + values.put(ToolConstants.PAN_CA, "0300"); + values.put(ToolConstants.SELECTION_CA, "0400"); + values.put(ToolConstants.INFO_CA, "0500"); + values.put(ToolConstants.EDIT_CA, "0600"); + values.put(ToolConstants.TOOL_EDIT_CA, "0700"); + values.put(ToolConstants.TOOL_CREATE_CA, "0800"); + values.put(ToolConstants.TOOL_FEATURE_CA, "0900"); + } + + private static final int MAX = -1; + private static final int MIN = 1; /** * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) */ - public int compare( String arg0, String arg1 ) { - Integer value0 = values.get(arg0); - Integer value1 = values.get(arg1); - if (value0 == null && value1 == null) - return 0; - if (value1 == null) - return max; - if (value0 == null ) - return min; - if (value0.equals(value1)) + public int compare(String arg0, String arg1) { + arg0 = getOrDefault(values, arg0, "") + arg0; + arg1 = getOrDefault(values, arg1, "") + arg1; + if (arg0.equals(arg1)) return 0; + if (arg1.isEmpty() || arg1.equals(Messages.ToolCategory_other)) + return MAX; + if (arg0.isEmpty() || arg0.equals(Messages.ToolCategory_other)) + return MIN; - return value0.intValue() > value1.intValue() ? max : min; + return arg0.compareTo(arg1); } + private String getOrDefault(java.util.Map map, String key, + String defaultValue) { + String value = map.get(key); + if (value == null) { + return defaultValue; + } else { + return value; + } + } } /** @@ -1911,23 +1910,33 @@ public ToolProxy getActiveToolProxy(){ * * @param activeModalToolProxy */ - public void setActiveModalToolProxy(ToolProxy modalToolProxy) { - if( modalToolProxy == null ){ - // we will have to use the default then - modalToolProxy = defaultModalToolProxy; - } - if(activeModalToolProxy != null && activeModalToolProxy.getId() == modalToolProxy.getId() ){ - return; // no change required - } - this.activeModalToolProxy = modalToolProxy; + public void setActiveModalToolProxy(ToolProxy modalToolProxy) { + if (modalToolProxy == null) { + // we will have to use the default then + modalToolProxy = defaultModalToolProxy; + } - // connect the tools to the map area - setActiveModalTool( modalToolProxy.getModalTool() ); - currentEditor.setSelectionProvider(modalToolProxy.getSelectionProvider()); + // this is still the old ToolProxy + if (activeModalToolProxy != null) { + if (activeModalToolProxy.getId() == modalToolProxy.getId()) { + return; // no change required + } + activeModalToolProxy.setChecked(false); + } - // add tool options to the status area - initToolOptionsContribution(currentEditor.getStatusLineManager(), getActiveToolProxy()); - } + // and now for the new ToolProxy + activeModalToolProxy = modalToolProxy; + activeModalToolProxy.setChecked(true); + + // connect the tools to the map area + setActiveModalTool(modalToolProxy.getModalTool()); + currentEditor.setSelectionProvider(modalToolProxy.getSelectionProvider()); + + // add tool options to the status area + if (FT_ACTION_TOOL_PREF_LINKS) { + initToolOptionsContribution(currentEditor.getStatusLineManager(), getActiveToolProxy()); + } + } /** * This method goes through the steps of deactivating the current tool option contribution and @@ -2186,7 +2195,14 @@ public void run() { finalMap = (Map) command.getCreatedMap(); finalDropHandler = new UDIGDropHandler(); } else { - finalDropHandler = activeEditor.getDropHandler(); + + UDIGDropHandler mapDropHandler = activeEditor.getDropHandler(); + + if (mapDropHandler == null) { + finalDropHandler = new UDIGDropHandler(); + } else { + finalDropHandler = mapDropHandler; + } finalMap = activeEditor.getMap(); } diff --git a/plugins/org.locationtech.udig.project.ui/src/org/locationtech/udig/project/ui/internal/tool/display/ToolProxy.java b/plugins/org.locationtech.udig.project.ui/src/org/locationtech/udig/project/ui/internal/tool/display/ToolProxy.java index 26cf8b3eb..5b9c422e7 100644 --- a/plugins/org.locationtech.udig.project.ui/src/org/locationtech/udig/project/ui/internal/tool/display/ToolProxy.java +++ b/plugins/org.locationtech.udig.project.ui/src/org/locationtech/udig/project/ui/internal/tool/display/ToolProxy.java @@ -125,8 +125,7 @@ public class ToolProxy extends ModalItem implements ModalTool, ActionTool { * @param definition The configuration element which describes the tool * @param toolManager ToolManager responsible for this tool */ - public ToolProxy(IExtension extension, IConfigurationElement definition, - ToolManager toolManager) { + public ToolProxy(IExtension extension, IConfigurationElement definition, ToolManager toolManager ) { super(); this.toolManager = toolManager; @@ -141,10 +140,13 @@ public ToolProxy(IExtension extension, IConfigurationElement definition, String toolTip = definition.getAttribute("tooltip"); //$NON-NLS-1$ String iconID = definition.getAttribute("icon"); //$NON-NLS-1$ String largeIconID = definition.getAttribute("largeIcon"); //$NON-NLS-1$ - String preferencePageId = definition.getAttribute("preferencePageId"); //$NON-NLS-1$ - // setup attributes used by status bare tool options + + //setup attributes used by status bar tool options setPreferencePageId(preferencePageId); + setName(name); + setToolTipText(toolTip); + setId(id); defaultCursorID = definition.getAttribute("toolCursorId"); //$NON-NLS-1$ @@ -171,6 +173,8 @@ public ToolProxy(IExtension extension, IConfigurationElement definition, bool = definition.getAttribute("onToolbar"); //$NON-NLS-1$ onToolbar = ((bool != null) && bool.equalsIgnoreCase("true")) ? true : false; //$NON-NLS-1$ menuPath = definition.getAttribute("menuPath"); //$NON-NLS-1$ + element = definition; + ImageDescriptor icon; if (iconID == null) { icon = null; @@ -183,15 +187,10 @@ public ToolProxy(IExtension extension, IConfigurationElement definition, // default to normal size so we have something setLargeImageDescriptor(icon); } else { - ImageDescriptor largeIcon = icon = AbstractUIPlugin.imageDescriptorFromPlugin(pluginid, - largeIconID); + ImageDescriptor largeIcon = AbstractUIPlugin.imageDescriptorFromPlugin(pluginid, largeIconID); setLargeImageDescriptor(largeIcon); } - this.element = definition; - setName(name); - setToolTipText(toolTip); - setId(id); if (type.equals("modalTool")) { //$NON-NLS-1$ this.type = MODAL; } else if (type.equals("backgroundTool")) { //$NON-NLS-1$ @@ -306,78 +305,54 @@ ActionTool getModelessTool() { */ public Tool getTool() { if (tool == null) { - Display display = Display.getCurrent(); - if (display == null) - display = Display.getDefault(); - final Display finalDisplay = display; - Runnable runnable = new Runnable() { - @Override - public void run() { - BusyIndicator.showWhile(finalDisplay, new Runnable() { - @Override - public void run() { - String klassName = element.getAttribute("class"); //$NON-NLS-1$ - if (klassName != null) { - try { - Object o = element.createExecutableExtension("class"); //$NON-NLS-1$ - tool = (Tool) o; - - if (tool instanceof AbstractTool) { - ((AbstractTool) tool).init(element); - } - - /* Tool cursors framework */ - if (tool instanceof ModalTool) { - if (defaultCursorID != null) { - ((ModalTool) tool).setCursorID(defaultCursorID); - tool.setProperty(ToolConstants.DEFAULT_CURSOR_ID_KEY, - defaultCursorID); - } - } - - tool.setContext(toolContext); - tool.setEnabled(isEnabled()); - - if (tool instanceof ModalTool) { - IMapEditorSelectionProvider selectionProvider = getSelectionProvider(); - ModalTool modalTool = (ModalTool) tool; - modalTool.setSelectionProvider(selectionProvider); - } - - } catch (CoreException e) { - ProjectUIPlugin.log("Error loading tool", e); //$NON-NLS-1$ - } - } - - IConfigurationElement[] toolElementChildren = element.getChildren(); - - for (IConfigurationElement toolElement : toolElementChildren) { - - if (toolElement.getAttribute("class") != null) { - try { - String contributionId = toolElement.getAttribute("id"); - - Object optionsContribution = toolElement - .createExecutableExtension("class"); - ContributionItem contributionItem = (ContributionItem) optionsContribution; - contributionItem.setId(contributionId); - - addOptionsContribution( - (ContributionItem) optionsContribution); - } catch (CoreException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - } + PlatformGIS.syncInDisplayThread(() -> { + try { + Object o = element.createExecutableExtension("class"); //$NON-NLS-1$ + tool = (Tool) o; + if (tool instanceof AbstractTool) { + ((AbstractTool) tool).init(element); + } + + /* Tool cursors framework */ + if (tool instanceof ModalTool) { + if (defaultCursorID != null) { + ((ModalTool) tool).setCursorID(defaultCursorID); + tool.setProperty(ToolConstants.DEFAULT_CURSOR_ID_KEY, + defaultCursorID); } - }); - } - }; + } + + tool.setContext(toolContext); + tool.setEnabled(isEnabled()); + + if (tool instanceof ModalTool) { + IMapEditorSelectionProvider selectionProvider = getSelectionProvider(); + ModalTool modalTool = (ModalTool) tool; + modalTool.setSelectionProvider(selectionProvider); + } + + IConfigurationElement[] toolElementChildren = element.getChildren(); + + for (IConfigurationElement toolElement : toolElementChildren) { + + if (toolElement.getAttribute("class") != null) { + String contributionId = toolElement.getAttribute("id"); - PlatformGIS.syncInDisplayThread(runnable); + Object optionsContribution = toolElement + .createExecutableExtension("class"); + ContributionItem contributionItem = (ContributionItem) optionsContribution; + contributionItem.setId(contributionId); + + addOptionsContribution((ContributionItem) optionsContribution); + } + } + + } catch (CoreException e) { + tool = null; + ProjectUIPlugin.log("Error loading tool with id " + getId(), e); //$NON-NLS-1$ + } + }); } return tool; } @@ -527,7 +502,7 @@ protected void runModal() { if (activeToolProxy == this) { // good that worked then } else { - // okay we will chagne the active item ourself + // okay we will change the active item ourself if (activeToolProxy != null) { activeToolProxy.setActive(false); } diff --git a/plugins/org.locationtech.udig.project.ui/src/org/locationtech/udig/project/ui/tool/IToolManager.java b/plugins/org.locationtech.udig.project.ui/src/org/locationtech/udig/project/ui/tool/IToolManager.java index d5bea9c2b..ea8e6b63d 100644 --- a/plugins/org.locationtech.udig.project.ui/src/org/locationtech/udig/project/ui/tool/IToolManager.java +++ b/plugins/org.locationtech.udig.project.ui/src/org/locationtech/udig/project/ui/tool/IToolManager.java @@ -161,7 +161,18 @@ public interface IToolManager { * */ void contributeToCoolBar( SubCoolBarManager cbmanager, IActionBars bars ); - + + /** + * Adds tools contribution items to the toolbar. + *

+ * The actual toolbar UI elements are created and managed by the framework, IToolManager + * just adds tools as contributions to the specified IToolBarManager. + * + * @param toolManager + * @param bars + */ + void contributeTools( IToolBarManager toolBarManager, IActionBars bars ); + /** * Adds action tools contribution items to the toolbar. *

diff --git a/plugins/org.locationtech.udig.project.ui/src/org/locationtech/udig/project/ui/tool/ToolConstants.java b/plugins/org.locationtech.udig.project.ui/src/org/locationtech/udig/project/ui/tool/ToolConstants.java index 248c0d51f..2dfb657f2 100644 --- a/plugins/org.locationtech.udig.project.ui/src/org/locationtech/udig/project/ui/tool/ToolConstants.java +++ b/plugins/org.locationtech.udig.project.ui/src/org/locationtech/udig/project/ui/tool/ToolConstants.java @@ -24,6 +24,9 @@ public interface ToolConstants { public static final String SELECTION_CA = "org.locationtech.udig.tool.category.selection"; //$NON-NLS-1$ public static final String INFO_CA = "org.locationtech.udig.tool.category.info"; //$NON-NLS-1$ public static final String EDIT_CA = "org.locationtech.udig.tool.category.edit"; //$NON-NLS-1$ + public static final String TOOL_EDIT_CA = "org.locationtech.udig.tool.edit.edit"; //$NON-NLS-1$ + public static final String TOOL_CREATE_CA = "org.locationtech.udig.tool.edit.create"; //$NON-NLS-1$ + public static final String TOOL_FEATURE_CA = "org.locationtech.udig.tool.edit.feature"; //$NON-NLS-1$ /**