Project

General

Profile

Download (2.86 KB) Statistics
| Branch: | Tag: | Revision:
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.molecular.handler;
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.model.AbstractUtility;
22
import eu.etaxonomy.taxeditor.molecular.editor.AlignmentEditor;
23

    
24

    
25

    
26
/**
27
 * Switches an {@link AlignmentEditor} between insertion in the base sequence to
28
 * the left or to the right.
29
 *
30
 * @author Ben Stöver
31
 * @date 04.12.2014
32
 */
33
public class ToggleLeftRightInsertionHandler extends AbstractAlignmentEditorHandler implements IElementUpdater {
34
    public static final String COMMAND_ID = "eu.etaxonomy.taxeditor.molecular.AlignmentEditor.toggleLeftRightInsertion";
35

    
36

    
37
    private final ImageDescriptor INSERT_LEFT_DESCRIPTOR =
38
            HandlerTools.createImageDescriptor("pherogram-insert-left-16x16.png");
39
    private final ImageDescriptor INSERT_RIGHT_DESCRIPTOR =
40
            HandlerTools.createImageDescriptor("pherogram-insert-right-16x16.png");
41
    private final ImageDescriptor INSERT_LEFT_DISABLED_DESCRIPTOR =
42
            HandlerTools.createImageDescriptor("pherogram-insert-left-disabled-16x16.png");
43
    private final ImageDescriptor INSERT_RIGHT_DISABLED_DESCRIPTOR =
44
            HandlerTools.createImageDescriptor("pherogram-insert-right-disabled-16x16.png");
45

    
46

    
47
    @Override
48
    public void doExecute(ExecutionEvent event, AlignmentEditor editor) throws ExecutionException {
49
        editor.toggleLeftRightInsertionInPherogram();
50
    }
51

    
52

    
53
    @Override
54
    public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map parameters) {
55
        IEditorPart activeEditor = AbstractUtility.getActiveEditor();
56
        if (activeEditor instanceof AlignmentEditor) {
57
            setBaseEnabled(((AlignmentEditor)activeEditor).isInsertMode());
58
            if (((AlignmentEditor)activeEditor).isInsertLeftInPherogram()) {
59
                element.setIcon(INSERT_LEFT_DESCRIPTOR);
60
                element.setDisabledIcon(INSERT_LEFT_DISABLED_DESCRIPTOR);
61
                element.setText("Left");
62
                element.setTooltip("Switch to insert pherogram distorsions right of future edits.");
63
            }
64
            else {
65
                element.setIcon(INSERT_RIGHT_DESCRIPTOR);
66
                element.setDisabledIcon(INSERT_RIGHT_DISABLED_DESCRIPTOR);
67
                element.setText("Right");
68
                element.setTooltip("Switch to insert pherogram distorsions left of future edits.");
69
            }
70
        }
71
    }
72
}
(17-17/21)