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
|
|
13
|
import java.util.Map;
|
14
|
|
15
|
import org.eclipse.core.commands.ExecutionEvent;
|
16
|
import org.eclipse.core.commands.ExecutionException;
|
17
|
import org.eclipse.jface.resource.ImageDescriptor;
|
18
|
import org.eclipse.ui.IEditorPart;
|
19
|
import org.eclipse.ui.PlatformUI;
|
20
|
import org.eclipse.ui.commands.ICommandService;
|
21
|
import org.eclipse.ui.commands.IElementUpdater;
|
22
|
import org.eclipse.ui.menus.UIElement;
|
23
|
|
24
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
25
|
import eu.etaxonomy.taxeditor.molecular.editor.AlignmentEditor;
|
26
|
|
27
|
|
28
|
|
29
|
/**
|
30
|
* Switches an {@link AlignmentEditor} between insertion and overwrite mode.
|
31
|
*
|
32
|
* @author Ben Stöver
|
33
|
* @date 04.12.2014
|
34
|
*/
|
35
|
public class ToggleInsertOverwriteHandler extends AbstractAlignmentEditorHandler implements IElementUpdater {
|
36
|
public static final String COMMAND_ID =
|
37
|
"eu.etaxonomy.taxeditor.molecular.AlignmentEditor.toggleInsertOverwrite";
|
38
|
|
39
|
|
40
|
private final ImageDescriptor INSERT_DESCRIPTOR = HandlerTools.createImageDescriptor("insert-16x16.png");
|
41
|
private final ImageDescriptor OVERWRITE_DESCRIPTOR = HandlerTools.createImageDescriptor("overwrite-16x16.png");
|
42
|
|
43
|
|
44
|
@Override
|
45
|
public void doExecute(ExecutionEvent event, AlignmentEditor editor) throws ExecutionException {
|
46
|
editor.toggleInsertOverwrite();
|
47
|
}
|
48
|
|
49
|
|
50
|
@Override
|
51
|
public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map parameters) {
|
52
|
IEditorPart activeEditor = AbstractUtility.getActiveEditor();
|
53
|
if (activeEditor instanceof AlignmentEditor) {
|
54
|
if (((AlignmentEditor)activeEditor).isInsertMode()) {
|
55
|
element.setIcon(INSERT_DESCRIPTOR);
|
56
|
element.setText("INS");
|
57
|
element.setTooltip("Click to switch to overwrite mode");
|
58
|
}
|
59
|
else {
|
60
|
element.setIcon(OVERWRITE_DESCRIPTOR);
|
61
|
element.setText("OVR");
|
62
|
element.setTooltip("Click to switch to insertion mode");
|
63
|
}
|
64
|
((ICommandService)PlatformUI.getWorkbench().getService(ICommandService.class)).refreshElements(
|
65
|
ToggleLeftRightInsertionHandler.COMMAND_ID, null);
|
66
|
}
|
67
|
}
|
68
|
}
|