Revision 479060ec
Added by Ben Stöver over 8 years ago
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/handler/AlignmentEditorCopyHandler.java | ||
---|---|---|
1 | 1 |
package eu.etaxonomy.taxeditor.molecular.handler; |
2 | 2 |
|
3 | 3 |
|
4 |
import java.util.Map; |
|
5 |
|
|
4 | 6 |
import info.bioinfweb.libralign.alignmentarea.AlignmentArea; |
5 | 7 |
import info.bioinfweb.libralign.alignmentarea.selection.SelectionModel; |
6 | 8 |
import info.bioinfweb.libralign.model.AlignmentModel; |
7 | 9 |
import info.bioinfweb.libralign.model.tokenset.AbstractTokenSet; |
8 | 10 |
|
9 |
import org.eclipse.core.commands.AbstractHandler; |
|
10 | 11 |
import org.eclipse.core.commands.ExecutionEvent; |
11 | 12 |
import org.eclipse.core.commands.ExecutionException; |
12 | 13 |
import org.eclipse.swt.dnd.Clipboard; |
13 | 14 |
import org.eclipse.swt.dnd.TextTransfer; |
14 | 15 |
import org.eclipse.swt.dnd.Transfer; |
15 | 16 |
import org.eclipse.swt.widgets.Display; |
16 |
import org.eclipse.ui.IEditorPart;
|
|
17 |
import org.eclipse.ui.handlers.HandlerUtil;
|
|
17 |
import org.eclipse.ui.commands.IElementUpdater;
|
|
18 |
import org.eclipse.ui.menus.UIElement;
|
|
18 | 19 |
|
19 | 20 |
import eu.etaxonomy.taxeditor.molecular.editor.AlignmentEditor; |
20 | 21 |
|
... | ... | |
33 | 34 |
* @author Ben Stöver |
34 | 35 |
* @date 25.08.2015 |
35 | 36 |
*/ |
36 |
public class AlignmentEditorCopyHandler extends AbstractHandler { |
|
37 |
@Override |
|
38 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
39 |
IEditorPart activeEditor = HandlerUtil.getActiveEditor(event); |
|
40 |
if(activeEditor instanceof AlignmentEditor){ |
|
41 |
AlignmentArea focusedArea = ((AlignmentEditor)activeEditor).getFocusedArea(); |
|
42 |
if (focusedArea != null) { |
|
43 |
copySelectionAsString(focusedArea); |
|
44 |
} |
|
45 |
} |
|
46 |
return null; |
|
47 |
} |
|
48 |
|
|
49 |
|
|
37 |
public class AlignmentEditorCopyHandler extends AbstractAlignmentEditorHandler implements IElementUpdater { |
|
50 | 38 |
@SuppressWarnings("unchecked") |
51 | 39 |
public static void copySelectionAsString(AlignmentArea area) { |
52 | 40 |
SelectionModel selection = area.getSelection(); |
... | ... | |
71 | 59 |
new Transfer[]{TextTransfer.getInstance()}); |
72 | 60 |
} |
73 | 61 |
} |
62 |
|
|
63 |
|
|
64 |
@Override |
|
65 |
public void doExecute(ExecutionEvent event, AlignmentEditor editor) throws ExecutionException { |
|
66 |
AlignmentArea focusedArea = editor.getFocusedArea(); |
|
67 |
if (focusedArea != null) { |
|
68 |
copySelectionAsString(focusedArea); |
|
69 |
} |
|
70 |
} |
|
71 |
|
|
72 |
|
|
73 |
@Override |
|
74 |
public boolean isEnabled() { |
|
75 |
AlignmentEditor editor = getActiveAlignmentEditor(); |
|
76 |
if (editor != null) { |
|
77 |
AlignmentArea focusedArea = editor.getFocusedArea(); |
|
78 |
if (focusedArea != null) { |
|
79 |
return !focusedArea.getSelection().isEmpty(); |
|
80 |
} |
|
81 |
} |
|
82 |
return false; |
|
83 |
} |
|
84 |
|
|
85 |
|
|
86 |
@Override |
|
87 |
public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map parameters) { |
|
88 |
setBaseEnabled(isEnabled()); |
|
89 |
} |
|
74 | 90 |
} |
Also available in: Unified diff
AlignmentEditorCopyHandler now sets current action status.