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