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 MISAPPLICATION = "isMisapplication"; //$NON-NLS-1$
|
37
|
private static final String TAXONBASE = "isTaxonBase"; //$NON-NLS-1$
|
38
|
private static final String CONCEPT = "isConceptRelation"; //$NON-NLS-1$
|
39
|
private static final String EMPTY_NAMES = "hasEmptyNames"; //$NON-NLS-1$
|
40
|
private static final String ACCEPTED_AND_NO_HOMOTYPIC_SYNONYMS = "isAcceptedAndHasNoHomotypicSynonyms"; //$NON-NLS-1$
|
41
|
private static final String NOT_HOMOTYPIC_SYNONYM_OF_ACCEPTED = "isNotHomotypicSynonymOfAcceptedTaxon"; //$NON-NLS-1$
|
42
|
private static final String SYNONYM_WITH_HOMOTYPIC_SYNONYMS = "isSynonymInHomotypicalGroupWithMoreSynonyms"; //$NON-NLS-1$
|
43
|
private static final String IS_ORPHANED = "isOrphaned"; //$NON-NLS-1$
|
44
|
|
45
|
/**
|
46
|
* <p>Constructor for NameEditorMenuPropertyTester.</p>
|
47
|
*/
|
48
|
public NameEditorMenuPropertyTester() {
|
49
|
}
|
50
|
|
51
|
/** {@inheritDoc} */
|
52
|
@Override
|
53
|
public boolean test(Object receiver, String property, Object[] args,
|
54
|
Object expectedValue) {
|
55
|
|
56
|
if(receiver instanceof IStructuredSelection){
|
57
|
|
58
|
IStructuredSelection selection = (IStructuredSelection) receiver;
|
59
|
|
60
|
Object selectedElement = selection.getFirstElement();
|
61
|
if(selectedElement instanceof UuidAndTitleCache){
|
62
|
UuidAndTitleCache uuidAndTitleCache = (UuidAndTitleCache<?>)selectedElement;
|
63
|
CdmBase cdmBase = CdmStore.getCommonService().find(uuidAndTitleCache.getType(), uuidAndTitleCache.getUuid());
|
64
|
selectedElement = cdmBase;
|
65
|
}
|
66
|
if(NOT_ACCEPTED.equals(property)){
|
67
|
return !isAccepted(selectedElement);
|
68
|
}
|
69
|
if(ACCEPTED.equals(property)){
|
70
|
return isAccepted(selectedElement);
|
71
|
}
|
72
|
else if(SYNONYM.equals(property)){
|
73
|
return isSynonym(selectedElement);
|
74
|
}
|
75
|
else if(MISAPPLICATION.equals(property)){
|
76
|
return isMisapplication(selectedElement);
|
77
|
}
|
78
|
else if(TAXONBASE.equals(property)){
|
79
|
return isTaxonBase(selectedElement);
|
80
|
}
|
81
|
else if(CONCEPT.equals(property)){
|
82
|
return isRelatedConcept(selectedElement);
|
83
|
}
|
84
|
else if(EMPTY_NAMES.equals(property)){
|
85
|
return hasEmptyNames(receiver);
|
86
|
}
|
87
|
else if(ACCEPTED_AND_NO_HOMOTYPIC_SYNONYMS.equals(property)){
|
88
|
return isAcceptedAndHasNoHomotypicSynonyms(selectedElement);
|
89
|
}
|
90
|
else if (NOT_HOMOTYPIC_SYNONYM_OF_ACCEPTED.equals(property)){
|
91
|
return isNotHomotypicSynonymOfAcceptedTaxon(selectedElement);
|
92
|
}
|
93
|
else if (SYNONYM_WITH_HOMOTYPIC_SYNONYMS.equals(property)){
|
94
|
return isSynonymInHomotypicalGroupWithMoreSynonyms(selectedElement);
|
95
|
}
|
96
|
else if (IS_ORPHANED.equals(property)){
|
97
|
return isOrphaned(selectedElement);
|
98
|
}
|
99
|
|
100
|
}
|
101
|
|
102
|
return false;
|
103
|
|
104
|
}
|
105
|
|
106
|
public static boolean isAcceptedAndHasNoHomotypicSynonyms(Object selectedElement) {
|
107
|
if (isAccepted(selectedElement)){
|
108
|
Taxon taxon = (Taxon) selectedElement;
|
109
|
return taxon.getSynonymsInGroup(taxon.getHomotypicGroup()).isEmpty();
|
110
|
}
|
111
|
return false;
|
112
|
}
|
113
|
public static boolean isNotAcceptedTaxon(Object selectedElement) {
|
114
|
|
115
|
return !isAccepted(selectedElement);
|
116
|
}
|
117
|
|
118
|
public static 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
|
public static boolean isNotHomotypicSynonymOfAcceptedTaxon(Object selectedElement) {
|
128
|
if (isSynonym(selectedElement)){
|
129
|
Synonym synonym = (Synonym) selectedElement;
|
130
|
Taxon taxon = synonym.getAcceptedTaxon();
|
131
|
if (taxon != null &&
|
132
|
taxon.getHomotypicGroup().equals(synonym.getHomotypicGroup())){
|
133
|
return false;
|
134
|
}
|
135
|
}
|
136
|
return true;
|
137
|
}
|
138
|
|
139
|
|
140
|
/**
|
141
|
* @param receiver
|
142
|
* @return
|
143
|
*/
|
144
|
public static boolean hasEmptyNames(Object receiver) {
|
145
|
TaxonNameEditorE4 editor = (TaxonNameEditorE4) EventUtility.getTaxonEditor();
|
146
|
return editor == null ? false : editor.checkForEmptyNames();
|
147
|
}
|
148
|
|
149
|
public static boolean isRelatedConcept(Object selectedElement) {
|
150
|
if(selectedElement instanceof Taxon && ((Taxon) selectedElement).isRelatedConcept()){
|
151
|
return true;
|
152
|
}
|
153
|
return false;
|
154
|
}
|
155
|
|
156
|
public static boolean isTaxonBase(Object selectedElement) {
|
157
|
return (selectedElement instanceof TaxonBase) ? true : false;
|
158
|
}
|
159
|
|
160
|
public static boolean isMisapplication(Object selectedElement) {
|
161
|
if(selectedElement instanceof Taxon && ((Taxon) selectedElement).isMisapplication()){
|
162
|
return true;
|
163
|
}
|
164
|
return false;
|
165
|
}
|
166
|
|
167
|
public static boolean isSynonym(Object selectedElement) {
|
168
|
return (selectedElement instanceof Synonym) ? true : false;
|
169
|
}
|
170
|
|
171
|
public static boolean isAccepted(Object selectedElement) {
|
172
|
return (selectedElement instanceof Taxon && ! ((Taxon) selectedElement).isMisapplication()) ? true : false;
|
173
|
}
|
174
|
|
175
|
public static boolean isOrphaned(Object selectedElement) {
|
176
|
if(selectedElement instanceof Taxon){
|
177
|
return ((Taxon) selectedElement).isOrphaned();
|
178
|
}
|
179
|
else if(selectedElement instanceof Synonym){
|
180
|
return ((Synonym) selectedElement).isOrphaned();
|
181
|
}
|
182
|
return false;
|
183
|
}
|
184
|
}
|