1 package eu
.etaxonomy
.taxeditor
.editor
.handler
;
4 import org
.eclipse
.core
.expressions
.PropertyTester
;
5 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
6 import org
.eclipse
.jface
.viewers
.TreeNode
;
8 import eu
.etaxonomy
.cdm
.model
.molecular
.Sequence
;
9 import eu
.etaxonomy
.cdm
.model
.molecular
.SingleRead
;
10 import eu
.etaxonomy
.cdm
.model
.occurrence
.MediaSpecimen
;
11 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
12 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
17 * Tests types of specimens to add items to the context menu.
22 public class SpecimenPropertyTester
extends PropertyTester
{
23 private static final String SEQUENCE
= "isSequence"; //$NON-NLS-1$
24 private static final String SINGLE_READ
= "isSingleRead"; //$NON-NLS-1$
25 private static final String IS_SPECIMEN_OR_OBSERVATION_BASE
= "isSpecimenOrObservationBase"; //$NON-NLS-1$
26 private static final String IS_ADD_DERIVATE_ALLOWED
= "isAddDerivateAllowed"; //$NON-NLS-1$
27 private static final String IS_ADD_MEDIA_ALLOWED
= "isAddMediaAllowed"; //$NON-NLS-1$
30 public SpecimenPropertyTester() {}
34 public boolean test(Object receiver
, String property
, Object
[] args
, Object expectedValue
) {
35 if (receiver
instanceof IStructuredSelection
) {
36 IStructuredSelection selection
= (IStructuredSelection
) receiver
;
37 TreeNode treeNodeOfSelection
= EditorUtil
.getTreeNodeOfSelection(selection
);
38 if (treeNodeOfSelection
!=null) {
39 if (SEQUENCE
.equals(property
)) {
40 return isSequence(treeNodeOfSelection
.getValue());
42 else if (SINGLE_READ
.equals(property
)) {
43 return isSingleRead(treeNodeOfSelection
.getValue());
45 else if (IS_SPECIMEN_OR_OBSERVATION_BASE
.equals(property
)) {
46 return isSpecimenOrObservationBase(treeNodeOfSelection
.getValue());
48 else if (IS_ADD_DERIVATE_ALLOWED
.equals(property
)) {
49 return isAddDerivateAllowed(treeNodeOfSelection
.getValue());
51 else if (IS_ADD_MEDIA_ALLOWED
.equals(property
)) {
52 return isAddMediaAllowed(treeNodeOfSelection
.getValue());
60 private boolean isSpecimenOrObservationBase(Object object
) {
61 return (object
instanceof SpecimenOrObservationBase
);
64 private boolean isAddDerivateAllowed(Object object
) {
65 return (object
instanceof SpecimenOrObservationBase
|| object
instanceof Sequence
)
66 && !(object
instanceof MediaSpecimen
);
69 private boolean isAddMediaAllowed(Object object
) {
70 return object
instanceof SpecimenOrObservationBase
71 && !(object
instanceof MediaSpecimen
);
74 private boolean isSingleRead(Object object
) {
75 return (object
instanceof SingleRead
);
78 private boolean isSequence(Object object
) {
79 return (object
instanceof Sequence
);