1
|
package eu.etaxonomy.taxeditor.molecular.handler;
|
2
|
|
3
|
|
4
|
import info.bioinfweb.libralign.alignmentarea.AlignmentArea;
|
5
|
import info.bioinfweb.libralign.alignmentarea.selection.SelectionModel;
|
6
|
import info.bioinfweb.libralign.model.utils.AlignmentModelUtils;
|
7
|
|
8
|
import java.util.Map;
|
9
|
|
10
|
import org.eclipse.core.commands.ExecutionEvent;
|
11
|
import org.eclipse.swt.dnd.TextTransfer;
|
12
|
import org.eclipse.swt.dnd.Transfer;
|
13
|
import org.eclipse.ui.commands.IElementUpdater;
|
14
|
import org.eclipse.ui.menus.UIElement;
|
15
|
|
16
|
import eu.etaxonomy.taxeditor.molecular.editor.AlignmentEditor;
|
17
|
|
18
|
|
19
|
|
20
|
/**
|
21
|
* Handler that copies the currently selected nucleotides from an alignment editor to the clipboard.
|
22
|
* <p>
|
23
|
* The copied contents either come from the single reads or the consensus sequence alignment area,
|
24
|
* depending on which component currently has the focus. If none of these components has the focus,
|
25
|
* nothing will be copied, even if nucleotides are currently selected.
|
26
|
* <p>
|
27
|
* If the selection contains parts of multiple sequence, these are separated by the line separator
|
28
|
* of the current operating system.
|
29
|
*
|
30
|
* @author Ben Stöver
|
31
|
* @date 25.08.2015
|
32
|
*/
|
33
|
public class AlignmentEditorCopyHandler extends AbstractFocusedAlignmentAreaHandler implements IElementUpdater {
|
34
|
@Override
|
35
|
@SuppressWarnings("unchecked")
|
36
|
protected void doExecute2(ExecutionEvent event, AlignmentEditor editor, AlignmentArea focusedArea) {
|
37
|
SelectionModel selection = focusedArea.getSelection();
|
38
|
if (!selection.isEmpty()) {
|
39
|
editor.CLIPBOARD.setContents(new Object[]{AlignmentModelUtils.selectionAsString(focusedArea, false)},
|
40
|
new Transfer[]{TextTransfer.getInstance()});
|
41
|
}
|
42
|
}
|
43
|
|
44
|
|
45
|
@Override
|
46
|
public boolean isEnabled() {
|
47
|
AlignmentEditor editor = getActiveAlignmentEditor();
|
48
|
if (editor != null) {
|
49
|
AlignmentArea focusedArea = editor.getFocusedArea();
|
50
|
if (focusedArea != null) {
|
51
|
return !focusedArea.getSelection().isEmpty();
|
52
|
}
|
53
|
}
|
54
|
return false;
|
55
|
}
|
56
|
|
57
|
|
58
|
@Override
|
59
|
public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map parameters) {
|
60
|
setBaseEnabled(isEnabled());
|
61
|
}
|
62
|
}
|