Project

General

Profile

Download (1.51 KB) Statistics
| Branch: | Tag: | Revision:
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.Collection;
11

    
12
import org.eclipse.core.expressions.PropertyTester;
13

    
14
import eu.etaxonomy.cdm.model.taxon.Taxon;
15
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
16
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
17
public class TaxonNodePropertyTester extends PropertyTester {
18

    
19
	private static final Object HAS_SYNONYMS = "hasSynonyms"; //$NON-NLS-1$
20
	private static final Object HAS_TAXA = "hasTaxa"; //$NON-NLS-1$
21
	private static final Object IS_CLASSIFICATION = "isClassification"; //$NON-NLS-1$
22

    
23
	/** {@inheritDoc} */
24
	@Override
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 TaxonNodeDto && IS_CLASSIFICATION.equals(property)) {
48
			TaxonNodeDto node = (TaxonNodeDto) receiver;
49
			return node.getTaxonUuid() == null;
50
		}
51

    
52
		return false;
53
	}
54
}
(6-6/6)