1
|
|
2
|
/**
|
3
|
* <p>TaxonNodePropertyTester class.</p>
|
4
|
*
|
5
|
* @author n.hoffmann
|
6
|
*/
|
7
|
package eu.etaxonomy.taxeditor.navigation.navigator;
|
8
|
|
9
|
import java.util.Collection;
|
10
|
|
11
|
import org.eclipse.core.expressions.PropertyTester;
|
12
|
|
13
|
import eu.etaxonomy.cdm.api.service.IClassificationService;
|
14
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
15
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
16
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
17
|
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
|
18
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
19
|
public class TaxonNodePropertyTester extends PropertyTester {
|
20
|
|
21
|
private static final Object HAS_SYNONYMS = "hasSynonyms"; //$NON-NLS-1$
|
22
|
private static final Object HAS_TAXA = "hasTaxa"; //$NON-NLS-1$
|
23
|
private static final Object IS_CLASSIFICATION = "isClassification"; //$NON-NLS-1$
|
24
|
private static final Object IS_NOT_CLASSIFICATION = "isNotClassification"; //$NON-NLS-1$
|
25
|
private static final Object IS_UNPLACED = "isUnplaced"; //$NON-NLS-1$
|
26
|
private static final Object IS_EXCLUDED = "isExcluded"; //$NON-NLS-1$
|
27
|
private static final Object NO_CLASSIFICATION_EXIST = "noClassificationExist";
|
28
|
|
29
|
@Override
|
30
|
public boolean test(Object receiver, String property, Object[] args,
|
31
|
Object expectedValue) {
|
32
|
if (receiver instanceof Collection){
|
33
|
if (((Collection<?>)receiver).iterator().hasNext()){
|
34
|
receiver = ((Collection<?>)receiver).iterator().next();
|
35
|
}
|
36
|
}
|
37
|
if (receiver instanceof TaxonNode && HAS_SYNONYMS.equals(property)) {
|
38
|
Taxon taxon = ((TaxonNode) receiver).getTaxon();
|
39
|
if(taxon != null){
|
40
|
return taxon.hasSynonyms();
|
41
|
}
|
42
|
}
|
43
|
|
44
|
if (receiver instanceof TaxonNode && HAS_TAXA.equals(property)) {
|
45
|
TaxonNode node = (TaxonNode) receiver;
|
46
|
if (!node.hasTaxon()){
|
47
|
return node.getChildNodes().size() > 0;
|
48
|
}else{
|
49
|
return false;
|
50
|
}
|
51
|
}
|
52
|
if (receiver instanceof TaxonNodeDto && IS_CLASSIFICATION.equals(property)) {
|
53
|
TaxonNodeDto node = (TaxonNodeDto) receiver;
|
54
|
return node.getTaxonUuid() == null;
|
55
|
}
|
56
|
if (receiver instanceof TaxonNodeDto && IS_NOT_CLASSIFICATION.equals(property)) {
|
57
|
TaxonNodeDto node = (TaxonNodeDto) receiver;
|
58
|
return node.getTaxonUuid() != null;
|
59
|
}
|
60
|
if (receiver instanceof TaxonNodeDto && IS_UNPLACED.equals(property)) {
|
61
|
TaxonNodeDto node = (TaxonNodeDto) receiver;
|
62
|
return node.isUnplaced() && node.getTaxonUuid() != null;
|
63
|
}
|
64
|
if (receiver instanceof TaxonNodeDto && IS_EXCLUDED.equals(property)) {
|
65
|
TaxonNodeDto node = (TaxonNodeDto) receiver;
|
66
|
return node.isExcluded() && node.getTaxonUuid() != null;
|
67
|
}
|
68
|
if (NO_CLASSIFICATION_EXIST.equals(property)) {
|
69
|
return 0 == CdmStore.getService(IClassificationService.class).count(Classification.class);
|
70
|
}
|
71
|
|
72
|
return false;
|
73
|
}
|
74
|
|
75
|
public static boolean noClassifiactionExists(){
|
76
|
int count = CdmStore.getService(IClassificationService.class).count(Classification.class);
|
77
|
return 0 == count;
|
78
|
}
|
79
|
}
|