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
.apache
.log4j
.Logger
;
14 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
15 import org
.eclipse
.ui
.IEditorPart
;
17 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
18 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
19 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
20 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
21 import eu
.etaxonomy
.taxeditor
.editor
.Page
;
22 import eu
.etaxonomy
.taxeditor
.editor
.name
.TaxonNameEditor
;
25 * <p>NameEditorMenuPropertyTester class.</p>
28 * @created Jun 22, 2010
31 public class NameEditorMenuPropertyTester
extends org
.eclipse
.core
.expressions
.PropertyTester
{
33 private static final String ACCEPTED
= "isAcceptedTaxon";
34 private static final String SYNONYM
= "isSynonym";
35 private static final String MISAPPLICATION
= "isMisapplication";
36 private static final String TAXONBASE
= "isTaxonBase";
37 private static final String CONCEPT
= "isConceptRelation";
38 private static final String EMPTY_NAMES
= "hasEmptyNames";
41 * <p>Constructor for NameEditorMenuPropertyTester.</p>
43 public NameEditorMenuPropertyTester() {
47 * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
50 public boolean test(Object receiver
, String property
, Object
[] args
,
51 Object expectedValue
) {
53 if(receiver
instanceof IStructuredSelection
){
55 IStructuredSelection selection
= (IStructuredSelection
) receiver
;
57 Object selectedElement
= selection
.getFirstElement();
59 if(ACCEPTED
.equals(property
)){
60 return isAccepted(selectedElement
);
62 else if(SYNONYM
.equals(property
)){
63 return isSynonym(selectedElement
);
65 else if(MISAPPLICATION
.equals(property
)){
66 return isMisapplication(selectedElement
);
68 else if(TAXONBASE
.equals(property
)){
69 return isTaxonBase(selectedElement
);
71 else if(CONCEPT
.equals(property
)){
72 return isRelatedConcept(selectedElement
);
74 else if(EMPTY_NAMES
.equals(property
)){
75 return hasEmptyNames(receiver
);
87 private boolean hasEmptyNames(Object receiver
) {
88 return ((TaxonNameEditor
) EditorUtil
.getActiveEditorPage(Page
.NAME
)).checkForEmptyNames();
91 private boolean isRelatedConcept(Object selectedElement
) {
92 if(selectedElement
instanceof Taxon
&& ((Taxon
) selectedElement
).isRelatedConcept()){
98 private boolean isTaxonBase(Object selectedElement
) {
99 return (selectedElement
instanceof TaxonBase
) ?
true : false;
102 private boolean isMisapplication(Object selectedElement
) {
103 if(selectedElement
instanceof Taxon
&& ((Taxon
) selectedElement
).isMisapplication()){
109 private boolean isSynonym(Object selectedElement
) {
110 return (selectedElement
instanceof Synonym
) ?
true : false;
113 private boolean isAccepted(Object selectedElement
) {
114 return (selectedElement
instanceof Taxon
&& ! ((Taxon
) selectedElement
).isMisapplication()) ?
true : false;