Project

General

Profile

Download (7.98 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 NOT_SYNONYM = "isNotSynonym"; //$NON-NLS-1$
37
	private static final String MISAPPLICATION = "isMisapplication"; //$NON-NLS-1$
38
	private static final String NOT_MISAPPLICATION = "isNotMisapplication"; //$NON-NLS-1$
39
	private static final String PROPARTE_SYNONYM = "isProparteSynonym";//$NON-NLS-1$
40
	private static final String NOT_PROPARTE_SYNONYM = "isNotProparteSynonym"; //$NON-NLS-1$
41
	private static final String TAXONBASE = "isTaxonBase"; //$NON-NLS-1$
42
	private static final String CONCEPT = "isConceptRelation"; //$NON-NLS-1$
43
	private static final String EMPTY_NAMES = "hasEmptyNames"; //$NON-NLS-1$
44
	private static final String ACCEPTED_AND_NO_HOMOTYPIC_SYNONYMS = "isAcceptedAndHasNoHomotypicSynonyms"; //$NON-NLS-1$
45
	private static final String NOT_HOMOTYPIC_SYNONYM_OF_ACCEPTED = "isNotHomotypicSynonymOfAcceptedTaxon"; //$NON-NLS-1$
46
	private static final String SYNONYM_WITH_HOMOTYPIC_SYNONYMS = "isSynonymInHomotypicalGroupWithMoreSynonyms"; //$NON-NLS-1$
47
	private static final String IS_ORPHANED = "isOrphaned";
48
	private static final String IS_NOT_INVALID_DESIGNATION = "isNotInvalidDesignation";//$NON-NLS-1$
49

    
50
	/**
51
	 * <p>Constructor for NameEditorMenuPropertyTester.</p>
52
	 */
53
	public NameEditorMenuPropertyTester() {
54
	}
55

    
56
	/** {@inheritDoc} */
57
	@Override
58
    public boolean test(Object receiver, String property, Object[] args,
59
			Object expectedValue) {
60

    
61
		if(receiver instanceof IStructuredSelection){
62

    
63
			IStructuredSelection selection = (IStructuredSelection) receiver;
64

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

    
117
		}
118

    
119
		return false;
120

    
121
	}
122

    
123
	public static boolean isAcceptedAndHasNoHomotypicSynonyms(Object selectedElement) {
124
		if (isAccepted(selectedElement)){
125
			Taxon taxon = (Taxon) selectedElement;
126
			return taxon.getSynonymsInGroup(taxon.getHomotypicGroup()).isEmpty();
127
		}
128
		return false;
129
	}
130
	public static boolean isNotAcceptedTaxon(Object selectedElement) {
131

    
132
        return !isAccepted(selectedElement);
133
    }
134

    
135
	public static boolean isNotMisapplication(Object selectedElement) {
136

    
137
        return !isMisapplication(selectedElement);
138
    }
139

    
140
	public static boolean isSynonymInHomotypicalGroupWithMoreSynonyms(Object selectedElement) {
141
		if (isSynonym(selectedElement)){
142
			Synonym synonym = (Synonym) selectedElement;
143
			return synonym.getHomotypicGroup().getTypifiedNames().size()>1;
144
		}
145
		return false;
146
	}
147

    
148

    
149
	public static boolean isNotHomotypicSynonymOfAcceptedTaxon(Object selectedElement) {
150
		if (isSynonym(selectedElement)){
151
			Synonym synonym = (Synonym) selectedElement;
152
			Taxon taxon = synonym.getAcceptedTaxon();
153
			if (taxon != null &&
154
					taxon.getHomotypicGroup().equals(synonym.getHomotypicGroup())){
155
				return false;
156
			}
157
		}
158
		return true;
159
	}
160

    
161

    
162
	/**
163
	 * @param receiver
164
	 * @return
165
	 */
166
	public static boolean hasEmptyNames(Object receiver) {
167
		TaxonNameEditorE4 editor = (TaxonNameEditorE4) EventUtility.getTaxonEditor();
168
		return editor == null ? false : editor.checkForEmptyNames();
169
	}
170

    
171
	public static boolean isRelatedConcept(Object selectedElement) {
172
		if(selectedElement instanceof Taxon && ((Taxon) selectedElement).isRelatedConcept()){
173
			return true;
174
		}
175
		return false;
176
	}
177

    
178
	public static boolean isTaxonBase(Object selectedElement) {
179
		return (selectedElement instanceof TaxonBase) ? true : false;
180
	}
181

    
182
	public static boolean isMisapplication(Object selectedElement) {
183
		if(selectedElement instanceof Taxon && ((Taxon) selectedElement).isMisapplication() ){
184
			return true;
185
		}
186
		return false;
187
	}
188

    
189
	public static boolean isProparteSynonym(Object selectedElement) {
190
        if(selectedElement instanceof Taxon && ((Taxon) selectedElement).isProparteSynonym()){
191
            return true;
192
        }
193
        return false;
194
    }
195
	public static boolean isNotProparteSynonym(Object selectedElement) {
196
	    if (selectedElement instanceof Synonym){
197
	        return true;
198
	    }
199
        if(((Taxon) selectedElement).isProparteSynonym() ){
200
            return false;
201
        }
202
        return true;
203
    }
204

    
205
	public static boolean isSynonym(Object selectedElement) {
206
		return (selectedElement instanceof Synonym) ? true : false;
207
	}
208
	public static boolean isNotSynonym(Object selectedElement) {
209
        return !isSynonym(selectedElement);
210
    }
211

    
212
	public static boolean isAccepted(Object selectedElement) {
213
		return (selectedElement instanceof Taxon  && ! ((Taxon) selectedElement).isMisapplication() && ! ((Taxon) selectedElement).isProparteSynonym()) ? true : false;
214
	}
215

    
216
	public static boolean isOrphaned(Object selectedElement) {
217
	    if(selectedElement instanceof Taxon){
218
	        return ((Taxon) selectedElement).isOrphaned();
219
	    }
220
	    else if(selectedElement instanceof Synonym){
221
	        return ((Synonym) selectedElement).isOrphaned();
222
	    }
223
	    return false;
224
	}
225

    
226
    /**
227
     * @param selectedElement
228
     * @return
229
     */
230
    public static boolean isProParteSynonym(Object selectedElement) {
231
        if(selectedElement instanceof Taxon && ((Taxon) selectedElement).isProparteSynonym()){
232
            return true;
233
        }
234
        return false;
235
    }
236
}
    (1-1/1)