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