1
|
package eu.etaxonomy.taxeditor.molecular.editor;
|
2
|
|
3
|
|
4
|
import org.eclipse.swt.widgets.Event;
|
5
|
import org.eclipse.swt.widgets.Listener;
|
6
|
import org.eclipse.ui.PlatformUI;
|
7
|
import org.eclipse.ui.actions.ActionFactory;
|
8
|
import org.eclipse.ui.commands.ICommandService;
|
9
|
|
10
|
import eu.etaxonomy.taxeditor.molecular.handler.AbstractAlignmentEditorHandler;
|
11
|
import info.bioinfweb.libralign.alignmentarea.selection.SelectionChangeEvent;
|
12
|
import info.bioinfweb.libralign.alignmentarea.selection.SelectionListener;
|
13
|
|
14
|
|
15
|
|
16
|
/**
|
17
|
* Listener used to update copy/paste events associated with {@link AlignmentEditor}.
|
18
|
*
|
19
|
* @author Ben Stöver
|
20
|
* @date 25.08.2015
|
21
|
*/
|
22
|
public class AlignmentEditorActionUpdater implements SelectionListener, Listener {
|
23
|
private static final String[] IDS = {ActionFactory.COPY.getCommandId(), ActionFactory.CUT.getCommandId(),
|
24
|
ActionFactory.PASTE.getCommandId()};
|
25
|
|
26
|
|
27
|
private void updateEvents() {
|
28
|
ICommandService service = (ICommandService)PlatformUI.getWorkbench().getService(ICommandService.class);
|
29
|
for (int i = 0; i < IDS.length; i++) {
|
30
|
service.refreshElements(IDS[i], null);
|
31
|
}
|
32
|
}
|
33
|
|
34
|
|
35
|
@Override
|
36
|
public void handleEvent(Event event) {
|
37
|
AlignmentEditor editor = AbstractAlignmentEditorHandler.getActiveAlignmentEditor();
|
38
|
if (editor != null) {
|
39
|
updateEvents();
|
40
|
}
|
41
|
}
|
42
|
|
43
|
|
44
|
@Override
|
45
|
public void selectionChanged(SelectionChangeEvent e) {
|
46
|
AlignmentEditor editor = AbstractAlignmentEditorHandler.getActiveAlignmentEditor();
|
47
|
if (editor != null) {
|
48
|
if ((e.getSource() == editor.getReadsArea().getSelection()) ||
|
49
|
(e.getSource() == editor.getEditableConsensusArea().getSelection())) {
|
50
|
|
51
|
updateEvents();
|
52
|
}
|
53
|
}
|
54
|
}
|
55
|
}
|