import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
public AlignmentArea getEditableConsensusArea() {
return getAlignmentsContainer().getAlignmentAreas().get(EDITABLE_CONSENSUS_AREA_INDEX);
}
-
+
+ /**
+ * Checks whether {@link #getReadsArea()} or {@link #getEditableConsensusArea()} currently
+ * have the user focus and returns the according component.
+ *
+ * @return either the reads or the consensus alignment area or {@code null} if none of these
+ * components is currently focused
+ */
+ public AlignmentArea getFocusedArea() {
+ AlignmentArea result = getReadsArea();
+ if (hasFocus(result)) {
+ return result;
+ }
+ else {
+ result = getEditableConsensusArea();
+ if (hasFocus(result)) {
+ return result;
+ }
+ else {
+ return null;
+ }
+ }
+ }
+
+
+ /**
+ * Checks whether the specified alignment area or one of its subcomponents currently has the
+ * focus.
+ *
+ * @param area the alignment area to be checked (Can only be {@link #getReadsArea()} or
+ * {@link #getEditableConsensusArea()}.)
+ * @return {@code true} if the specified component is focused and is either equal to
+ * {@link #getReadsArea()} or {@link #getEditableConsensusArea()}or {@code false} otherwise
+ */
+ public boolean hasFocus(AlignmentArea area) {
+ Composite areaComponent = (Composite)area.getToolkitComponent();
+ Control control = Display.getCurrent().getFocusControl();
+ while ((control != areaComponent) && (control != null)) {
+ control = control.getParent();
+ }
+ return (control == areaComponent);
+ }
+
+
public boolean hasPherogram(int sequenceID) {
return getReadsArea().getDataAreas().getSequenceAreas(sequenceID).size() > PHEROGRAM_AREA_INDEX;
}
@Override
public void setFocus() {
- if(conversationHolder!=null){
+ if(conversationHolder != null){
conversationHolder.bind();
}
}
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.handlers.HandlerUtil;
*/
public class AlignmentEditorCopyHandler extends AbstractHandler {
@Override
+ @SuppressWarnings("unchecked")
public Object execute(ExecutionEvent event) throws ExecutionException {
- Clipboard clipboard = new Clipboard(Display.getCurrent());
- TextTransfer textTransfer = TextTransfer.getInstance();
- Transfer[] transfers = new Transfer[]{textTransfer};
-
IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
if(activeEditor instanceof AlignmentEditor){
AlignmentEditor alignmentEditor = (AlignmentEditor)activeEditor;
StringBuilder selectedCharacters = new StringBuilder();
- AlignmentArea focusedArea = getFocusedArea(alignmentEditor);
+ AlignmentArea focusedArea = alignmentEditor.getFocusedArea();
if (focusedArea != null) {
SelectionModel selection = focusedArea.getSelection();
if (!selection.isEmpty()) {
- AlignmentModel<Character> alignmentModel = (AlignmentModel<Character>)focusedArea.getAlignmentModel();
+ 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++) {
}
}
}
- Object[] data = new Object[]{selectedCharacters.toString()};
- clipboard.setContents(data, transfers);
+ new Clipboard(Display.getCurrent()).setContents(new Object[]{selectedCharacters.toString()},
+ new Transfer[]{TextTransfer.getInstance()});
}
return null;
}
-
-
- private AlignmentArea getFocusedArea(AlignmentEditor editor) {
- AlignmentArea result = editor.getReadsArea();
- if (hasFocus(result)) {
- return result;
- }
- else {
- result = editor.getEditableConsensusArea();
- if (hasFocus(result)) {
- return result;
- }
- else {
- return null;
- }
- }
- }
-
-
- private boolean hasFocus(AlignmentArea area) {
- Composite areaComponent = (Composite)area.getToolkitComponent();
- Control control = Display.getCurrent().getFocusControl();
- while ((control != areaComponent) && (control != null)) {
- control = control.getParent();
- }
- return (control == areaComponent);
- }
}