1 package eu
.etaxonomy
.taxeditor
.editor
.handler
;
4 import org
.eclipse
.core
.expressions
.PropertyTester
;
5 import org
.eclipse
.jface
.util
.LocalSelectionTransfer
;
6 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
7 import org
.eclipse
.jface
.viewers
.TreeNode
;
8 import org
.eclipse
.ui
.IEditorPart
;
9 import org
.eclipse
.ui
.IWorkbenchWindow
;
10 import org
.eclipse
.ui
.PlatformUI
;
12 import eu
.etaxonomy
.cdm
.model
.molecular
.Sequence
;
13 import eu
.etaxonomy
.cdm
.model
.molecular
.SingleRead
;
14 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
15 import eu
.etaxonomy
.taxeditor
.editor
.view
.derivate
.DerivateView
;
20 * Tests types of specimens to add items to the context menu.
25 public class SpecimenPropertyTester
extends PropertyTester
{
26 private static final String SEQUENCE
= "isSequence";
27 private static final String SINGLE_READ
= "isSingleRead";
28 private static final String IS_SINGLEREAD_REUSABLE_HERE
= "isSingleReadReusableHere";
29 private static final String IS_SINGLEREAD_REUSED
= "isSingleReadReused";
32 public SpecimenPropertyTester() {}
36 public boolean test(Object receiver
, String property
, Object
[] args
, Object expectedValue
) {
37 if (receiver
instanceof IStructuredSelection
) {
38 IStructuredSelection selection
= (IStructuredSelection
) receiver
;
39 TreeNode treeNodeOfSelection
= EditorUtil
.getTreeNodeOfSelection(selection
);
40 if (treeNodeOfSelection
!=null) {
41 if (SEQUENCE
.equals(property
)) {
42 return isSequence(treeNodeOfSelection
.getValue());
44 else if (SINGLE_READ
.equals(property
)) {
45 return isSingleReadAlignment(treeNodeOfSelection
.getValue());
47 else if (IS_SINGLEREAD_REUSABLE_HERE
.equals(property
)) {
48 return isSingleReadReusableHere(treeNodeOfSelection
.getValue());
50 else if (IS_SINGLEREAD_REUSED
.equals(property
)) {
51 return isSingleReadReused(treeNodeOfSelection
.getValue());
58 private boolean isSingleReadReused(Object value
) {
59 final IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
60 final IEditorPart activeEditor
= window
.getActivePage().getActiveEditor();
61 if(value
instanceof SingleRead
){
62 if(activeEditor
instanceof DerivateView
63 && ((DerivateView
) activeEditor
).getMultiLinkSingleReads().contains(value
)){
70 private boolean isSingleReadReusableHere(Object value
) {
71 TreeNode clipboardNode
= EditorUtil
.getTreeNodeOfSelection(LocalSelectionTransfer
.getTransfer().getSelection());
72 if(value
instanceof Sequence
&& clipboardNode
!=null && clipboardNode
.getValue() instanceof SingleRead
73 && !((Sequence
) value
).getSingleReads().contains(clipboardNode
.getValue())){
79 private boolean isSequence(Object object
) {
80 return (object
instanceof Sequence
);
83 private boolean isSingleReadAlignment(Object object
) {
84 return (object
instanceof SingleRead
);