merge-update from trunk
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / handler / ToggleLeftRightInsertionHandler.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;
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 in the base sequence to the left or to the right.
29 *
30 * @author Ben Stöver
31 * @date 04.12.2014
32 */
33 public class ToggleLeftRightInsertionHandler extends AbstractHandler implements IElementUpdater {
34 public static final String COMMAND_ID =
35 "eu.etaxonomy.taxeditor.editor.molecular.AlignmentEditor.toggleLeftRightInsertion";
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).toggleLeftRightInsertionInPherogram();
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 //TODO Use icons instead.
53 if (((AlignmentEditor)activeEditor).isInsertLeftInPherogram()) {
54 element.setText(" Left ");
55 element.setTooltip("Click to switch to insert new distorsions of the base call sequence right of future edits.");
56 }
57 else {
58 element.setText("Right");
59 element.setTooltip("Click to switch to insert new distorsions of the base call sequence left of future edits.");
60 }
61 }
62 }
63 }