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"; //$NON-NLS-1$
|
48
|
|
49
|
/**
|
50
|
* <p>Constructor for NameEditorMenuPropertyTester.</p>
|
51
|
*/
|
52
|
public NameEditorMenuPropertyTester() {
|
53
|
}
|
54
|
|
55
|
/** {@inheritDoc} */
|
56
|
@Override
|
57
|
public boolean test(Object receiver, String property, Object[] args,
|
58
|
Object expectedValue) {
|
59
|
|
60
|
if(receiver instanceof IStructuredSelection){
|
61
|
|
62
|
IStructuredSelection selection = (IStructuredSelection) receiver;
|
63
|
|
64
|
Object selectedElement = selection.getFirstElement();
|
65
|
if(selectedElement instanceof UuidAndTitleCache){
|
66
|
UuidAndTitleCache uuidAndTitleCache = (UuidAndTitleCache<?>)selectedElement;
|
67
|
CdmBase cdmBase = CdmStore.getCommonService().find(uuidAndTitleCache.getType(), uuidAndTitleCache.getUuid());
|
68
|
selectedElement = cdmBase;
|
69
|
}
|
70
|
if(NOT_ACCEPTED.equals(property)){
|
71
|
return !isAccepted(selectedElement);
|
72
|
}
|
73
|
if(ACCEPTED.equals(property)){
|
74
|
return isAccepted(selectedElement);
|
75
|
}
|
76
|
else if(SYNONYM.equals(property)){
|
77
|
return isSynonym(selectedElement);
|
78
|
}
|
79
|
else if(NOT_SYNONYM.equals(property)){
|
80
|
return isNotSynonym(selectedElement);
|
81
|
}
|
82
|
else if(MISAPPLICATION.equals(property)){
|
83
|
return isMisapplication(selectedElement);
|
84
|
}
|
85
|
else if(PROPARTE_SYNONYM.equals(property)){
|
86
|
return isProparteSynonym(selectedElement);
|
87
|
}
|
88
|
else if(NOT_PROPARTE_SYNONYM.equals(property)){
|
89
|
return isNotProparteSynonym(selectedElement);
|
90
|
}
|
91
|
else if(NOT_MISAPPLICATION.equals(property)){
|
92
|
return isNotMisapplication(selectedElement);
|
93
|
}
|
94
|
else if(TAXONBASE.equals(property)){
|
95
|
return isTaxonBase(selectedElement);
|
96
|
}
|
97
|
else if(CONCEPT.equals(property)){
|
98
|
return isRelatedConcept(selectedElement);
|
99
|
}
|
100
|
else if(EMPTY_NAMES.equals(property)){
|
101
|
return hasEmptyNames(receiver);
|
102
|
}
|
103
|
else if(ACCEPTED_AND_NO_HOMOTYPIC_SYNONYMS.equals(property)){
|
104
|
return isAcceptedAndHasNoHomotypicSynonyms(selectedElement);
|
105
|
}
|
106
|
else if (NOT_HOMOTYPIC_SYNONYM_OF_ACCEPTED.equals(property)){
|
107
|
return isNotHomotypicSynonymOfAcceptedTaxon(selectedElement);
|
108
|
}
|
109
|
else if (SYNONYM_WITH_HOMOTYPIC_SYNONYMS.equals(property)){
|
110
|
return isSynonymInHomotypicalGroupWithMoreSynonyms(selectedElement);
|
111
|
}
|
112
|
else if (IS_ORPHANED.equals(property)){
|
113
|
return isOrphaned(selectedElement);
|
114
|
}
|
115
|
|
116
|
}
|
117
|
|
118
|
return false;
|
119
|
|
120
|
}
|
121
|
|
122
|
public static boolean isAcceptedAndHasNoHomotypicSynonyms(Object selectedElement) {
|
123
|
if (isAccepted(selectedElement)){
|
124
|
Taxon taxon = (Taxon) selectedElement;
|
125
|
return taxon.getSynonymsInGroup(taxon.getHomotypicGroup()).isEmpty();
|
126
|
}
|
127
|
return false;
|
128
|
}
|
129
|
public static boolean isNotAcceptedTaxon(Object selectedElement) {
|
130
|
|
131
|
return !isAccepted(selectedElement);
|
132
|
}
|
133
|
|
134
|
public static boolean isNotMisapplication(Object selectedElement) {
|
135
|
|
136
|
return !isMisapplication(selectedElement);
|
137
|
}
|
138
|
|
139
|
public static boolean isSynonymInHomotypicalGroupWithMoreSynonyms(Object selectedElement) {
|
140
|
if (isSynonym(selectedElement)){
|
141
|
Synonym synonym = (Synonym) selectedElement;
|
142
|
return synonym.getHomotypicGroup().getTypifiedNames().size()>1;
|
143
|
}
|
144
|
return false;
|
145
|
}
|
146
|
|
147
|
|
148
|
public static boolean isNotHomotypicSynonymOfAcceptedTaxon(Object selectedElement) {
|
149
|
if (isSynonym(selectedElement)){
|
150
|
Synonym synonym = (Synonym) selectedElement;
|
151
|
Taxon taxon = synonym.getAcceptedTaxon();
|
152
|
if (taxon != null &&
|
153
|
taxon.getHomotypicGroup().equals(synonym.getHomotypicGroup())){
|
154
|
return false;
|
155
|
}
|
156
|
}
|
157
|
return true;
|
158
|
}
|
159
|
|
160
|
|
161
|
/**
|
162
|
* @param receiver
|
163
|
* @return
|
164
|
*/
|
165
|
public static boolean hasEmptyNames(Object receiver) {
|
166
|
TaxonNameEditorE4 editor = (TaxonNameEditorE4) EventUtility.getTaxonEditor();
|
167
|
return editor == null ? false : editor.checkForEmptyNames();
|
168
|
}
|
169
|
|
170
|
public static boolean isRelatedConcept(Object selectedElement) {
|
171
|
if(selectedElement instanceof Taxon && ((Taxon) selectedElement).isRelatedConcept()){
|
172
|
return true;
|
173
|
}
|
174
|
return false;
|
175
|
}
|
176
|
|
177
|
public static boolean isTaxonBase(Object selectedElement) {
|
178
|
return (selectedElement instanceof TaxonBase) ? true : false;
|
179
|
}
|
180
|
|
181
|
public static boolean isMisapplication(Object selectedElement) {
|
182
|
if(selectedElement instanceof Taxon && ((Taxon) selectedElement).isMisapplication() ){
|
183
|
return true;
|
184
|
}
|
185
|
return false;
|
186
|
}
|
187
|
|
188
|
public static boolean isProparteSynonym(Object selectedElement) {
|
189
|
if(selectedElement instanceof Taxon && ((Taxon) selectedElement).isProparteSynonym()){
|
190
|
return true;
|
191
|
}
|
192
|
return false;
|
193
|
}
|
194
|
public static boolean isNotProparteSynonym(Object selectedElement) {
|
195
|
if (selectedElement instanceof Synonym){
|
196
|
return true;
|
197
|
}
|
198
|
if(!((Taxon) selectedElement).isProparteSynonym() ){
|
199
|
return true;
|
200
|
}
|
201
|
return false;
|
202
|
}
|
203
|
|
204
|
public static boolean isSynonym(Object selectedElement) {
|
205
|
return (selectedElement instanceof Synonym) ? true : false;
|
206
|
}
|
207
|
public static boolean isNotSynonym(Object selectedElement) {
|
208
|
return !isSynonym(selectedElement);
|
209
|
}
|
210
|
|
211
|
public static boolean isAccepted(Object selectedElement) {
|
212
|
return (selectedElement instanceof Taxon) ? true : false;
|
213
|
}
|
214
|
|
215
|
public static boolean isOrphaned(Object selectedElement) {
|
216
|
if(selectedElement instanceof Taxon){
|
217
|
return ((Taxon) selectedElement).isOrphaned();
|
218
|
}
|
219
|
else if(selectedElement instanceof Synonym){
|
220
|
return ((Synonym) selectedElement).isOrphaned();
|
221
|
}
|
222
|
return false;
|
223
|
}
|
224
|
|
225
|
/**
|
226
|
* @param selectedElement
|
227
|
* @return
|
228
|
*/
|
229
|
public static boolean isProParteSynonym(Object selectedElement) {
|
230
|
if(selectedElement instanceof Taxon && ((Taxon) selectedElement).isMisapplication()){
|
231
|
return true;
|
232
|
}
|
233
|
return false;
|
234
|
}
|
235
|
|
236
|
/**
|
237
|
* @param selectedElement
|
238
|
* @return
|
239
|
*/
|
240
|
public static boolean isNotInvalidDesignation(Object selectedElement) {
|
241
|
if((selectedElement instanceof Taxon) && !((Taxon) selectedElement).isInvalidDesignation()){
|
242
|
return true;
|
243
|
}
|
244
|
return false;
|
245
|
}
|
246
|
}
|