2d3ebb83fe77d91b857ca0073f3d8c030350240e
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / handler / alignmenteditor / ToggleInsertOverwriteHandler.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9
10 package eu.etaxonomy.taxeditor.editor.handler.alignmenteditor;
11
12
13 import java.util.HashMap;
14 import java.util.Map;
15
16 import org.eclipse.core.commands.AbstractHandler;
17 import org.eclipse.core.commands.ExecutionEvent;
18 import org.eclipse.core.commands.ExecutionException;
19 import org.eclipse.jface.resource.ImageDescriptor;
20 import org.eclipse.ui.IEditorPart;
21 import org.eclipse.ui.PlatformUI;
22 import org.eclipse.ui.commands.ICommandService;
23 import org.eclipse.ui.commands.IElementUpdater;
24 import org.eclipse.ui.menus.UIElement;
25
26 import eu.etaxonomy.taxeditor.editor.handler.HandlerTools;
27 import eu.etaxonomy.taxeditor.editor.molecular.AlignmentEditor;
28 import eu.etaxonomy.taxeditor.model.AbstractUtility;
29
30
31
32 /**
33 * Switches an {@link AlignmentEditor} between insertion and overwrite mode.
34 *
35 * @author Ben Stöver
36 * @date 04.12.2014
37 */
38 public class ToggleInsertOverwriteHandler extends AbstractHandler implements IElementUpdater {
39 public static final String COMMAND_ID =
40 "eu.etaxonomy.taxeditor.editor.molecular.AlignmentEditor.toggleInsertOverwrite";
41
42
43 private final ImageDescriptor INSERT_DESCRIPTOR = HandlerTools.createImageDescriptor("insert-16x16.png");
44 private final ImageDescriptor OVERWRITE_DESCRIPTOR = HandlerTools.createImageDescriptor("overwrite-16x16.png");
45
46
47 @Override
48 public Object execute(ExecutionEvent event) throws ExecutionException {
49 IEditorPart activeEditor = AbstractUtility.getActiveEditor();
50 if (activeEditor instanceof AlignmentEditor) {
51 ((AlignmentEditor)activeEditor).toggleInsertOverwrite();
52 ((ICommandService)PlatformUI.getWorkbench().getService(ICommandService.class)).refreshElements(
53 ToggleLeftRightInsertionHandler.COMMAND_ID, new HashMap());
54 }
55 return null;
56 }
57
58
59 @Override
60 public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map parameters) {
61 IEditorPart activeEditor = AbstractUtility.getActiveEditor();
62 if (activeEditor instanceof AlignmentEditor) {
63 if (((AlignmentEditor)activeEditor).isInsertMode()) {
64 element.setIcon(INSERT_DESCRIPTOR);
65 element.setText("INS");
66 element.setTooltip("Click to switch to overwrite mode");
67 }
68 else {
69 element.setIcon(OVERWRITE_DESCRIPTOR);
70 element.setText("OVR");
71 element.setTooltip("Click to switch to insertion mode");
72 }
73 }
74 }
75 }