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 if(ACCEPTED
.equals(property
)){
59 return isAccepted(selectedElement
);
61 else if(SYNONYM
.equals(property
)){
62 return isSynonym(selectedElement
);
64 else if(MISAPPLICATION
.equals(property
)){
65 return isMisapplication(selectedElement
);
67 else if(TAXONBASE
.equals(property
)){
68 return isTaxonBase(selectedElement
);
70 else if(CONCEPT
.equals(property
)){
71 return isRelatedConcept(selectedElement
);
73 else if(EMPTY_NAMES
.equals(property
)){
74 return hasEmptyNames(receiver
);
76 else if(ACCEPTED_AND_NO_HOMOTYPIC_SYNONYMS
.equals(property
)){
77 return isAcceptedAndHasNoHomotypicSynonyms(selectedElement
);
85 private boolean isAcceptedAndHasNoHomotypicSynonyms(Object selectedElement
) {
86 if (isAccepted(selectedElement
)){
87 Taxon taxon
= (Taxon
) selectedElement
;
88 return taxon
.getSynonymsInGroup(taxon
.getHomotypicGroup()).isEmpty();
97 private boolean hasEmptyNames(Object receiver
) {
98 TaxonNameEditor editor
= (TaxonNameEditor
) EditorUtil
.getActiveEditorPage(Page
.NAME
);
99 return editor
== null ?
false : editor
.checkForEmptyNames();
102 private boolean isRelatedConcept(Object selectedElement
) {
103 if(selectedElement
instanceof Taxon
&& ((Taxon
) selectedElement
).isRelatedConcept()){
109 private boolean isTaxonBase(Object selectedElement
) {
110 return (selectedElement
instanceof TaxonBase
) ?
true : false;
113 private boolean isMisapplication(Object selectedElement
) {
114 if(selectedElement
instanceof Taxon
&& ((Taxon
) selectedElement
).isMisapplication()){
120 private boolean isSynonym(Object selectedElement
) {
121 return (selectedElement
instanceof Synonym
) ?
true : false;
124 private boolean isAccepted(Object selectedElement
) {
125 return (selectedElement
instanceof Taxon
&& ! ((Taxon
) selectedElement
).isMisapplication()) ?
true : false;