1
|
package eu.etaxonomy.taxeditor.editor.handler;
|
2
|
|
3
|
|
4
|
import org.eclipse.core.expressions.PropertyTester;
|
5
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
6
|
import org.eclipse.jface.viewers.TreeNode;
|
7
|
|
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;
|
13
|
|
14
|
|
15
|
|
16
|
/**
|
17
|
* Tests types of specimens to add items to the context menu.
|
18
|
*
|
19
|
* @author pplitzner
|
20
|
* @author BenStoever
|
21
|
*/
|
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$
|
28
|
|
29
|
|
30
|
public SpecimenPropertyTester() {}
|
31
|
|
32
|
/** {@inheritDoc} */
|
33
|
@Override
|
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());
|
41
|
}
|
42
|
else if (SINGLE_READ.equals(property)) {
|
43
|
return isSingleRead(treeNodeOfSelection.getValue());
|
44
|
}
|
45
|
else if (IS_SPECIMEN_OR_OBSERVATION_BASE.equals(property)) {
|
46
|
return isSpecimenOrObservationBase(treeNodeOfSelection.getValue());
|
47
|
}
|
48
|
else if (IS_ADD_DERIVATE_ALLOWED.equals(property)) {
|
49
|
return isAddDerivateAllowed(treeNodeOfSelection.getValue());
|
50
|
}
|
51
|
else if (IS_ADD_MEDIA_ALLOWED.equals(property)) {
|
52
|
return isAddMediaAllowed(treeNodeOfSelection.getValue());
|
53
|
}
|
54
|
}
|
55
|
}
|
56
|
return false;
|
57
|
}
|
58
|
|
59
|
|
60
|
private boolean isSpecimenOrObservationBase(Object object) {
|
61
|
return (object instanceof SpecimenOrObservationBase);
|
62
|
}
|
63
|
|
64
|
private boolean isAddDerivateAllowed(Object object) {
|
65
|
return (object instanceof SpecimenOrObservationBase || object instanceof Sequence)
|
66
|
&& !(object instanceof MediaSpecimen);
|
67
|
}
|
68
|
|
69
|
private boolean isAddMediaAllowed(Object object) {
|
70
|
return object instanceof SpecimenOrObservationBase
|
71
|
&& !(object instanceof MediaSpecimen);
|
72
|
}
|
73
|
|
74
|
private boolean isSingleRead(Object object) {
|
75
|
return (object instanceof SingleRead);
|
76
|
}
|
77
|
|
78
|
private boolean isSequence(Object object) {
|
79
|
return (object instanceof Sequence);
|
80
|
}
|
81
|
|
82
|
}
|