Revision a0f46df5
Added by Ben Stöver over 8 years ago
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/handler/AlignmentEditorCopyHandler.java | ||
---|---|---|
35 | 35 |
*/ |
36 | 36 |
public class AlignmentEditorCopyHandler extends AbstractHandler { |
37 | 37 |
@Override |
38 |
@SuppressWarnings("unchecked") |
|
39 | 38 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
40 | 39 |
IEditorPart activeEditor = HandlerUtil.getActiveEditor(event); |
41 | 40 |
if(activeEditor instanceof AlignmentEditor){ |
42 |
AlignmentEditor alignmentEditor = (AlignmentEditor)activeEditor; |
|
43 |
|
|
44 |
StringBuilder selectedCharacters = new StringBuilder(); |
|
45 |
AlignmentArea focusedArea = alignmentEditor.getFocusedArea(); |
|
41 |
AlignmentArea focusedArea = ((AlignmentEditor)activeEditor).getFocusedArea(); |
|
46 | 42 |
if (focusedArea != null) { |
47 |
SelectionModel selection = focusedArea.getSelection(); |
|
48 |
if (!selection.isEmpty()) { |
|
49 |
AlignmentModel<Character> alignmentModel = (AlignmentModel<Character>)focusedArea.getAlignmentModel(); |
|
50 |
for (int row = selection.getFirstRow(); row <= selection.getLastRow(); row++) { |
|
51 |
int id = focusedArea.getSequenceOrder().idByIndex(row); |
|
52 |
for (int column = selection.getFirstColumn(); column <= selection.getLastColumn(); column++) { |
|
53 |
if (alignmentModel.getSequenceLength(id) > column) { |
|
54 |
selectedCharacters.append(alignmentModel.getTokenAt(id, column)); |
|
55 |
} |
|
56 |
else { // Add gaps if selection is behind the end of the sequence. |
|
57 |
selectedCharacters.append(AbstractTokenSet.DEFAULT_GAP_REPRESENTATION); |
|
58 |
} |
|
59 |
} |
|
60 |
if (row < selection.getLastRow()) { |
|
61 |
selectedCharacters.append(System.getProperty("line.separator")); |
|
62 |
} |
|
63 |
} |
|
64 |
} |
|
43 |
copySelectionAsString(focusedArea); |
|
65 | 44 |
} |
66 |
new Clipboard(Display.getCurrent()).setContents(new Object[]{selectedCharacters.toString()}, |
|
67 |
new Transfer[]{TextTransfer.getInstance()}); |
|
68 | 45 |
} |
69 | 46 |
return null; |
70 | 47 |
} |
48 |
|
|
49 |
|
|
50 |
@SuppressWarnings("unchecked") |
|
51 |
public static void copySelectionAsString(AlignmentArea area) { |
|
52 |
SelectionModel selection = area.getSelection(); |
|
53 |
if (!selection.isEmpty()) { |
|
54 |
StringBuilder selectedCharacters = new StringBuilder(); |
|
55 |
AlignmentModel<Character> alignmentModel = (AlignmentModel<Character>)area.getAlignmentModel(); |
|
56 |
for (int row = selection.getFirstRow(); row <= selection.getLastRow(); row++) { |
|
57 |
int id = area.getSequenceOrder().idByIndex(row); |
|
58 |
for (int column = selection.getFirstColumn(); column <= selection.getLastColumn(); column++) { |
|
59 |
if (alignmentModel.getSequenceLength(id) > column) { |
|
60 |
selectedCharacters.append(alignmentModel.getTokenAt(id, column)); |
|
61 |
} |
|
62 |
else { // Add gaps if selection is behind the end of the sequence. |
|
63 |
selectedCharacters.append(AbstractTokenSet.DEFAULT_GAP_REPRESENTATION); |
|
64 |
} |
|
65 |
} |
|
66 |
if (row < selection.getLastRow()) { |
|
67 |
selectedCharacters.append(System.getProperty("line.separator")); |
|
68 |
} |
|
69 |
} |
|
70 |
new Clipboard(Display.getCurrent()).setContents(new Object[]{selectedCharacters.toString()}, |
|
71 |
new Transfer[]{TextTransfer.getInstance()}); |
|
72 |
} |
|
73 |
} |
|
71 | 74 |
} |
Also available in: Unified diff
AlignmentEditorCopyHandler now offers copying functionality as a static method.
Copying not performed, if no nucleotides are selected.