Project

General

Profile

Download (3.28 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;
11

    
12
import org.apache.log4j.Logger;
13
import org.eclipse.swt.graphics.Font;
14
import org.eclipse.swt.widgets.Composite;
15
import org.eclipse.ui.views.properties.IPropertySource;
16

    
17
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
18
import eu.etaxonomy.cdm.model.taxon.Taxon;
19
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
20
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
21
import eu.etaxonomy.taxeditor.propertysheet.name.ConceptPropertySource;
22

    
23
/**
24
 * @author p.ciardelli
25
 * @created 26.01.2009
26
 * @version 1.0
27
 */
28
public class ConceptComposite extends NameComposite {
29
	private static final Logger logger = Logger
30
			.getLogger(ConceptComposite.class);
31
	
32
	private Taxon relatedTaxon;
33
	private TaxonRelationshipType relationshipType;
34
	
35
	/**
36
	 * 
37
	 */
38
	private boolean acceptedTaxonIsFromTaxon;
39
		
40
	private ConceptComposite(TaxonNameEditor editor, Composite parent,
41
			Taxon relatedTaxon, TaxonRelationshipType relationshipType, 
42
			boolean acceptedTaxonIsFromTaxon) {
43
		super(editor, parent, NameComposite.CONCEPTRELATION, relatedTaxon);
44
		
45
		this.taxon = editor.getTaxon();
46
		this.relatedTaxon = relatedTaxon;
47
		this.relationshipType = relationshipType;
48
		this.acceptedTaxonIsFromTaxon = acceptedTaxonIsFromTaxon;
49
		
50
		setIsDraggable(true);
51
		setIcon(CONCEPT_ICON);
52
		setFont(getViewerFont());
53
		setIndent(CONCEPT_INDENT);
54
		
55
		showRelationshipType();
56
		showSec();
57
				
58
		initTextViewer(relatedTaxon);
59
	}
60
	
61
	private void showRelationshipType() {
62
		setNonEditableInfo(relationshipType.getLabel());
63
	}
64

    
65
	private void showSec() {
66
		if (relatedTaxon == null) {
67
			return;
68
		}
69
		
70
		if (relatedTaxon.getSec() == null) {
71
			setNonEditableInfo("sec. ???");
72
		} else {
73
			setNonEditableInfo("sec. " + relatedTaxon.getSec().getTitleCache());
74
		}
75
	}
76

    
77
	public static ConceptComposite getNewInstance(TaxonNameEditor editor, Composite parent, TaxonRelationship relationship){
78

    
79
		TaxonRelationshipType relationshipType = relationship.getType();
80
		
81
		if (relationship.getToTaxon().equals(editor.getTaxon())) {
82
			return new ConceptComposite (editor, parent, 
83
					relationship.getFromTaxon(), relationshipType, false);
84
		} else {
85
			return new ConceptComposite (editor, parent, 
86
					relationship.getToTaxon(), relationshipType, true);
87
		} 
88
	}
89

    
90
	/* (non-Javadoc)
91
	 * @see eu.etaxonomy.taxeditor.editor.GroupedComposite#getViewerFont()
92
	 */
93
	@Override
94
	protected Font getViewerFont() {
95
		return CONCEPT_FONT;
96
	}
97

    
98
	/* (non-Javadoc)
99
	 * @see eu.etaxonomy.taxeditor.editor.IHasPropertySource#getPropertySource()
100
	 */
101
	
102
	public IPropertySource getPropertySource() {
103
		return new ConceptPropertySource(relatedTaxon);
104
	}
105

    
106
	public Taxon getRelatedTaxon() {
107
		return relatedTaxon;
108
	}
109
	
110
	protected TaxonNameBase getName() {
111
		return relatedTaxon.getName();
112
	}
113
	
114
	protected void calculateErrors() {
115
		super.calculateErrors();
116
		
117
		textViewer.setShowSecError(relatedTaxon);
118
	}
119
	
120
	public Object getData () {
121
		return getRelatedTaxon();
122
	}
123
}
124

    
125

    
126

    
127

    
128

    
129

    
(4-4/18)