Shared functionality moved from AlignmentEditorCopyHandler to AlignmentModelUtils...
authorb.stoever <b.stoever@localhost>
Wed, 26 Aug 2015 16:39:06 +0000 (16:39 +0000)
committerb.stoever <b.stoever@localhost>
Wed, 26 Aug 2015 16:39:06 +0000 (16:39 +0000)
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/handler/AlignmentEditorCopyHandler.java

index 4c249e10447b1b0a054c5ad8e4b791e5ac703f8d..381cf3536caee1cbd0ae9b8176629c96866b225a 100644 (file)
@@ -5,8 +5,7 @@ import java.util.Map;
 
 import info.bioinfweb.libralign.alignmentarea.AlignmentArea;
 import info.bioinfweb.libralign.alignmentarea.selection.SelectionModel;
-import info.bioinfweb.libralign.model.AlignmentModel;
-import info.bioinfweb.libralign.model.tokenset.AbstractTokenSet;
+import info.bioinfweb.libralign.model.AlignmentModelUtils;
 
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.swt.dnd.TextTransfer;
@@ -37,23 +36,7 @@ public class AlignmentEditorCopyHandler extends AbstractFocusedAlignmentAreaHand
        protected void doExecute2(ExecutionEvent event, AlignmentEditor editor, AlignmentArea focusedArea) {
        SelectionModel selection = focusedArea.getSelection();
        if (!selection.isEmpty()) {
-            StringBuilder selectedCharacters = new StringBuilder();
-                       AlignmentModel<Character> alignmentModel = (AlignmentModel<Character>)focusedArea.getAlignmentModel();
-               for (int row = selection.getFirstRow(); row <= selection.getLastRow(); row++) {
-               int id = focusedArea.getSequenceOrder().idByIndex(row);
-               for (int column = selection.getFirstColumn(); column <= selection.getLastColumn(); column++) {
-                       if (alignmentModel.getSequenceLength(id) > column) {
-                               selectedCharacters.append(alignmentModel.getTokenAt(id, column));
-                       }
-                       else {  // Add gaps if selection is behind the end of the sequence.
-                               selectedCharacters.append(AbstractTokenSet.DEFAULT_GAP_REPRESENTATION);
-                       }
-                               }
-               if (row < selection.getLastRow()) {
-                       selectedCharacters.append(System.getProperty("line.separator"));
-               }
-                       }
-               editor.CLIPBOARD.setContents(new Object[]{selectedCharacters.toString()}, 
+               editor.CLIPBOARD.setContents(new Object[]{AlignmentModelUtils.selectionAsString(focusedArea, false)}, 
                        new Transfer[]{TextTransfer.getInstance()});
        }
        }