1
|
/**
|
2
|
*
|
3
|
*/
|
4
|
package eu.etaxonomy.taxeditor.editor.view.descriptive.e4.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.description.IndividualsAssociation;
|
12
|
import eu.etaxonomy.cdm.model.media.Media;
|
13
|
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditor;
|
14
|
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonEditor;
|
15
|
import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
|
16
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
17
|
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
|
18
|
|
19
|
/**
|
20
|
* Property tester used by the description tree menu.
|
21
|
*
|
22
|
* @author p.ciardelli
|
23
|
* @author n.hoffmann
|
24
|
*/
|
25
|
public class DescriptionsMenuPropertyTesterE4 extends PropertyTester {
|
26
|
|
27
|
private static final String MEDIA = "isMedia"; //$NON-NLS-1$
|
28
|
private static final String FEATURE_NODE_CONTAINER = "isFeatureNodeContainer"; //$NON-NLS-1$
|
29
|
private static final String DESCRIPTION = "isDescription"; //$NON-NLS-1$
|
30
|
private static final String INDIVIDUALS_ASSOCIATION = "isIndividualsAssociation"; //$NON-NLS-1$
|
31
|
private static final String DESCRIPTION_ELEMENT = "isDescriptionElement"; //$NON-NLS-1$
|
32
|
private static final String DELETABLE = "isDeletable"; //$NON-NLS-1$
|
33
|
private static final String IMAGE_GALLERY = "isImageGallery"; //$NON-NLS-1$
|
34
|
private static final String TAXON_EDITOR = "isTaxonEditor"; //$NON-NLS-1$
|
35
|
private static final String BULK_EDITOR = "isBulkEditor"; //$NON-NLS-1$
|
36
|
private static final String DERIVATE_EDITOR = "isDerivateEditor"; //$NON-NLS-1$
|
37
|
|
38
|
@Override
|
39
|
public boolean test(Object receiver, String property, Object[] args,
|
40
|
Object expectedValue) {
|
41
|
|
42
|
if(TAXON_EDITOR.equals(property)){
|
43
|
return isTaxonEditor();
|
44
|
}
|
45
|
else if(BULK_EDITOR.equals(property)){
|
46
|
return isBulkEditor();
|
47
|
}
|
48
|
else if(DERIVATE_EDITOR.equals(property)){
|
49
|
return isDerivateEditor();
|
50
|
}
|
51
|
|
52
|
Object[] selectedElements = ((IStructuredSelection) receiver).toArray();
|
53
|
|
54
|
if(selectedElements.length == 0){
|
55
|
// nothing selected so all tests should fail
|
56
|
return false;
|
57
|
}
|
58
|
|
59
|
if(MEDIA.equals(property)){
|
60
|
return isMedia(selectedElements);
|
61
|
}
|
62
|
else if(FEATURE_NODE_CONTAINER.equals(property)){
|
63
|
return isFeatureNodeContainer(selectedElements);
|
64
|
}
|
65
|
else if(DESCRIPTION.equals(property)){
|
66
|
return isDescription(selectedElements);
|
67
|
}
|
68
|
else if(INDIVIDUALS_ASSOCIATION.equals(property)){
|
69
|
return isIndividualsAssociation(selectedElements);
|
70
|
}
|
71
|
else if(DESCRIPTION_ELEMENT.equals(property)){
|
72
|
return isDescriptionElement(selectedElements);
|
73
|
}
|
74
|
else if(DELETABLE.equals(property)){
|
75
|
return isDeletable(selectedElements);
|
76
|
}
|
77
|
else if(IMAGE_GALLERY.equals(property)){
|
78
|
return isImageGallery(selectedElements);
|
79
|
}
|
80
|
else{
|
81
|
return false;
|
82
|
}
|
83
|
}
|
84
|
|
85
|
private boolean isImageGallery(Object[] selectedElements) {
|
86
|
for (Object object : selectedElements){
|
87
|
if(!(object instanceof DescriptionBase) || !((DescriptionBase<?>) object).isImageGallery()){
|
88
|
return false;
|
89
|
}
|
90
|
}
|
91
|
return true;
|
92
|
}
|
93
|
|
94
|
private boolean isFeatureNodeContainer(Object[] selectedElements) {
|
95
|
for (Object object : selectedElements){
|
96
|
if(!(object instanceof FeatureNodeContainer)){
|
97
|
return false;
|
98
|
}
|
99
|
}
|
100
|
return true;
|
101
|
}
|
102
|
|
103
|
private boolean isDeletable(Object[] selectedElements) {
|
104
|
boolean result = false;
|
105
|
|
106
|
for (Object object : selectedElements) {
|
107
|
|
108
|
if((object instanceof DescriptionBase)
|
109
|
|| (object instanceof DescriptionElementBase)
|
110
|
|| (object instanceof Media)
|
111
|
|| (object instanceof FeatureNodeContainer)){
|
112
|
result = true;
|
113
|
}else{
|
114
|
return false;
|
115
|
}
|
116
|
|
117
|
}
|
118
|
return result;
|
119
|
}
|
120
|
|
121
|
private boolean isDescriptionElement(Object[] selectedElements) {
|
122
|
for (Object object : selectedElements){
|
123
|
if(!(object instanceof DescriptionElementBase)){
|
124
|
return false;
|
125
|
}
|
126
|
}
|
127
|
return true;
|
128
|
}
|
129
|
|
130
|
private boolean isDescription(Object[] selectedElements) {
|
131
|
for (Object object : selectedElements){
|
132
|
if(!(object instanceof DescriptionBase)){
|
133
|
return false;
|
134
|
}
|
135
|
}
|
136
|
return true;
|
137
|
}
|
138
|
|
139
|
private boolean isIndividualsAssociation(Object[] selectedElements) {
|
140
|
for (Object object : selectedElements){
|
141
|
if(!(object instanceof IndividualsAssociation)){
|
142
|
return false;
|
143
|
}
|
144
|
}
|
145
|
return true;
|
146
|
}
|
147
|
|
148
|
private boolean isMedia(Object[] selectedElements) {
|
149
|
for (Object object : selectedElements){
|
150
|
if(!(object instanceof Media)){
|
151
|
return false;
|
152
|
}
|
153
|
}
|
154
|
return true;
|
155
|
}
|
156
|
|
157
|
private boolean isTaxonEditor() {
|
158
|
if(AbstractUtility.getActiveEditor() instanceof TaxonEditor){
|
159
|
return true;
|
160
|
}
|
161
|
return false;
|
162
|
}
|
163
|
|
164
|
private boolean isBulkEditor() {
|
165
|
if(AbstractUtility.getActiveEditor() instanceof BulkEditor){
|
166
|
return true;
|
167
|
}
|
168
|
return false;
|
169
|
}
|
170
|
|
171
|
private boolean isDerivateEditor() {
|
172
|
if(AbstractUtility.getActiveEditor() instanceof DerivateView){
|
173
|
return true;
|
174
|
}
|
175
|
return false;
|
176
|
}
|
177
|
}
|