AbstractAlignmentEditorHandler added.
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / handler / alignmenteditor / ToggleInsertOverwriteHandler.java
index 7b047f8882255f59c7ed3456d744c554885e5328..283767bd3edaa5150644e0e9c4161efab4657dae 100644 (file)
@@ -1,8 +1,8 @@
 /**\r
 * Copyright (C) 2007 EDIT\r
-* European Distributed Institute of Taxonomy \r
+* European Distributed Institute of Taxonomy\r
 * http://www.e-taxonomy.eu\r
-* \r
+*\r
 * The contents of this file are subject to the Mozilla Public License Version 1.1\r
 * See LICENSE.TXT at the top of this package for the full license terms.\r
 */\r
@@ -12,13 +12,16 @@ package eu.etaxonomy.taxeditor.editor.handler.alignmenteditor;
 \r
 import java.util.Map;\r
 \r
-import org.eclipse.core.commands.AbstractHandler;\r
 import org.eclipse.core.commands.ExecutionEvent;\r
 import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.jface.resource.ImageDescriptor;\r
 import org.eclipse.ui.IEditorPart;\r
+import org.eclipse.ui.PlatformUI;\r
+import org.eclipse.ui.commands.ICommandService;\r
 import org.eclipse.ui.commands.IElementUpdater;\r
 import org.eclipse.ui.menus.UIElement;\r
 \r
+import eu.etaxonomy.taxeditor.editor.handler.HandlerTools;\r
 import eu.etaxonomy.taxeditor.editor.molecular.AlignmentEditor;\r
 import eu.etaxonomy.taxeditor.model.AbstractUtility;\r
 \r
@@ -26,37 +29,41 @@ import eu.etaxonomy.taxeditor.model.AbstractUtility;
 \r
 /**\r
  * Switches an {@link AlignmentEditor} between insertion and overwrite mode.\r
- * \r
+ *\r
  * @author Ben Stöver\r
  * @date 04.12.2014\r
  */\r
-public class ToggleInsertOverwriteHandler extends AbstractHandler implements IElementUpdater {\r
-       public static final String COMMAND_ID = \r
+public class ToggleInsertOverwriteHandler extends AbstractAlignmentEditorHandler implements IElementUpdater {\r
+       public static final String COMMAND_ID =\r
                        "eu.etaxonomy.taxeditor.editor.molecular.AlignmentEditor.toggleInsertOverwrite";\r
-       \r
-       \r
-       @Override\r
-       public Object execute(ExecutionEvent event) throws ExecutionException {\r
-        IEditorPart activeEditor = AbstractUtility.getActiveEditor();\r
-        if (activeEditor instanceof AlignmentEditor) {\r
-            ((AlignmentEditor)activeEditor).toggleInsertOverwrite();\r
-        }\r
-        return null;\r
-       }\r
-    \r
-    \r
+\r
+\r
+    private final ImageDescriptor INSERT_DESCRIPTOR = HandlerTools.createImageDescriptor("insert-16x16.png");\r
+    private final ImageDescriptor OVERWRITE_DESCRIPTOR = HandlerTools.createImageDescriptor("overwrite-16x16.png");\r
+\r
+\r
+    @Override\r
+    public void doExecute(ExecutionEvent event, AlignmentEditor editor) throws ExecutionException {\r
+        editor.toggleInsertOverwrite();\r
+    }\r
+\r
+\r
        @Override\r
        public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map parameters) {\r
         IEditorPart activeEditor = AbstractUtility.getActiveEditor();\r
                if (activeEditor instanceof AlignmentEditor) {\r
                        if (((AlignmentEditor)activeEditor).isInsertMode()) {\r
-                               element.setText(" INS ");\r
+                           element.setIcon(INSERT_DESCRIPTOR);\r
+                               element.setText("INS");\r
                                element.setTooltip("Click to switch to overwrite mode");\r
                        }\r
                        else {\r
+                element.setIcon(OVERWRITE_DESCRIPTOR);\r
                                element.setText("OVR");\r
                                element.setTooltip("Click to switch to insertion mode");\r
                        }\r
+            ((ICommandService)PlatformUI.getWorkbench().getService(ICommandService.class)).refreshElements(\r
+                    ToggleLeftRightInsertionHandler.COMMAND_ID, null);\r
                }\r
        }\r
 }\r