Project

General

Profile

Download (3.02 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.taxeditor.editor.handler;
2

    
3
import org.eclipse.core.expressions.PropertyTester;
4
import org.eclipse.jface.viewers.IStructuredSelection;
5
import org.eclipse.jface.viewers.TreeNode;
6

    
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;
12

    
13
/**
14
 * Tests types of specimens to add items to the context menu.
15
 *
16
 * @author pplitzner
17
 * @author BenStoever
18
 */
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$
25

    
26

    
27
    public SpecimenPropertyTester() {}
28

    
29
    @Override
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());
37
                }
38
                else if (SINGLE_READ.equals(property)) {
39
                    return isSingleRead(treeNodeOfSelection.getValue());
40
                }
41
                else if (IS_SPECIMEN_OR_OBSERVATION_BASE.equals(property)) {
42
                    return isSpecimenOrObservationBase(treeNodeOfSelection.getValue());
43
                }
44
                else if (IS_ADD_DERIVATE_ALLOWED.equals(property)) {
45
                    return isAddDerivateAllowed(treeNodeOfSelection.getValue());
46
                }
47
                else if (IS_ADD_MEDIA_ALLOWED.equals(property)) {
48
                    return isAddMediaAllowed(treeNodeOfSelection.getValue());
49
                }
50
            }
51
        }
52
        return false;
53
    }
54

    
55

    
56
    private boolean isSpecimenOrObservationBase(Object object) {
57
    	return (object instanceof SpecimenOrObservationBase);
58
	}
59

    
60
    private boolean isAddDerivateAllowed(Object object) {
61
        return (object instanceof SpecimenOrObservationBase || object instanceof Sequence)
62
                && !(object instanceof MediaSpecimen);
63
    }
64

    
65
    private boolean isAddMediaAllowed(Object object) {
66
        return object instanceof SpecimenOrObservationBase
67
                && !(object instanceof MediaSpecimen);
68
    }
69

    
70
    private boolean isSingleRead(Object object) {
71
        return (object instanceof SingleRead);
72
    }
73

    
74
    private boolean isSequence(Object object) {
75
        return (object instanceof Sequence);
76
    }
77
}
    (1-1/1)