1
|
|
2
|
/**
|
3
|
* <p>TaxonNodePropertyTester class.</p>
|
4
|
*
|
5
|
* @author n.hoffmann
|
6
|
* @version $Id: $
|
7
|
*/
|
8
|
package eu.etaxonomy.taxeditor.navigation.navigator;
|
9
|
|
10
|
import java.util.ArrayList;
|
11
|
import java.util.Collection;
|
12
|
|
13
|
import org.eclipse.core.expressions.PropertyTester;
|
14
|
|
15
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
16
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
17
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
18
|
public class TaxonNodePropertyTester extends PropertyTester {
|
19
|
|
20
|
private static final Object HAS_SYNONYMS = "hasSynonyms"; //$NON-NLS-1$
|
21
|
private static final Object HAS_TAXA = "hasTaxa"; //$NON-NLS-1$
|
22
|
private static final Object IS_CLASSIFICATION = "isClassification"; //$NON-NLS-1$
|
23
|
|
24
|
/** {@inheritDoc} */
|
25
|
public boolean test(Object receiver, String property, Object[] args,
|
26
|
Object expectedValue) {
|
27
|
if (receiver instanceof Collection){
|
28
|
if (((Collection)receiver).iterator().hasNext()){
|
29
|
receiver = ((Collection)receiver).iterator().next();
|
30
|
}
|
31
|
}
|
32
|
if (receiver instanceof TaxonNode && HAS_SYNONYMS.equals(property)) {
|
33
|
Taxon taxon = ((TaxonNode) receiver).getTaxon();
|
34
|
if(taxon != null){
|
35
|
return taxon.hasSynonyms();
|
36
|
}
|
37
|
}
|
38
|
|
39
|
if (receiver instanceof TaxonNode && HAS_TAXA.equals(property)) {
|
40
|
TaxonNode node = (TaxonNode) receiver;
|
41
|
if (!node.hasTaxon()){
|
42
|
return node.getChildNodes().size() > 0;
|
43
|
}else{
|
44
|
return false;
|
45
|
}
|
46
|
}
|
47
|
if (receiver instanceof TaxonNode && IS_CLASSIFICATION.equals(property)) {
|
48
|
TaxonNode node = (TaxonNode) receiver;
|
49
|
return !node.hasTaxon();
|
50
|
}
|
51
|
|
52
|
return false;
|
53
|
}
|
54
|
}
|