+++ /dev/null
-// $Id$
-/**
-* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
-* http://www.e-taxonomy.eu
-*
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
-
-package eu.etaxonomy.taxeditor.editor.name.handler;
-
-import org.apache.log4j.Logger;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.ui.IEditorPart;
-
-import eu.etaxonomy.cdm.model.taxon.Synonym;
-import eu.etaxonomy.cdm.model.taxon.Taxon;
-import eu.etaxonomy.cdm.model.taxon.TaxonBase;
-import eu.etaxonomy.taxeditor.editor.EditorUtil;
-import eu.etaxonomy.taxeditor.editor.Page;
-import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
-
-/**
- * <p>NameEditorMenuPropertyTester class.</p>
- *
- * @author n.hoffmann
- * @created Jun 22, 2010
- * @version 1.0
- */
-public class NameEditorMenuPropertyTester extends org.eclipse.core.expressions.PropertyTester {
-
- private static final String ACCEPTED = "isAcceptedTaxon";
- private static final String SYNONYM = "isSynonym";
- private static final String MISAPPLICATION = "isMisapplication";
- private static final String TAXONBASE = "isTaxonBase";
- private static final String CONCEPT = "isConceptRelation";
- private static final String EMPTY_NAMES = "hasEmptyNames";
-
- /**
- * <p>Constructor for NameEditorMenuPropertyTester.</p>
- */
- public NameEditorMenuPropertyTester() {
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
- */
- /** {@inheritDoc} */
- public boolean test(Object receiver, String property, Object[] args,
- Object expectedValue) {
-
- if(receiver instanceof IStructuredSelection){
-
- IStructuredSelection selection = (IStructuredSelection) receiver;
-
- Object selectedElement = selection.getFirstElement();
-
- if(ACCEPTED.equals(property)){
- return isAccepted(selectedElement);
- }
- else if(SYNONYM.equals(property)){
- return isSynonym(selectedElement);
- }
- else if(MISAPPLICATION.equals(property)){
- return isMisapplication(selectedElement);
- }
- else if(TAXONBASE.equals(property)){
- return isTaxonBase(selectedElement);
- }
- else if(CONCEPT.equals(property)){
- return isRelatedConcept(selectedElement);
- }
- else if(EMPTY_NAMES.equals(property)){
- return hasEmptyNames(receiver);
- }
- }
-
- return false;
-
- }
-
- /**
- * @param receiver
- * @return
- */
- private boolean hasEmptyNames(Object receiver) {
- TaxonNameEditor editor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(Page.NAME);
- return editor == null ? false : editor.checkForEmptyNames();
- }
-
- private boolean isRelatedConcept(Object selectedElement) {
- if(selectedElement instanceof Taxon && ((Taxon) selectedElement).isRelatedConcept()){
- return true;
- }
- return false;
- }
-
- private boolean isTaxonBase(Object selectedElement) {
- return (selectedElement instanceof TaxonBase) ? true : false;
- }
-
- private boolean isMisapplication(Object selectedElement) {
- if(selectedElement instanceof Taxon && ((Taxon) selectedElement).isMisapplication()){
- return true;
- }
- return false;
- }
-
- private boolean isSynonym(Object selectedElement) {
- return (selectedElement instanceof Synonym) ? true : false;
- }
-
- private boolean isAccepted(Object selectedElement) {
- return (selectedElement instanceof Taxon && ! ((Taxon) selectedElement).isMisapplication()) ? true : false;
- }
-}