Project

General

Profile

Download (3.98 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.ui.section.name;
11

    
12
import org.eclipse.swt.events.SelectionListener;
13
import org.eclipse.swt.graphics.Color;
14

    
15
import eu.etaxonomy.cdm.model.name.NameRelationship;
16
import eu.etaxonomy.cdm.model.name.NameRelationshipType;
17
import eu.etaxonomy.taxeditor.model.MessagingUtils;
18
import eu.etaxonomy.taxeditor.preference.NameDetailsConfigurator;
19
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
20
import eu.etaxonomy.taxeditor.ui.combo.term.TermComboElement;
21
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
22
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
23
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
24
import eu.etaxonomy.taxeditor.ui.element.LabelElement;
25
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
26
import eu.etaxonomy.taxeditor.ui.section.supplemental.AbstractSourcedEntityElement;
27
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
28

    
29
/**
30
 * <p>NameRelationshipDetailElement class.</p>
31
 *
32
 * @author n.hoffmann
33
 * @created Mar 18, 2010
34
 */
35
public class NameRelationshipDetailElement extends AbstractSourcedEntityElement<NameRelationship>{
36

    
37
	private RuleConsideredElement ruleConsidered;
38
	private EntitySelectionElement<?> selection_toName;
39
	private TermComboElement<NameRelationshipType> combo_relationshipType;
40
	private LabelElement labelElement;
41

    
42
//	private OriginalSourceElement sourceElement;
43

    
44
	/**
45
	 * <p>Constructor for NameRelationshipDetailElement.</p>
46
	 *
47
	 * @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
48
	 * @param formElement a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection} object.
49
	 * @param entity a {@link eu.etaxonomy.cdm.model.name.NameRelationship} object.
50
	 * @param removeListener a {@link org.eclipse.swt.events.SelectionListener} object.
51
	 * @param style a int.
52
	 */
53
	public NameRelationshipDetailElement(CdmFormFactory cdmFormFactory,
54
	        AbstractFormSection formElement,
55
            NameRelationship entity, SelectionListener removeListener, int style){
56
	    super(cdmFormFactory, formElement, entity, removeListener, "Source", style);
57
	    setSourceLabel("Source");
58
	}
59

    
60
	@Override
61
	public void createControls(ICdmFormElement element, int style) {
62

    
63
	    NameDetailsConfigurator config = PreferencesUtil.getPreferredNameDetailsConfiguration();
64
		labelElement = formFactory.createLabel(element, null);
65

    
66
		if (config == null || config.isNameRelationsRuleConsideredActivated()){
67
		    ruleConsidered = formFactory.createRuleConsideredElement(
68
		            element, "Rule Considered", config == null
69
		            || config.isNameRelationsRuleConsideredCodeEditionActivated(), style);
70
		}
71
		LabelElement spacer = formFactory.createLabel(element, null);
72
		spacer.getLayoutComposite().setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
73
		addElement(spacer);
74
		super.createControls(element, style);
75
	}
76

    
77
	@Override
78
	public void setEntity(NameRelationship entity) {
79
		String text = (entity.getFromName() == null? "-":entity.getFromName().getTitleCache())
80
		        + " is " + (entity.getType()==null?"(no type)":entity.getType().getLabel())
81
		        + " " + (entity.getToName()==null?"-":entity.getToName().getTitleCache());
82
		labelElement.setText(text);
83
		if (ruleConsidered != null){
84
		    ruleConsidered.setElement(entity);
85
		}
86

    
87
		super.setEntity(entity);
88
	}
89

    
90
	@Override
91
	public void handleEvent(Object eventSource) {
92
	    if(eventSource == combo_relationshipType){
93
			getEntity().setType(combo_relationshipType.getSelection());
94
		}
95
		else if(eventSource == selection_toName){
96
			MessagingUtils.error(getClass(), "No API call available.", null);
97
		}
98

    
99

    
100
	}
101

    
102
	@Override
103
	public void setBackground(Color color) {
104
		if(labelElement != null) {
105
            labelElement.setBackground(color);
106
        }
107
		super.setBackground(color);
108
	}
109

    
110

    
111
}
(8-8/21)