AbstractAlignmentEditorHandler added.
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / handler / alignmenteditor / 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.alignmenteditor;
11
12 import java.util.Map;
13
14 import org.eclipse.core.commands.ExecutionEvent;
15 import org.eclipse.core.commands.ExecutionException;
16 import org.eclipse.jface.resource.ImageDescriptor;
17 import org.eclipse.ui.IEditorPart;
18 import org.eclipse.ui.commands.IElementUpdater;
19 import org.eclipse.ui.menus.UIElement;
20
21 import eu.etaxonomy.taxeditor.editor.handler.HandlerTools;
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
29 * the left or to the right.
30 *
31 * @author Ben Stöver
32 * @date 04.12.2014
33 */
34 public class ToggleLeftRightInsertionHandler extends AbstractAlignmentEditorHandler implements IElementUpdater {
35 public static final String COMMAND_ID = "eu.etaxonomy.taxeditor.editor.molecular.AlignmentEditor.toggleLeftRightInsertion";
36
37
38 private final ImageDescriptor INSERT_LEFT_DESCRIPTOR =
39 HandlerTools.createImageDescriptor("pherogram-insert-left-16x16.png");
40 private final ImageDescriptor INSERT_RIGHT_DESCRIPTOR =
41 HandlerTools.createImageDescriptor("pherogram-insert-right-16x16.png");
42 private final ImageDescriptor INSERT_LEFT_DISABLED_DESCRIPTOR =
43 HandlerTools.createImageDescriptor("pherogram-insert-left-disabled-16x16.png");
44 private final ImageDescriptor INSERT_RIGHT_DISABLED_DESCRIPTOR =
45 HandlerTools.createImageDescriptor("pherogram-insert-right-disabled-16x16.png");
46
47
48 @Override
49 public void doExecute(ExecutionEvent event, AlignmentEditor editor) throws ExecutionException {
50 editor.toggleLeftRightInsertionInPherogram();
51 }
52
53
54 @Override
55 public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map parameters) {
56 IEditorPart activeEditor = AbstractUtility.getActiveEditor();
57 if (activeEditor instanceof AlignmentEditor) {
58 setBaseEnabled(((AlignmentEditor)activeEditor).isInsertMode());
59 if (((AlignmentEditor)activeEditor).isInsertLeftInPherogram()) {
60 element.setIcon(INSERT_LEFT_DESCRIPTOR);
61 element.setDisabledIcon(INSERT_LEFT_DISABLED_DESCRIPTOR);
62 element.setText("Left");
63 element.setTooltip("Switch to insert pherogram distorsions right of future edits.");
64 }
65 else {
66 element.setIcon(INSERT_RIGHT_DESCRIPTOR);
67 element.setDisabledIcon(INSERT_RIGHT_DISABLED_DESCRIPTOR);
68 element.setText("Right");
69 element.setTooltip("Switch to insert pherogram distorsions left of future edits.");
70 }
71 }
72 }
73 }