3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.editor
.name
.handler
;
13 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
15 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
16 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
17 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
18 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
19 import eu
.etaxonomy
.taxeditor
.editor
.Page
;
20 import eu
.etaxonomy
.taxeditor
.editor
.name
.TaxonNameEditor
;
23 * <p>NameEditorMenuPropertyTester class.</p>
26 * @created Jun 22, 2010
29 public class NameEditorMenuPropertyTester
extends org
.eclipse
.core
.expressions
.PropertyTester
{
31 private static final String ACCEPTED
= "isAcceptedTaxon";
32 private static final String SYNONYM
= "isSynonym";
33 private static final String MISAPPLICATION
= "isMisapplication";
34 private static final String TAXONBASE
= "isTaxonBase";
35 private static final String CONCEPT
= "isConceptRelation";
36 private static final String EMPTY_NAMES
= "hasEmptyNames";
37 private static final String ACCEPTED_AND_NO_HOMOTYPIC_SYNONYMS
= "isAcceptedAndHasNoHomotypicSynonyms";
40 * <p>Constructor for NameEditorMenuPropertyTester.</p>
42 public NameEditorMenuPropertyTester() {
46 * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
49 public boolean test(Object receiver
, String property
, Object
[] args
,
50 Object expectedValue
) {
52 if(receiver
instanceof IStructuredSelection
){
54 IStructuredSelection selection
= (IStructuredSelection
) receiver
;
56 Object selectedElement
= selection
.getFirstElement();
58 System
.out
.println(selectedElement
);
59 System
.out
.println(property
);
60 if(ACCEPTED
.equals(property
)){
61 return isAccepted(selectedElement
);
63 else if(SYNONYM
.equals(property
)){
64 System
.out
.println(isSynonym(selectedElement
));
65 return isSynonym(selectedElement
);
67 else if(MISAPPLICATION
.equals(property
)){
68 return isMisapplication(selectedElement
);
70 else if(TAXONBASE
.equals(property
)){
71 return isTaxonBase(selectedElement
);
73 else if(CONCEPT
.equals(property
)){
74 return isRelatedConcept(selectedElement
);
76 else if(EMPTY_NAMES
.equals(property
)){
77 return hasEmptyNames(receiver
);
79 else if(ACCEPTED_AND_NO_HOMOTYPIC_SYNONYMS
.equals(property
)){
80 return isAcceptedAndHasNoHomotypicSynonyms(selectedElement
);
88 private boolean isAcceptedAndHasNoHomotypicSynonyms(Object selectedElement
) {
89 if (isAccepted(selectedElement
)){
90 Taxon taxon
= (Taxon
) selectedElement
;
91 return taxon
.getSynonymsInGroup(taxon
.getHomotypicGroup()).isEmpty();
100 private boolean hasEmptyNames(Object receiver
) {
101 TaxonNameEditor editor
= (TaxonNameEditor
) EditorUtil
.getActiveEditorPage(Page
.NAME
);
102 return editor
== null ?
false : editor
.checkForEmptyNames();
105 private boolean isRelatedConcept(Object selectedElement
) {
106 if(selectedElement
instanceof Taxon
&& ((Taxon
) selectedElement
).isRelatedConcept()){
112 private boolean isTaxonBase(Object selectedElement
) {
113 return (selectedElement
instanceof TaxonBase
) ?
true : false;
116 private boolean isMisapplication(Object selectedElement
) {
117 if(selectedElement
instanceof Taxon
&& ((Taxon
) selectedElement
).isMisapplication()){
123 private boolean isSynonym(Object selectedElement
) {
124 System
.out
.println("isSynonym...." + selectedElement
);
125 return (selectedElement
instanceof Synonym
) ?
true : false;
128 private boolean isAccepted(Object selectedElement
) {
129 return (selectedElement
instanceof Taxon
&& ! ((Taxon
) selectedElement
).isMisapplication()) ?
true : false;