Project

General

Profile

Download (5.76 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

    
10
package eu.etaxonomy.taxeditor.editor.name.handler;
11

    
12
import org.eclipse.core.expressions.PropertyTester;
13
import org.eclipse.jface.viewers.IStructuredSelection;
14

    
15
import eu.etaxonomy.cdm.model.common.CdmBase;
16
import eu.etaxonomy.cdm.model.taxon.Synonym;
17
import eu.etaxonomy.cdm.model.taxon.Taxon;
18
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
19
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
20
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
21
import eu.etaxonomy.taxeditor.event.EventUtility;
22
import eu.etaxonomy.taxeditor.store.CdmStore;
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 PropertyTester {
32

    
33
	private static final String ACCEPTED = "isAcceptedTaxon"; //$NON-NLS-1$
34
	private static final String SYNONYM = "isSynonym"; //$NON-NLS-1$
35
	private static final String MISAPPLICATION = "isMisapplication"; //$NON-NLS-1$
36
	private static final String TAXONBASE = "isTaxonBase"; //$NON-NLS-1$
37
	private static final String CONCEPT = "isConceptRelation"; //$NON-NLS-1$
38
	private static final String EMPTY_NAMES = "hasEmptyNames"; //$NON-NLS-1$
39
	private static final String ACCEPTED_AND_NO_HOMOTYPIC_SYNONYMS = "isAcceptedAndHasNoHomotypicSynonyms"; //$NON-NLS-1$
40
	private static final String NOT_HOMOTYPIC_SYNONYM_OF_ACCEPTED = "isNotHomotypicSynonymOfAcceptedTaxon"; //$NON-NLS-1$
41
	private static final String SYNONYM_WITH_HOMOTYPIC_SYNONYMS = "isSynonymInHomotypicalGroupWithMoreSynonyms"; //$NON-NLS-1$
42
	private static final String IS_ORPHANED = "isOrphaned"; //$NON-NLS-1$
43

    
44
	/**
45
	 * <p>Constructor for NameEditorMenuPropertyTester.</p>
46
	 */
47
	public NameEditorMenuPropertyTester() {
48
	}
49

    
50
	/** {@inheritDoc} */
51
	@Override
52
    public boolean test(Object receiver, String property, Object[] args,
53
			Object expectedValue) {
54

    
55
		if(receiver instanceof IStructuredSelection){
56

    
57
			IStructuredSelection selection = (IStructuredSelection) receiver;
58

    
59
			Object selectedElement = selection.getFirstElement();
60
			if(selectedElement instanceof UuidAndTitleCache){
61
			    UuidAndTitleCache uuidAndTitleCache = (UuidAndTitleCache<?>)selectedElement;
62
			    CdmBase cdmBase = CdmStore.getCommonService().find(uuidAndTitleCache.getType(), uuidAndTitleCache.getUuid());
63
			    selectedElement = cdmBase;
64
			}
65

    
66
			if(ACCEPTED.equals(property)){
67
				return isAccepted(selectedElement);
68
			}
69
			else if(SYNONYM.equals(property)){
70
				return isSynonym(selectedElement);
71
			}
72
			else if(MISAPPLICATION.equals(property)){
73
				return isMisapplication(selectedElement);
74
			}
75
			else if(TAXONBASE.equals(property)){
76
				return isTaxonBase(selectedElement);
77
			}
78
			else if(CONCEPT.equals(property)){
79
				return isRelatedConcept(selectedElement);
80
			}
81
			else if(EMPTY_NAMES.equals(property)){
82
				return hasEmptyNames(receiver);
83
			}
84
			else if(ACCEPTED_AND_NO_HOMOTYPIC_SYNONYMS.equals(property)){
85
				return isAcceptedAndHasNoHomotypicSynonyms(selectedElement);
86
			}
87
			else if (NOT_HOMOTYPIC_SYNONYM_OF_ACCEPTED.equals(property)){
88
				return isNotHomotypicSynonymOfAcceptedTaxon(selectedElement);
89
			}
90
			else if (SYNONYM_WITH_HOMOTYPIC_SYNONYMS.equals(property)){
91
				return isSynonymInHomotypicalGroupWithMoreSynonyms(selectedElement);
92
			}
93
			else if (IS_ORPHANED.equals(property)){
94
			    return isOrphaned(selectedElement);
95
			}
96

    
97
		}
98

    
99
		return false;
100

    
101
	}
102

    
103
	public static boolean isAcceptedAndHasNoHomotypicSynonyms(Object selectedElement) {
104
		if (isAccepted(selectedElement)){
105
			Taxon taxon = (Taxon) selectedElement;
106
			return taxon.getSynonymsInGroup(taxon.getHomotypicGroup()).isEmpty();
107
		}
108
		return false;
109
	}
110

    
111
	public static boolean isSynonymInHomotypicalGroupWithMoreSynonyms(Object selectedElement) {
112
		if (isSynonym(selectedElement)){
113
			Synonym synonym = (Synonym) selectedElement;
114
			return synonym.getHomotypicGroup().getTypifiedNames().size()>1;
115
		}
116
		return false;
117
	}
118

    
119

    
120
	public static boolean isNotHomotypicSynonymOfAcceptedTaxon(Object selectedElement) {
121
		if (isSynonym(selectedElement)){
122
			Synonym synonym = (Synonym) selectedElement;
123
			Taxon taxon = synonym.getAcceptedTaxon();
124
			if (taxon != null &&
125
					taxon.getHomotypicGroup().equals(synonym.getHomotypicGroup())){
126
				return false;
127
			}
128
		}
129
		return true;
130
	}
131

    
132

    
133
	/**
134
	 * @param receiver
135
	 * @return
136
	 */
137
	public static boolean hasEmptyNames(Object receiver) {
138
		TaxonNameEditorE4 editor = (TaxonNameEditorE4) EventUtility.getTaxonEditor();
139
		return editor == null ? false : editor.checkForEmptyNames();
140
	}
141

    
142
	public static boolean isRelatedConcept(Object selectedElement) {
143
		if(selectedElement instanceof Taxon && ((Taxon) selectedElement).isRelatedConcept()){
144
			return true;
145
		}
146
		return false;
147
	}
148

    
149
	public static boolean isTaxonBase(Object selectedElement) {
150
		return (selectedElement instanceof TaxonBase) ? true : false;
151
	}
152

    
153
	public static boolean isMisapplication(Object selectedElement) {
154
		if(selectedElement instanceof Taxon && ((Taxon) selectedElement).isMisapplication()){
155
			return true;
156
		}
157
		return false;
158
	}
159

    
160
	public static boolean isSynonym(Object selectedElement) {
161
		return (selectedElement instanceof Synonym) ? true : false;
162
	}
163

    
164
	public static boolean isAccepted(Object selectedElement) {
165
		return (selectedElement instanceof Taxon  && ! ((Taxon) selectedElement).isMisapplication()) ? true : false;
166
	}
167

    
168
	public static boolean isOrphaned(Object selectedElement) {
169
	    if(selectedElement instanceof Taxon){
170
	        return ((Taxon) selectedElement).isOrphaned();
171
	    }
172
	    else if(selectedElement instanceof Synonym){
173
	        return ((Synonym) selectedElement).isOrphaned();
174
	    }
175
	    return false;
176
	}
177
}
    (1-1/1)