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.eclipse.jface.viewers.IStructuredSelection;
|
14
|
|
15
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
16
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
17
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
18
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
19
|
import eu.etaxonomy.taxeditor.editor.Page;
|
20
|
import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
|
21
|
|
22
|
/**
|
23
|
* <p>NameEditorMenuPropertyTester class.</p>
|
24
|
*
|
25
|
* @author n.hoffmann
|
26
|
* @created Jun 22, 2010
|
27
|
* @version 1.0
|
28
|
*/
|
29
|
public class NameEditorMenuPropertyTester extends org.eclipse.core.expressions.PropertyTester {
|
30
|
|
31
|
private static final String ACCEPTED = "isAcceptedTaxon";
|
32
|
private static final String SYNONYM = "isSynonym";
|
33
|
private static final String MISAPPLICATION = "isMisapplication";
|
34
|
private static final String TAXONBASE = "isTaxonBase";
|
35
|
private static final String CONCEPT = "isConceptRelation";
|
36
|
private static final String EMPTY_NAMES = "hasEmptyNames";
|
37
|
private static final String ACCEPTED_AND_NO_HOMOTYPIC_SYNONYMS = "isAcceptedAndHasNoHomotypicSynonyms";
|
38
|
|
39
|
/**
|
40
|
* <p>Constructor for NameEditorMenuPropertyTester.</p>
|
41
|
*/
|
42
|
public NameEditorMenuPropertyTester() {
|
43
|
}
|
44
|
|
45
|
/* (non-Javadoc)
|
46
|
* @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
|
47
|
*/
|
48
|
/** {@inheritDoc} */
|
49
|
@Override
|
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
|
else if(ACCEPTED_AND_NO_HOMOTYPIC_SYNONYMS.equals(property)){
|
78
|
return isAcceptedAndHasNoHomotypicSynonyms(selectedElement);
|
79
|
}
|
80
|
}
|
81
|
|
82
|
return false;
|
83
|
|
84
|
}
|
85
|
|
86
|
private boolean isAcceptedAndHasNoHomotypicSynonyms(Object selectedElement) {
|
87
|
if (isAccepted(selectedElement)){
|
88
|
Taxon taxon = (Taxon) selectedElement;
|
89
|
return taxon.getSynonymsInGroup(taxon.getHomotypicGroup()).isEmpty();
|
90
|
}
|
91
|
return false;
|
92
|
}
|
93
|
|
94
|
/**
|
95
|
* @param receiver
|
96
|
* @return
|
97
|
*/
|
98
|
private boolean hasEmptyNames(Object receiver) {
|
99
|
TaxonNameEditor editor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(Page.NAME);
|
100
|
return editor == null ? false : editor.checkForEmptyNames();
|
101
|
}
|
102
|
|
103
|
private boolean isRelatedConcept(Object selectedElement) {
|
104
|
if(selectedElement instanceof Taxon && ((Taxon) selectedElement).isRelatedConcept()){
|
105
|
return true;
|
106
|
}
|
107
|
return false;
|
108
|
}
|
109
|
|
110
|
private boolean isTaxonBase(Object selectedElement) {
|
111
|
return (selectedElement instanceof TaxonBase) ? true : false;
|
112
|
}
|
113
|
|
114
|
private boolean isMisapplication(Object selectedElement) {
|
115
|
if(selectedElement instanceof Taxon && ((Taxon) selectedElement).isMisapplication()){
|
116
|
return true;
|
117
|
}
|
118
|
return false;
|
119
|
}
|
120
|
|
121
|
private boolean isSynonym(Object selectedElement) {
|
122
|
return (selectedElement instanceof Synonym) ? true : false;
|
123
|
}
|
124
|
|
125
|
private boolean isAccepted(Object selectedElement) {
|
126
|
return (selectedElement instanceof Taxon && ! ((Taxon) selectedElement).isMisapplication()) ? true : false;
|
127
|
}
|
128
|
}
|