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(NOT_ACCEPTED
.equals(property
)){
72 return !isAccepted(selectedElement
);
74 if(ACCEPTED
.equals(property
)){
75 return isAccepted(selectedElement
);
77 else if(SYNONYM
.equals(property
)){
78 return isSynonym(selectedElement
);
80 else if(NOT_SYNONYM
.equals(property
)){
81 return isNotSynonym(selectedElement
);
83 else if(MISAPPLICATION
.equals(property
)){
84 return isMisapplication(selectedElement
);
86 else if(PROPARTE_SYNONYM
.equals(property
)){
87 return isProparteSynonym(selectedElement
);
89 else if(NOT_PROPARTE_SYNONYM
.equals(property
)){
90 return isNotProparteSynonym(selectedElement
);
92 else if(NOT_MISAPPLICATION
.equals(property
)){
93 return isNotMisapplication(selectedElement
);
95 else if(TAXONBASE
.equals(property
)){
96 return isTaxonBase(selectedElement
);
98 else if(CONCEPT
.equals(property
)){
99 return isRelatedConcept(selectedElement
);
101 else if(EMPTY_NAMES
.equals(property
)){
102 return hasEmptyNames(receiver
);
104 else if(ACCEPTED_AND_NO_HOMOTYPIC_SYNONYMS
.equals(property
)){
105 return isAcceptedAndHasNoHomotypicSynonyms(selectedElement
);
107 else if (NOT_HOMOTYPIC_SYNONYM_OF_ACCEPTED
.equals(property
)){
108 return isNotHomotypicSynonymOfAcceptedTaxon(selectedElement
);
110 else if (SYNONYM_WITH_HOMOTYPIC_SYNONYMS
.equals(property
)){
111 return isSynonymInHomotypicalGroupWithMoreSynonyms(selectedElement
);
113 else if (IS_ORPHANED
.equals(property
)){
114 return isOrphaned(selectedElement
);
115 }else if (IS_NOT_INVALID_DESIGNATION
.equals(property
)){
116 return isNotInvalidDesignation(selectedElement
);
125 public static boolean isAcceptedAndHasNoHomotypicSynonyms(Object selectedElement
) {
126 if (isAccepted(selectedElement
)){
127 Taxon taxon
= (Taxon
) selectedElement
;
128 return taxon
.getSynonymsInGroup(taxon
.getHomotypicGroup()).isEmpty();
132 public static boolean isNotAcceptedTaxon(Object selectedElement
) {
134 return !isAccepted(selectedElement
);
137 public static boolean isNotMisapplication(Object selectedElement
) {
139 return !isMisapplication(selectedElement
);
142 public static boolean isSynonymInHomotypicalGroupWithMoreSynonyms(Object selectedElement
) {
143 if (isSynonym(selectedElement
)){
144 Synonym synonym
= (Synonym
) selectedElement
;
145 return synonym
.getHomotypicGroup().getTypifiedNames().size()>1;
151 public static boolean isNotHomotypicSynonymOfAcceptedTaxon(Object selectedElement
) {
152 if (isSynonym(selectedElement
)){
153 Synonym synonym
= (Synonym
) selectedElement
;
154 Taxon taxon
= synonym
.getAcceptedTaxon();
156 taxon
.getHomotypicGroup().equals(synonym
.getHomotypicGroup())){
168 public static boolean hasEmptyNames(Object receiver
) {
169 TaxonNameEditorE4 editor
= (TaxonNameEditorE4
) EventUtility
.getTaxonEditor();
170 return editor
== null ?
false : editor
.checkForEmptyNames();
173 public static boolean isRelatedConcept(Object selectedElement
) {
174 if(selectedElement
instanceof Taxon
&& ((Taxon
) selectedElement
).isRelatedConcept()){
180 public static boolean isTaxonBase(Object selectedElement
) {
181 return (selectedElement
instanceof TaxonBase
) ?
true : false;
184 public static boolean isMisapplication(Object selectedElement
) {
185 if(selectedElement
instanceof Taxon
&& ((Taxon
) selectedElement
).isMisapplication() ){
191 public static boolean isProparteSynonym(Object selectedElement
) {
192 if(selectedElement
instanceof Taxon
&& ((Taxon
) selectedElement
).isProparteSynonym()){
197 public static boolean isNotProparteSynonym(Object selectedElement
) {
198 if (selectedElement
instanceof Synonym
){
201 if(((Taxon
) selectedElement
).isProparteSynonym() ){
207 public static boolean isSynonym(Object selectedElement
) {
208 return (selectedElement
instanceof Synonym
) ?
true : false;
210 public static boolean isNotSynonym(Object selectedElement
) {
211 return !isSynonym(selectedElement
);
214 public static boolean isAccepted(Object selectedElement
) {
215 return (selectedElement
instanceof Taxon
&& !(((Taxon
) selectedElement
).isMisapplication()|| ((Taxon
) selectedElement
).isProparteSynonym() || ((Taxon
) selectedElement
).isInvalidDesignation())) ?
true : false;
218 public static boolean isOrphaned(Object selectedElement
) {
219 if(selectedElement
instanceof Taxon
){
220 return ((Taxon
) selectedElement
).isOrphaned();
222 else if(selectedElement
instanceof Synonym
){
223 return ((Synonym
) selectedElement
).isOrphaned();
229 * @param selectedElement
232 public static boolean isProParteSynonym(Object selectedElement
) {
233 if(selectedElement
instanceof Taxon
&& ((Taxon
) selectedElement
).isProparteSynonym()){
240 * @param selectedElement
243 public static boolean isNotInvalidDesignation(Object selectedElement
) {
244 if (selectedElement
instanceof Synonym
){
247 if(((Taxon
) selectedElement
).isInvalidDesignation() ){