1 package eu
.etaxonomy
.taxeditor
.editor
.handler
;
3 import org
.eclipse
.core
.expressions
.PropertyTester
;
4 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
5 import org
.eclipse
.jface
.viewers
.TreeNode
;
7 import eu
.etaxonomy
.cdm
.model
.molecular
.Sequence
;
8 import eu
.etaxonomy
.cdm
.model
.molecular
.SingleRead
;
9 import eu
.etaxonomy
.cdm
.model
.occurrence
.MediaSpecimen
;
10 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
11 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
14 * Tests types of specimens to add items to the context menu.
19 public class SpecimenPropertyTester
extends PropertyTester
{
20 private static final String SEQUENCE
= "isSequence"; //$NON-NLS-1$
21 private static final String SINGLE_READ
= "isSingleRead"; //$NON-NLS-1$
22 private static final String IS_SPECIMEN_OR_OBSERVATION_BASE
= "isSpecimenOrObservationBase"; //$NON-NLS-1$
23 private static final String IS_ADD_DERIVATE_ALLOWED
= "isAddDerivateAllowed"; //$NON-NLS-1$
24 private static final String IS_ADD_MEDIA_ALLOWED
= "isAddMediaAllowed"; //$NON-NLS-1$
27 public SpecimenPropertyTester() {}
30 public boolean test(Object receiver
, String property
, Object
[] args
, Object expectedValue
) {
31 if (receiver
instanceof IStructuredSelection
) {
32 IStructuredSelection selection
= (IStructuredSelection
) receiver
;
33 TreeNode treeNodeOfSelection
= EditorUtil
.getTreeNodeOfSelection(selection
);
34 if (treeNodeOfSelection
!=null) {
35 if (SEQUENCE
.equals(property
)) {
36 return isSequence(treeNodeOfSelection
.getValue());
38 else if (SINGLE_READ
.equals(property
)) {
39 return isSingleRead(treeNodeOfSelection
.getValue());
41 else if (IS_SPECIMEN_OR_OBSERVATION_BASE
.equals(property
)) {
42 return isSpecimenOrObservationBase(treeNodeOfSelection
.getValue());
44 else if (IS_ADD_DERIVATE_ALLOWED
.equals(property
)) {
45 return isAddDerivateAllowed(treeNodeOfSelection
.getValue());
47 else if (IS_ADD_MEDIA_ALLOWED
.equals(property
)) {
48 return isAddMediaAllowed(treeNodeOfSelection
.getValue());
56 private boolean isSpecimenOrObservationBase(Object object
) {
57 return (object
instanceof SpecimenOrObservationBase
);
60 private boolean isAddDerivateAllowed(Object object
) {
61 return (object
instanceof SpecimenOrObservationBase
|| object
instanceof Sequence
)
62 && !(object
instanceof MediaSpecimen
);
65 private boolean isAddMediaAllowed(Object object
) {
66 return object
instanceof SpecimenOrObservationBase
67 && !(object
instanceof MediaSpecimen
);
70 private boolean isSingleRead(Object object
) {
71 return (object
instanceof SingleRead
);
74 private boolean isSequence(Object object
) {
75 return (object
instanceof Sequence
);