merge-update from trunk
[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.Map;
14
15 import org.eclipse.core.commands.AbstractHandler;
16 import org.eclipse.core.commands.ExecutionEvent;
17 import org.eclipse.core.commands.ExecutionException;
18 import org.eclipse.ui.IEditorPart;
19 import org.eclipse.ui.commands.IElementUpdater;
20 import org.eclipse.ui.menus.UIElement;
21
22 import eu.etaxonomy.taxeditor.editor.molecular.AlignmentEditor;
23 import eu.etaxonomy.taxeditor.model.AbstractUtility;
24
25
26
27 /**
28 * Switches an {@link AlignmentEditor} between insertion and overwrite mode.
29 *
30 * @author Ben Stöver
31 * @date 04.12.2014
32 */
33 public class ToggleInsertOverwriteHandler extends AbstractHandler implements IElementUpdater {
34 public static final String COMMAND_ID =
35 "eu.etaxonomy.taxeditor.editor.molecular.AlignmentEditor.toggleInsertOverwrite";
36
37
38 @Override
39 public Object execute(ExecutionEvent event) throws ExecutionException {
40 IEditorPart activeEditor = AbstractUtility.getActiveEditor();
41 if (activeEditor instanceof AlignmentEditor) {
42 ((AlignmentEditor)activeEditor).toggleInsertOverwrite();
43 }
44 return null;
45 }
46
47
48 @Override
49 public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map parameters) {
50 IEditorPart activeEditor = AbstractUtility.getActiveEditor();
51 if (activeEditor instanceof AlignmentEditor) {
52 if (((AlignmentEditor)activeEditor).isInsertMode()) {
53 element.setText(" INS ");
54 element.setTooltip("Click to switch to overwrite mode");
55 }
56 else {
57 element.setText("OVR");
58 element.setTooltip("Click to switch to insertion mode");
59 }
60 }
61 }
62 }