1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.taxeditor.editor.name.handler;
|
12
|
|
13
|
import java.util.Set;
|
14
|
|
15
|
import org.eclipse.core.expressions.PropertyTester;
|
16
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
17
|
|
18
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
19
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
20
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
21
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
22
|
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
|
23
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
24
|
import eu.etaxonomy.taxeditor.editor.Page;
|
25
|
import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
|
26
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
27
|
|
28
|
/**
|
29
|
* <p>NameEditorMenuPropertyTester class.</p>
|
30
|
*
|
31
|
* @author n.hoffmann
|
32
|
* @created Jun 22, 2010
|
33
|
* @version 1.0
|
34
|
*/
|
35
|
public class NameEditorMenuPropertyTester extends PropertyTester {
|
36
|
|
37
|
private static final String ACCEPTED = "isAcceptedTaxon";
|
38
|
private static final String SYNONYM = "isSynonym";
|
39
|
private static final String MISAPPLICATION = "isMisapplication";
|
40
|
private static final String TAXONBASE = "isTaxonBase";
|
41
|
private static final String CONCEPT = "isConceptRelation";
|
42
|
private static final String EMPTY_NAMES = "hasEmptyNames";
|
43
|
private static final String ACCEPTED_AND_NO_HOMOTYPIC_SYNONYMS = "isAcceptedAndHasNoHomotypicSynonyms";
|
44
|
private static final String NOT_HOMOTYPIC_SYNONYM_OF_ACCEPTED = "isNotHomotypicSynonymOfAcceptedTaxon";
|
45
|
private static final String SYNONYM_WITH_HOMOTYPIC_SYNONYMS = "isSynonymInHomotypicalGroupWithMoreSynonyms";
|
46
|
private static final String IS_ORPHANED = "isOrphaned";
|
47
|
|
48
|
/**
|
49
|
* <p>Constructor for NameEditorMenuPropertyTester.</p>
|
50
|
*/
|
51
|
public NameEditorMenuPropertyTester() {
|
52
|
}
|
53
|
|
54
|
/* (non-Javadoc)
|
55
|
* @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
|
56
|
*/
|
57
|
/** {@inheritDoc} */
|
58
|
@Override
|
59
|
public boolean test(Object receiver, String property, Object[] args,
|
60
|
Object expectedValue) {
|
61
|
|
62
|
if(receiver instanceof IStructuredSelection){
|
63
|
|
64
|
IStructuredSelection selection = (IStructuredSelection) receiver;
|
65
|
|
66
|
Object selectedElement = selection.getFirstElement();
|
67
|
if(selectedElement instanceof UuidAndTitleCache){
|
68
|
UuidAndTitleCache uuidAndTitleCache = (UuidAndTitleCache<?>)selectedElement;
|
69
|
CdmBase cdmBase = CdmStore.getCommonService().find(uuidAndTitleCache.getType(), uuidAndTitleCache.getUuid());
|
70
|
selectedElement = cdmBase;
|
71
|
}
|
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(MISAPPLICATION.equals(property)){
|
80
|
return isMisapplication(selectedElement);
|
81
|
}
|
82
|
else if(TAXONBASE.equals(property)){
|
83
|
return isTaxonBase(selectedElement);
|
84
|
}
|
85
|
else if(CONCEPT.equals(property)){
|
86
|
return isRelatedConcept(selectedElement);
|
87
|
}
|
88
|
else if(EMPTY_NAMES.equals(property)){
|
89
|
return hasEmptyNames(receiver);
|
90
|
}
|
91
|
else if(ACCEPTED_AND_NO_HOMOTYPIC_SYNONYMS.equals(property)){
|
92
|
return isAcceptedAndHasNoHomotypicSynonyms(selectedElement);
|
93
|
}
|
94
|
else if (NOT_HOMOTYPIC_SYNONYM_OF_ACCEPTED.equals(property)){
|
95
|
return isNotHomotypicSynonymOfAcceptedTaxon(selectedElement);
|
96
|
}
|
97
|
else if (SYNONYM_WITH_HOMOTYPIC_SYNONYMS.equals(property)){
|
98
|
return isSynonymInHomotypicalGroupWithMoreSynonyms(selectedElement);
|
99
|
}
|
100
|
else if (IS_ORPHANED.equals(property)){
|
101
|
return isOrphaned(selectedElement);
|
102
|
}
|
103
|
|
104
|
}
|
105
|
|
106
|
return false;
|
107
|
|
108
|
}
|
109
|
|
110
|
private boolean isAcceptedAndHasNoHomotypicSynonyms(Object selectedElement) {
|
111
|
if (isAccepted(selectedElement)){
|
112
|
Taxon taxon = (Taxon) selectedElement;
|
113
|
return taxon.getSynonymsInGroup(taxon.getHomotypicGroup()).isEmpty();
|
114
|
}
|
115
|
return false;
|
116
|
}
|
117
|
|
118
|
private boolean isSynonymInHomotypicalGroupWithMoreSynonyms(Object selectedElement) {
|
119
|
if (isSynonym(selectedElement)){
|
120
|
Synonym synonym = (Synonym) selectedElement;
|
121
|
return synonym.getHomotypicGroup().getTypifiedNames().size()>1;
|
122
|
}
|
123
|
return false;
|
124
|
}
|
125
|
|
126
|
|
127
|
private boolean isNotHomotypicSynonymOfAcceptedTaxon(Object selectedElement) {
|
128
|
if (isSynonym(selectedElement)){
|
129
|
Synonym synonym = (Synonym) selectedElement;
|
130
|
for (Taxon taxon:synonym.getAcceptedTaxa()){
|
131
|
if (taxon.getHomotypicGroup().equals(synonym.getHomotypicGroup())){
|
132
|
return false;
|
133
|
}
|
134
|
}
|
135
|
}
|
136
|
return true;
|
137
|
}
|
138
|
|
139
|
|
140
|
/**
|
141
|
* @param receiver
|
142
|
* @return
|
143
|
*/
|
144
|
private boolean hasEmptyNames(Object receiver) {
|
145
|
TaxonNameEditor editor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(Page.NAME);
|
146
|
return editor == null ? false : editor.checkForEmptyNames();
|
147
|
}
|
148
|
|
149
|
private boolean isRelatedConcept(Object selectedElement) {
|
150
|
if(selectedElement instanceof Taxon && ((Taxon) selectedElement).isRelatedConcept()){
|
151
|
return true;
|
152
|
}
|
153
|
return false;
|
154
|
}
|
155
|
|
156
|
private boolean isTaxonBase(Object selectedElement) {
|
157
|
return (selectedElement instanceof TaxonBase) ? true : false;
|
158
|
}
|
159
|
|
160
|
private boolean isMisapplication(Object selectedElement) {
|
161
|
if(selectedElement instanceof Taxon && ((Taxon) selectedElement).isMisapplication()){
|
162
|
return true;
|
163
|
}
|
164
|
return false;
|
165
|
}
|
166
|
|
167
|
private boolean isSynonym(Object selectedElement) {
|
168
|
return (selectedElement instanceof Synonym) ? true : false;
|
169
|
}
|
170
|
|
171
|
private boolean isAccepted(Object selectedElement) {
|
172
|
return (selectedElement instanceof Taxon && ! ((Taxon) selectedElement).isMisapplication()) ? true : false;
|
173
|
}
|
174
|
|
175
|
private boolean isOrphaned(Object selectedElement) {
|
176
|
if(selectedElement instanceof Taxon){
|
177
|
return ((Taxon) selectedElement).isOrphaned();
|
178
|
}
|
179
|
else if(selectedElement instanceof Synonym){
|
180
|
Set<Taxon> acceptedTaxa = ((Synonym) selectedElement).getAcceptedTaxa();
|
181
|
for (Taxon taxon : acceptedTaxa) {
|
182
|
if(!taxon.isOrphaned()){
|
183
|
return false;
|
184
|
}
|
185
|
}
|
186
|
}
|
187
|
return false;
|
188
|
}
|
189
|
}
|