adapting to chages in CdmUtils
[taxeditor.git] / eu.etaxonomy.taxeditor.molecular / src / main / java / eu / etaxonomy / taxeditor / molecular / handler / 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.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 import eu.etaxonomy.taxeditor.molecular.l10n.Messages;
27
28
29
30 /**
31 * Switches an {@link AlignmentEditor} between insertion and overwrite mode.
32 *
33 * @author Ben Stöver
34 * @date 04.12.2014
35 */
36 public class ToggleInsertOverwriteHandler extends AbstractAlignmentEditorHandler implements IElementUpdater {
37 public static final String COMMAND_ID =
38 "eu.etaxonomy.taxeditor.molecular.AlignmentEditor.toggleInsertOverwrite"; //$NON-NLS-1$
39
40
41 private final ImageDescriptor INSERT_DESCRIPTOR = HandlerTools.createImageDescriptor("insert-16x16.png"); //$NON-NLS-1$
42 private final ImageDescriptor OVERWRITE_DESCRIPTOR = HandlerTools.createImageDescriptor("overwrite-16x16.png"); //$NON-NLS-1$
43
44
45 @Override
46 public void doExecute(ExecutionEvent event, AlignmentEditor editor) throws ExecutionException {
47 editor.toggleInsertOverwrite();
48 }
49
50
51 @Override
52 public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map parameters) {
53 IEditorPart activeEditor = AbstractUtility.getActiveEditor();
54 if (activeEditor instanceof AlignmentEditor) {
55 if (((AlignmentEditor)activeEditor).isInsertMode()) {
56 element.setIcon(INSERT_DESCRIPTOR);
57 element.setText("INS"); //$NON-NLS-1$
58 element.setTooltip(Messages.ToggleInsertOverwriteHandler_SWITCH_OVERWRITE);
59 }
60 else {
61 element.setIcon(OVERWRITE_DESCRIPTOR);
62 element.setText("OVR"); //$NON-NLS-1$
63 element.setTooltip(Messages.ToggleInsertOverwriteHandler_SWITCH_INSERTION);
64 }
65 ((ICommandService)PlatformUI.getWorkbench().getService(ICommandService.class)).refreshElements(
66 ToggleLeftRightInsertionHandler.COMMAND_ID, null);
67 }
68 }
69 }