1
|
/**
|
2
|
*
|
3
|
*/
|
4
|
package eu.etaxonomy.taxeditor.editor.view.descriptive.handler;
|
5
|
|
6
|
import org.eclipse.core.expressions.PropertyTester;
|
7
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
8
|
|
9
|
import eu.etaxonomy.cdm.model.description.DescriptionBase;
|
10
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
11
|
import eu.etaxonomy.cdm.model.media.Media;
|
12
|
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
|
13
|
|
14
|
/**
|
15
|
* Property tester used by the description tree menu.
|
16
|
*
|
17
|
* @author p.ciardelli
|
18
|
* @author n.hoffmann
|
19
|
* @version $Id: $
|
20
|
*/
|
21
|
public class DescriptionsMenuPropertyTester extends PropertyTester {
|
22
|
|
23
|
private static final String MEDIA = "isMedia";
|
24
|
private static final String FEATURE_NODE_CONTAINER = "isFeatureNodeContainer";
|
25
|
private static final String DESCRIPTION = "isDescription";
|
26
|
private static final String DESCRIPTION_ELEMENT = "isDescriptionElement";
|
27
|
private static final String DELETABLE = "isDeletable";
|
28
|
|
29
|
/* (non-Javadoc)
|
30
|
* @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
|
31
|
*/
|
32
|
/** {@inheritDoc} */
|
33
|
public boolean test(Object receiver, String property, Object[] args,
|
34
|
Object expectedValue) {
|
35
|
|
36
|
Object[] selectedElements = ((IStructuredSelection) receiver).toArray();
|
37
|
|
38
|
if(selectedElements.length == 0){
|
39
|
// nothing selected so all tests should fail
|
40
|
return false;
|
41
|
}
|
42
|
|
43
|
if(MEDIA.equals(property)){
|
44
|
return isMedia(selectedElements);
|
45
|
}
|
46
|
else if(FEATURE_NODE_CONTAINER.equals(property)){
|
47
|
return isFeatureNodeContainer(selectedElements);
|
48
|
}
|
49
|
else if(DESCRIPTION.equals(property)){
|
50
|
return isDescription(selectedElements);
|
51
|
}
|
52
|
else if(DESCRIPTION_ELEMENT.equals(property)){
|
53
|
return isDescriptionElement(selectedElements);
|
54
|
}
|
55
|
else if(DELETABLE.equals(property)){
|
56
|
return isDeletable(selectedElements);
|
57
|
}
|
58
|
else{
|
59
|
return false;
|
60
|
}
|
61
|
}
|
62
|
|
63
|
private boolean isFeatureNodeContainer(Object[] selectedElements) {
|
64
|
for (Object object : selectedElements){
|
65
|
if(!(object instanceof FeatureNodeContainer)){
|
66
|
return false;
|
67
|
}
|
68
|
}
|
69
|
return true;
|
70
|
}
|
71
|
|
72
|
private boolean isDeletable(Object[] selectedElements) {
|
73
|
boolean result = false;
|
74
|
|
75
|
for (Object object : selectedElements) {
|
76
|
|
77
|
if((object instanceof DescriptionBase)
|
78
|
|| (object instanceof DescriptionElementBase)
|
79
|
|| (object instanceof Media)
|
80
|
|| (object instanceof FeatureNodeContainer)){
|
81
|
result = true;
|
82
|
}else{
|
83
|
return false;
|
84
|
}
|
85
|
|
86
|
}
|
87
|
return result;
|
88
|
}
|
89
|
|
90
|
private boolean isDescriptionElement(Object[] selectedElements) {
|
91
|
for (Object object : selectedElements){
|
92
|
if(!(object instanceof DescriptionElementBase)){
|
93
|
return false;
|
94
|
}
|
95
|
}
|
96
|
return true;
|
97
|
}
|
98
|
|
99
|
private boolean isDescription(Object[] selectedElements) {
|
100
|
for (Object object : selectedElements){
|
101
|
if(!(object instanceof DescriptionBase)){
|
102
|
return false;
|
103
|
}
|
104
|
}
|
105
|
return true;
|
106
|
}
|
107
|
|
108
|
private boolean isMedia(Object[] selectedElements) {
|
109
|
for (Object object : selectedElements){
|
110
|
if(!(object instanceof Media)){
|
111
|
return false;
|
112
|
}
|
113
|
}
|
114
|
return true;
|
115
|
}
|
116
|
}
|