1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.taxeditor.editor.name.handler;
|
11
|
|
12
|
import org.eclipse.core.expressions.PropertyTester;
|
13
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
14
|
|
15
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
16
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
17
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
18
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
19
|
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
|
20
|
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
|
21
|
import eu.etaxonomy.taxeditor.event.EventUtility;
|
22
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
23
|
|
24
|
/**
|
25
|
* <p>NameEditorMenuPropertyTester class.</p>
|
26
|
*
|
27
|
* @author n.hoffmann
|
28
|
* @created Jun 22, 2010
|
29
|
* @version 1.0
|
30
|
*/
|
31
|
public class NameEditorMenuPropertyTester extends PropertyTester {
|
32
|
|
33
|
private static final String ACCEPTED = "isAcceptedTaxon"; //$NON-NLS-1$
|
34
|
private static final String NOT_ACCEPTED = "isNotAcceptedTaxon"; //$NON-NLS-1$
|
35
|
private static final String SYNONYM = "isSynonym"; //$NON-NLS-1$
|
36
|
private static final String NOT_SYNONYM = "isNotSynonym"; //$NON-NLS-1$
|
37
|
private static final String MISAPPLICATION = "isMisapplication"; //$NON-NLS-1$
|
38
|
private static final String NOT_MISAPPLICATION = "isNotMisapplication"; //$NON-NLS-1$
|
39
|
private static final String PROPARTE_SYNONYM = "isProparteSynonym";//$NON-NLS-1$
|
40
|
private static final String NOT_PROPARTE_SYNONYM = "isNotProparteSynonym"; //$NON-NLS-1$
|
41
|
private static final String TAXONBASE = "isTaxonBase"; //$NON-NLS-1$
|
42
|
private static final String CONCEPT = "isConceptRelation"; //$NON-NLS-1$
|
43
|
private static final String EMPTY_NAMES = "hasEmptyNames"; //$NON-NLS-1$
|
44
|
private static final String ACCEPTED_AND_NO_HOMOTYPIC_SYNONYMS = "isAcceptedAndHasNoHomotypicSynonyms"; //$NON-NLS-1$
|
45
|
private static final String NOT_HOMOTYPIC_SYNONYM_OF_ACCEPTED = "isNotHomotypicSynonymOfAcceptedTaxon"; //$NON-NLS-1$
|
46
|
private static final String SYNONYM_WITH_HOMOTYPIC_SYNONYMS = "isSynonymInHomotypicalGroupWithMoreSynonyms"; //$NON-NLS-1$
|
47
|
private static final String IS_ORPHANED = "isOrphaned";
|
48
|
private static final String IS_NOT_INVALID_DESIGNATION = "isNotInvalidDesignation";//$NON-NLS-1$
|
49
|
|
50
|
/**
|
51
|
* <p>Constructor for NameEditorMenuPropertyTester.</p>
|
52
|
*/
|
53
|
public NameEditorMenuPropertyTester() {
|
54
|
}
|
55
|
|
56
|
/** {@inheritDoc} */
|
57
|
@Override
|
58
|
public boolean test(Object receiver, String property, Object[] args,
|
59
|
Object expectedValue) {
|
60
|
|
61
|
if(receiver instanceof IStructuredSelection){
|
62
|
|
63
|
IStructuredSelection selection = (IStructuredSelection) receiver;
|
64
|
|
65
|
Object selectedElement = selection.getFirstElement();
|
66
|
if(selectedElement instanceof UuidAndTitleCache){
|
67
|
UuidAndTitleCache uuidAndTitleCache = (UuidAndTitleCache<?>)selectedElement;
|
68
|
CdmBase cdmBase = CdmStore.getCommonService().find(uuidAndTitleCache.getType(), uuidAndTitleCache.getUuid());
|
69
|
selectedElement = cdmBase;
|
70
|
}
|
71
|
if(EMPTY_NAMES.equals(property)){
|
72
|
return hasEmptyNames(receiver);
|
73
|
}
|
74
|
else if(!(selectedElement instanceof TaxonBase)){
|
75
|
return false;
|
76
|
}
|
77
|
else if(NOT_ACCEPTED.equals(property)){
|
78
|
return !isAccepted(selectedElement);
|
79
|
}
|
80
|
else if(ACCEPTED.equals(property)){
|
81
|
return isAccepted(selectedElement);
|
82
|
}
|
83
|
else if(SYNONYM.equals(property)){
|
84
|
return isSynonym(selectedElement);
|
85
|
}
|
86
|
else if(NOT_SYNONYM.equals(property)){
|
87
|
return isNotSynonym(selectedElement);
|
88
|
}
|
89
|
else if(MISAPPLICATION.equals(property)){
|
90
|
return isMisapplication(selectedElement);
|
91
|
}
|
92
|
else if(PROPARTE_SYNONYM.equals(property)){
|
93
|
return isProparteSynonym(selectedElement);
|
94
|
}
|
95
|
else if(NOT_PROPARTE_SYNONYM.equals(property)){
|
96
|
return isNotProparteSynonym(selectedElement);
|
97
|
}
|
98
|
else if(NOT_MISAPPLICATION.equals(property)){
|
99
|
return isNotMisapplication(selectedElement);
|
100
|
}
|
101
|
else if(TAXONBASE.equals(property)){
|
102
|
return isTaxonBase(selectedElement);
|
103
|
}
|
104
|
else if(CONCEPT.equals(property)){
|
105
|
return isRelatedConcept(selectedElement);
|
106
|
}
|
107
|
else if(ACCEPTED_AND_NO_HOMOTYPIC_SYNONYMS.equals(property)){
|
108
|
return isAcceptedAndHasNoHomotypicSynonyms(selectedElement);
|
109
|
}
|
110
|
else if (NOT_HOMOTYPIC_SYNONYM_OF_ACCEPTED.equals(property)){
|
111
|
return isNotHomotypicSynonymOfAcceptedTaxon(selectedElement);
|
112
|
}
|
113
|
else if (SYNONYM_WITH_HOMOTYPIC_SYNONYMS.equals(property)){
|
114
|
return isSynonymInHomotypicalGroupWithMoreSynonyms(selectedElement);
|
115
|
}
|
116
|
else if (IS_ORPHANED.equals(property)){
|
117
|
return isOrphaned(selectedElement);
|
118
|
}
|
119
|
else if (IS_NOT_INVALID_DESIGNATION.equals(property)){
|
120
|
return isNotInvalidDesignation(selectedElement);
|
121
|
}
|
122
|
}
|
123
|
return false;
|
124
|
|
125
|
}
|
126
|
|
127
|
public static boolean isAcceptedAndHasNoHomotypicSynonyms(Object selectedElement) {
|
128
|
if (isAccepted(selectedElement)){
|
129
|
Taxon taxon = (Taxon) selectedElement;
|
130
|
return taxon.getSynonymsInGroup(taxon.getHomotypicGroup()).isEmpty();
|
131
|
}
|
132
|
return false;
|
133
|
}
|
134
|
public static boolean isNotAcceptedTaxon(Object selectedElement) {
|
135
|
|
136
|
return !isAccepted(selectedElement);
|
137
|
}
|
138
|
|
139
|
public static boolean isNotMisapplication(Object selectedElement) {
|
140
|
|
141
|
return !isMisapplication(selectedElement);
|
142
|
}
|
143
|
|
144
|
public static boolean isSynonymInHomotypicalGroupWithMoreSynonyms(Object selectedElement) {
|
145
|
if (isSynonym(selectedElement)){
|
146
|
Synonym synonym = (Synonym) selectedElement;
|
147
|
return synonym.getHomotypicGroup().getTypifiedNames().size()>1;
|
148
|
}
|
149
|
return false;
|
150
|
}
|
151
|
|
152
|
|
153
|
public static boolean isNotHomotypicSynonymOfAcceptedTaxon(Object selectedElement) {
|
154
|
if (isSynonym(selectedElement)){
|
155
|
Synonym synonym = (Synonym) selectedElement;
|
156
|
Taxon taxon = synonym.getAcceptedTaxon();
|
157
|
if (taxon != null &&
|
158
|
taxon.getHomotypicGroup().equals(synonym.getHomotypicGroup())){
|
159
|
return false;
|
160
|
}
|
161
|
}
|
162
|
return true;
|
163
|
}
|
164
|
|
165
|
|
166
|
/**
|
167
|
* @param receiver
|
168
|
* @return
|
169
|
*/
|
170
|
public static boolean hasEmptyNames(Object receiver) {
|
171
|
TaxonNameEditorE4 editor = (TaxonNameEditorE4) EventUtility.getTaxonEditor();
|
172
|
return editor == null ? false : editor.checkForEmptyNames();
|
173
|
}
|
174
|
|
175
|
public static boolean isRelatedConcept(Object selectedElement) {
|
176
|
if(selectedElement instanceof Taxon && ((Taxon) selectedElement).isRelatedConcept() && !((TaxonNameEditorE4) EventUtility.getTaxonEditor()).getTaxon().equals(selectedElement)){
|
177
|
return true;
|
178
|
}
|
179
|
return false;
|
180
|
}
|
181
|
|
182
|
public static boolean isTaxonBase(Object selectedElement) {
|
183
|
return (selectedElement instanceof TaxonBase) ? true : false;
|
184
|
}
|
185
|
|
186
|
public static boolean isMisapplication(Object selectedElement) {
|
187
|
if(selectedElement instanceof Taxon && ((Taxon) selectedElement).isMisapplication() && !((TaxonNameEditorE4) EventUtility.getTaxonEditor()).getTaxon().equals(selectedElement)){
|
188
|
return true;
|
189
|
}
|
190
|
return false;
|
191
|
}
|
192
|
|
193
|
public static boolean isProparteSynonym(Object selectedElement) {
|
194
|
if(selectedElement instanceof Taxon && ((Taxon) selectedElement).isProparteSynonym() && !((TaxonNameEditorE4) EventUtility.getTaxonEditor()).getTaxon().equals(selectedElement)){
|
195
|
return true;
|
196
|
}
|
197
|
return false;
|
198
|
}
|
199
|
public static boolean isNotProparteSynonym(Object selectedElement) {
|
200
|
if (selectedElement instanceof Synonym){
|
201
|
return true;
|
202
|
}
|
203
|
if(((Taxon) selectedElement).isProparteSynonym() && !((TaxonNameEditorE4) EventUtility.getTaxonEditor()).getTaxon().equals(selectedElement)){
|
204
|
return false;
|
205
|
}
|
206
|
return true;
|
207
|
}
|
208
|
|
209
|
public static boolean isSynonym(Object selectedElement) {
|
210
|
return (selectedElement instanceof Synonym) ? true : false;
|
211
|
}
|
212
|
public static boolean isNotSynonym(Object selectedElement) {
|
213
|
return !isSynonym(selectedElement);
|
214
|
}
|
215
|
|
216
|
public static boolean isAccepted(Object selectedElement) {
|
217
|
TaxonNameEditorE4 editor = (TaxonNameEditorE4) EventUtility.getTaxonEditor();
|
218
|
Taxon accepted = editor.getTaxon();
|
219
|
return (selectedElement instanceof Taxon && accepted.equals(selectedElement)) ? true : false;
|
220
|
}
|
221
|
|
222
|
public static boolean isOrphaned(Object selectedElement) {
|
223
|
if(selectedElement instanceof Taxon){
|
224
|
return ((Taxon) selectedElement).isOrphaned();
|
225
|
}
|
226
|
else if(selectedElement instanceof Synonym){
|
227
|
return ((Synonym) selectedElement).isOrphaned();
|
228
|
}
|
229
|
return false;
|
230
|
}
|
231
|
|
232
|
/**
|
233
|
* @param selectedElement
|
234
|
* @return
|
235
|
*/
|
236
|
public static boolean isProParteSynonym(Object selectedElement) {
|
237
|
if(selectedElement instanceof Taxon && ((Taxon) selectedElement).isProparteSynonym()){
|
238
|
return true;
|
239
|
}
|
240
|
return false;
|
241
|
}
|
242
|
|
243
|
/**
|
244
|
* @param selectedElement
|
245
|
* @return
|
246
|
*/
|
247
|
public static boolean isNotInvalidDesignation(Object selectedElement) {
|
248
|
if (selectedElement instanceof Synonym){
|
249
|
return true;
|
250
|
}
|
251
|
if(((Taxon) selectedElement).isInvalidDesignation() ){
|
252
|
return false;
|
253
|
}
|
254
|
return true;
|
255
|
}
|
256
|
|
257
|
}
|