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