Project

General

Profile

Download (2.67 KB) Statistics
| Branch: | Tag: | Revision:
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.occurrence.MediaSpecimen;
10
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
11
import eu.etaxonomy.taxeditor.editor.EditorUtil;
12

    
13

    
14

    
15
/**
16
 * Tests types of specimens to add items to the context menu.
17
 *
18
 * @author pplitzner
19
 * @author BenStoever
20
 */
21
public class SpecimenPropertyTester extends PropertyTester {
22
    private static final String SEQUENCE = "isSequence"; //$NON-NLS-1$
23
    private static final String IS_SPECIMEN_OR_OBSERVATION_BASE = "isSpecimenOrObservationBase"; //$NON-NLS-1$
24
    private static final String IS_ADD_DERIVATE_ALLOWED = "isAddDerivateAllowed"; //$NON-NLS-1$
25
    private static final String IS_ADD_MEDIA_ALLOWED = "isAddMediaAllowed"; //$NON-NLS-1$
26

    
27

    
28
    public SpecimenPropertyTester() {}
29

    
30
    /** {@inheritDoc} */
31
    @Override
32
    public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
33
        if (receiver instanceof IStructuredSelection) {
34
            IStructuredSelection selection = (IStructuredSelection) receiver;
35
            TreeNode treeNodeOfSelection = EditorUtil.getTreeNodeOfSelection(selection);
36
            if (treeNodeOfSelection!=null) {
37
                if (SEQUENCE.equals(property)) {
38
                    return isSequence(treeNodeOfSelection.getValue());
39
                }
40
                else if (IS_SPECIMEN_OR_OBSERVATION_BASE.equals(property)) {
41
                    return isSpecimenOrObservationBase(treeNodeOfSelection.getValue());
42
                }
43
                else if (IS_ADD_DERIVATE_ALLOWED.equals(property)) {
44
                    return isAddDerivateAllowed(treeNodeOfSelection.getValue());
45
                }
46
                else if (IS_ADD_MEDIA_ALLOWED.equals(property)) {
47
                    return isAddMediaAllowed(treeNodeOfSelection.getValue());
48
                }
49
            }
50
        }
51
        return false;
52
    }
53

    
54

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

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

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

    
69
    private boolean isSequence(Object object) {
70
        return (object instanceof Sequence);
71
    }
72

    
73
}
(7-7/7)