Project

General

Profile

Download (1.72 KB) Statistics
| Branch: | Tag: | Revision:
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.editor.e4.AlignmentEditorE4;
11
import eu.etaxonomy.taxeditor.molecular.handler.AbstractAlignmentEditorHandler;
12
import info.bioinfweb.libralign.alignmentarea.selection.SelectionChangeEvent;
13
import info.bioinfweb.libralign.alignmentarea.selection.SelectionListener;
14

    
15

    
16

    
17
/**
18
 * Listener used to update copy/paste events associated with {@link AlignmentEditor}.
19
 *
20
 * @author Ben Stöver
21
 * @date 25.08.2015
22
 */
23
public class AlignmentEditorActionUpdater implements SelectionListener, Listener {
24
	private static final String[] IDS = {ActionFactory.COPY.getCommandId(), ActionFactory.CUT.getCommandId(),
25
		ActionFactory.PASTE.getCommandId()};
26

    
27

    
28
	private void updateEvents() {
29
		ICommandService service = PlatformUI.getWorkbench().getService(ICommandService.class);
30
		for (int i = 0; i < IDS.length; i++) {
31
	        service.refreshElements(IDS[i], null);
32
		}
33
	}
34

    
35

    
36
	@Override
37
	public void handleEvent(Event event) {
38
		AlignmentEditorE4 editor = AbstractAlignmentEditorHandler.getActiveAlignmentEditor();
39
		if (editor != null) {
40
            updateEvents();
41
		}
42
	}
43

    
44

    
45
	@Override
46
	public void selectionChanged(SelectionChangeEvent e) {
47
		AlignmentEditorE4 editor = AbstractAlignmentEditorHandler.getActiveAlignmentEditor();
48
		if (editor != null) {
49
			if ((e.getSource() == editor.getReadsArea().getSelection()) ||
50
					(e.getSource() == editor.getEditableConsensusArea().getSelection())) {
51

    
52
				updateEvents();
53
			}
54
		}
55
	}
56
}
(1-1/3)