Project

General

Profile

Download (6.38 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 NOT_ACCEPTED = "isNotAcceptedTaxon"; //$NON-NLS-1$
35
	private static final String SYNONYM = "isSynonym"; //$NON-NLS-1$
36
	private static final String MISAPPLICATION = "isMisapplication"; //$NON-NLS-1$
37
	private static final String NOT_MISAPPLICATION = "isNotMisapplication"; //$NON-NLS-1$
38
	private static final String TAXONBASE = "isTaxonBase"; //$NON-NLS-1$
39
	private static final String CONCEPT = "isConceptRelation"; //$NON-NLS-1$
40
	private static final String EMPTY_NAMES = "hasEmptyNames"; //$NON-NLS-1$
41
	private static final String ACCEPTED_AND_NO_HOMOTYPIC_SYNONYMS = "isAcceptedAndHasNoHomotypicSynonyms"; //$NON-NLS-1$
42
	private static final String NOT_HOMOTYPIC_SYNONYM_OF_ACCEPTED = "isNotHomotypicSynonymOfAcceptedTaxon"; //$NON-NLS-1$
43
	private static final String SYNONYM_WITH_HOMOTYPIC_SYNONYMS = "isSynonymInHomotypicalGroupWithMoreSynonyms"; //$NON-NLS-1$
44
	private static final String IS_ORPHANED = "isOrphaned"; //$NON-NLS-1$
45

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

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

    
57
		if(receiver instanceof IStructuredSelection){
58

    
59
			IStructuredSelection selection = (IStructuredSelection) receiver;
60

    
61
			Object selectedElement = selection.getFirstElement();
62
			if(selectedElement instanceof UuidAndTitleCache){
63
			    UuidAndTitleCache uuidAndTitleCache = (UuidAndTitleCache<?>)selectedElement;
64
			    CdmBase cdmBase = CdmStore.getCommonService().find(uuidAndTitleCache.getType(), uuidAndTitleCache.getUuid());
65
			    selectedElement = cdmBase;
66
			}
67
			if(NOT_ACCEPTED.equals(property)){
68
                return !isAccepted(selectedElement);
69
            }
70
			if(ACCEPTED.equals(property)){
71
				return isAccepted(selectedElement);
72
			}
73
			else if(SYNONYM.equals(property)){
74
				return isSynonym(selectedElement);
75
			}
76
			else if(MISAPPLICATION.equals(property)){
77
				return isMisapplication(selectedElement);
78
			}
79
			else if(NOT_MISAPPLICATION.equals(property)){
80
                return isNotMisapplication(selectedElement);
81
            }
82
			else if(TAXONBASE.equals(property)){
83
				return isTaxonBase(selectedElement);
84
			}
85
			else if(CONCEPT.equals(property)){
86
				return isRelatedConcept(selectedElement);
87
			}
88
			else if(EMPTY_NAMES.equals(property)){
89
				return hasEmptyNames(receiver);
90
			}
91
			else if(ACCEPTED_AND_NO_HOMOTYPIC_SYNONYMS.equals(property)){
92
				return isAcceptedAndHasNoHomotypicSynonyms(selectedElement);
93
			}
94
			else if (NOT_HOMOTYPIC_SYNONYM_OF_ACCEPTED.equals(property)){
95
				return isNotHomotypicSynonymOfAcceptedTaxon(selectedElement);
96
			}
97
			else if (SYNONYM_WITH_HOMOTYPIC_SYNONYMS.equals(property)){
98
				return isSynonymInHomotypicalGroupWithMoreSynonyms(selectedElement);
99
			}
100
			else if (IS_ORPHANED.equals(property)){
101
			    return isOrphaned(selectedElement);
102
			}
103

    
104
		}
105

    
106
		return false;
107

    
108
	}
109

    
110
	public static boolean isAcceptedAndHasNoHomotypicSynonyms(Object selectedElement) {
111
		if (isAccepted(selectedElement)){
112
			Taxon taxon = (Taxon) selectedElement;
113
			return taxon.getSynonymsInGroup(taxon.getHomotypicGroup()).isEmpty();
114
		}
115
		return false;
116
	}
117
	public static boolean isNotAcceptedTaxon(Object selectedElement) {
118

    
119
        return !isAccepted(selectedElement);
120
    }
121

    
122
	public static boolean isNotMisapplication(Object selectedElement) {
123

    
124
        return !isMisapplication(selectedElement);
125
    }
126

    
127
	public static boolean isSynonymInHomotypicalGroupWithMoreSynonyms(Object selectedElement) {
128
		if (isSynonym(selectedElement)){
129
			Synonym synonym = (Synonym) selectedElement;
130
			return synonym.getHomotypicGroup().getTypifiedNames().size()>1;
131
		}
132
		return false;
133
	}
134

    
135

    
136
	public static boolean isNotHomotypicSynonymOfAcceptedTaxon(Object selectedElement) {
137
		if (isSynonym(selectedElement)){
138
			Synonym synonym = (Synonym) selectedElement;
139
			Taxon taxon = synonym.getAcceptedTaxon();
140
			if (taxon != null &&
141
					taxon.getHomotypicGroup().equals(synonym.getHomotypicGroup())){
142
				return false;
143
			}
144
		}
145
		return true;
146
	}
147

    
148

    
149
	/**
150
	 * @param receiver
151
	 * @return
152
	 */
153
	public static boolean hasEmptyNames(Object receiver) {
154
		TaxonNameEditorE4 editor = (TaxonNameEditorE4) EventUtility.getTaxonEditor();
155
		return editor == null ? false : editor.checkForEmptyNames();
156
	}
157

    
158
	public static boolean isRelatedConcept(Object selectedElement) {
159
		if(selectedElement instanceof Taxon && ((Taxon) selectedElement).isRelatedConcept()){
160
			return true;
161
		}
162
		return false;
163
	}
164

    
165
	public static boolean isTaxonBase(Object selectedElement) {
166
		return (selectedElement instanceof TaxonBase) ? true : false;
167
	}
168

    
169
	public static boolean isMisapplication(Object selectedElement) {
170
		if(selectedElement instanceof Taxon && ((Taxon) selectedElement).isMisapplication()){
171
			return true;
172
		}
173
		return false;
174
	}
175

    
176
	public static boolean isSynonym(Object selectedElement) {
177
		return (selectedElement instanceof Synonym) ? true : false;
178
	}
179

    
180
	public static boolean isAccepted(Object selectedElement) {
181
		return (selectedElement instanceof Taxon  && ! ((Taxon) selectedElement).isMisapplication()) ? true : false;
182
	}
183

    
184
	public static boolean isOrphaned(Object selectedElement) {
185
	    if(selectedElement instanceof Taxon){
186
	        return ((Taxon) selectedElement).isOrphaned();
187
	    }
188
	    else if(selectedElement instanceof Synonym){
189
	        return ((Synonym) selectedElement).isOrphaned();
190
	    }
191
	    return false;
192
	}
193
}
    (1-1/1)