had to rename the packages to make them compliant with buckminster
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / name / handler / NameEditorMenuPropertyTester.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
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.
9 */
10
11 package eu.etaxonomy.taxeditor.editor.name.handler;
12
13 import org.apache.log4j.Logger;
14 import org.eclipse.jface.viewers.IStructuredSelection;
15 import org.eclipse.ui.IEditorPart;
16
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;
23
24 /**
25 * <p>NameEditorMenuPropertyTester class.</p>
26 *
27 * @author n.hoffmann
28 * @created Jun 22, 2010
29 * @version 1.0
30 */
31 public class NameEditorMenuPropertyTester extends org.eclipse.core.expressions.PropertyTester {
32
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";
39
40 /**
41 * <p>Constructor for NameEditorMenuPropertyTester.</p>
42 */
43 public NameEditorMenuPropertyTester() {
44 }
45
46 /* (non-Javadoc)
47 * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
48 */
49 /** {@inheritDoc} */
50 public boolean test(Object receiver, String property, Object[] args,
51 Object expectedValue) {
52
53 if(receiver instanceof IStructuredSelection){
54
55 IStructuredSelection selection = (IStructuredSelection) receiver;
56
57 Object selectedElement = selection.getFirstElement();
58
59 if(ACCEPTED.equals(property)){
60 return isAccepted(selectedElement);
61 }
62 else if(SYNONYM.equals(property)){
63 return isSynonym(selectedElement);
64 }
65 else if(MISAPPLICATION.equals(property)){
66 return isMisapplication(selectedElement);
67 }
68 else if(TAXONBASE.equals(property)){
69 return isTaxonBase(selectedElement);
70 }
71 else if(CONCEPT.equals(property)){
72 return isRelatedConcept(selectedElement);
73 }
74 else if(EMPTY_NAMES.equals(property)){
75 return hasEmptyNames(receiver);
76 }
77 }
78
79 return false;
80
81 }
82
83 /**
84 * @param receiver
85 * @return
86 */
87 private boolean hasEmptyNames(Object receiver) {
88 TaxonNameEditor editor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(Page.NAME);
89 return editor == null ? false : editor.checkForEmptyNames();
90 }
91
92 private boolean isRelatedConcept(Object selectedElement) {
93 if(selectedElement instanceof Taxon && ((Taxon) selectedElement).isRelatedConcept()){
94 return true;
95 }
96 return false;
97 }
98
99 private boolean isTaxonBase(Object selectedElement) {
100 return (selectedElement instanceof TaxonBase) ? true : false;
101 }
102
103 private boolean isMisapplication(Object selectedElement) {
104 if(selectedElement instanceof Taxon && ((Taxon) selectedElement).isMisapplication()){
105 return true;
106 }
107 return false;
108 }
109
110 private boolean isSynonym(Object selectedElement) {
111 return (selectedElement instanceof Synonym) ? true : false;
112 }
113
114 private boolean isAccepted(Object selectedElement) {
115 return (selectedElement instanceof Taxon && ! ((Taxon) selectedElement).isMisapplication()) ? true : false;
116 }
117 }