2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.editor
.name
.handler
;
12 import org
.eclipse
.core
.expressions
.PropertyTester
;
13 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
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
;
25 * <p>NameEditorMenuPropertyTester class.</p>
28 * @created Jun 22, 2010
31 public class NameEditorMenuPropertyTester
extends PropertyTester
{
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$
51 * <p>Constructor for NameEditorMenuPropertyTester.</p>
53 public NameEditorMenuPropertyTester() {
58 public boolean test(Object receiver
, String property
, Object
[] args
,
59 Object expectedValue
) {
61 if(receiver
instanceof IStructuredSelection
){
63 IStructuredSelection selection
= (IStructuredSelection
) receiver
;
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
;
71 if(EMPTY_NAMES
.equals(property
)){
72 return hasEmptyNames(receiver
);
74 else if(selectedElement
==null){
77 else if(NOT_ACCEPTED
.equals(property
)){
78 return !isAccepted(selectedElement
);
80 else if(ACCEPTED
.equals(property
)){
81 return isAccepted(selectedElement
);
83 else if(SYNONYM
.equals(property
)){
84 return isSynonym(selectedElement
);
86 else if(NOT_SYNONYM
.equals(property
)){
87 return isNotSynonym(selectedElement
);
89 else if(MISAPPLICATION
.equals(property
)){
90 return isMisapplication(selectedElement
);
92 else if(PROPARTE_SYNONYM
.equals(property
)){
93 return isProparteSynonym(selectedElement
);
95 else if(NOT_PROPARTE_SYNONYM
.equals(property
)){
96 return isNotProparteSynonym(selectedElement
);
98 else if(NOT_MISAPPLICATION
.equals(property
)){
99 return isNotMisapplication(selectedElement
);
101 else if(TAXONBASE
.equals(property
)){
102 return isTaxonBase(selectedElement
);
104 else if(CONCEPT
.equals(property
)){
105 return isRelatedConcept(selectedElement
);
107 else if(ACCEPTED_AND_NO_HOMOTYPIC_SYNONYMS
.equals(property
)){
108 return isAcceptedAndHasNoHomotypicSynonyms(selectedElement
);
110 else if (NOT_HOMOTYPIC_SYNONYM_OF_ACCEPTED
.equals(property
)){
111 return isNotHomotypicSynonymOfAcceptedTaxon(selectedElement
);
113 else if (SYNONYM_WITH_HOMOTYPIC_SYNONYMS
.equals(property
)){
114 return isSynonymInHomotypicalGroupWithMoreSynonyms(selectedElement
);
116 else if (IS_ORPHANED
.equals(property
)){
117 return isOrphaned(selectedElement
);
119 else if (IS_NOT_INVALID_DESIGNATION
.equals(property
)){
120 return isNotInvalidDesignation(selectedElement
);
127 public static boolean isAcceptedAndHasNoHomotypicSynonyms(Object selectedElement
) {
128 if (isAccepted(selectedElement
)){
129 Taxon taxon
= (Taxon
) selectedElement
;
130 return taxon
.getSynonymsInGroup(taxon
.getHomotypicGroup()).isEmpty();
134 public static boolean isNotAcceptedTaxon(Object selectedElement
) {
136 return !isAccepted(selectedElement
);
139 public static boolean isNotMisapplication(Object selectedElement
) {
141 return !isMisapplication(selectedElement
);
144 public static boolean isSynonymInHomotypicalGroupWithMoreSynonyms(Object selectedElement
) {
145 if (isSynonym(selectedElement
)){
146 Synonym synonym
= (Synonym
) selectedElement
;
147 return synonym
.getHomotypicGroup().getTypifiedNames().size()>1;
153 public static boolean isNotHomotypicSynonymOfAcceptedTaxon(Object selectedElement
) {
154 if (isSynonym(selectedElement
)){
155 Synonym synonym
= (Synonym
) selectedElement
;
156 Taxon taxon
= synonym
.getAcceptedTaxon();
158 taxon
.getHomotypicGroup().equals(synonym
.getHomotypicGroup())){
170 public static boolean hasEmptyNames(Object receiver
) {
171 TaxonNameEditorE4 editor
= (TaxonNameEditorE4
) EventUtility
.getTaxonEditor();
172 return editor
== null ?
false : editor
.checkForEmptyNames();
175 public static boolean isRelatedConcept(Object selectedElement
) {
176 if(selectedElement
instanceof Taxon
&& ((Taxon
) selectedElement
).isRelatedConcept()){
182 public static boolean isTaxonBase(Object selectedElement
) {
183 return (selectedElement
instanceof TaxonBase
) ?
true : false;
186 public static boolean isMisapplication(Object selectedElement
) {
187 if(selectedElement
instanceof Taxon
&& ((Taxon
) selectedElement
).isMisapplication() ){
193 public static boolean isProparteSynonym(Object selectedElement
) {
194 if(selectedElement
instanceof Taxon
&& ((Taxon
) selectedElement
).isProparteSynonym()){
199 public static boolean isNotProparteSynonym(Object selectedElement
) {
200 if (selectedElement
instanceof Synonym
){
203 if(((Taxon
) selectedElement
).isProparteSynonym() ){
209 public static boolean isSynonym(Object selectedElement
) {
210 return (selectedElement
instanceof Synonym
) ?
true : false;
212 public static boolean isNotSynonym(Object selectedElement
) {
213 return !isSynonym(selectedElement
);
216 public static boolean isAccepted(Object selectedElement
) {
217 return (selectedElement
instanceof Taxon
&& !(((Taxon
) selectedElement
).isMisapplication()|| ((Taxon
) selectedElement
).isProparteSynonym() || ((Taxon
) selectedElement
).isInvalidDesignation())) ?
true : false;
220 public static boolean isOrphaned(Object selectedElement
) {
221 if(selectedElement
instanceof Taxon
){
222 return ((Taxon
) selectedElement
).isOrphaned();
224 else if(selectedElement
instanceof Synonym
){
225 return ((Synonym
) selectedElement
).isOrphaned();
231 * @param selectedElement
234 public static boolean isProParteSynonym(Object selectedElement
) {
235 if(selectedElement
instanceof Taxon
&& ((Taxon
) selectedElement
).isProparteSynonym()){
242 * @param selectedElement
245 public static boolean isNotInvalidDesignation(Object selectedElement
) {
246 if (selectedElement
instanceof Synonym
){
249 if(((Taxon
) selectedElement
).isInvalidDesignation() ){