Project

General

Profile

Download (4.66 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.description;
11

    
12
import org.eclipse.swt.SWT;
13
import org.eclipse.swt.events.SelectionListener;
14

    
15
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
16
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
17
import eu.etaxonomy.cdm.model.name.TaxonName;
18
import eu.etaxonomy.cdm.model.reference.Reference;
19
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
20
import eu.etaxonomy.taxeditor.store.StoreUtil;
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.IEnableableFormElement;
25
import eu.etaxonomy.taxeditor.ui.element.IEntityElement;
26
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
27
import eu.etaxonomy.taxeditor.ui.section.common.ExternalLinksSection;
28
import eu.etaxonomy.taxeditor.ui.section.supplemental.AbstractOriginalSourceElement;
29
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
30

    
31
/**
32
 *
33
 * @author n.hoffmann
34
 * @created Nov 16, 2009
35
 * @version 1.0
36
 */
37
public class DescriptionElementSourceElement extends
38
		AbstractOriginalSourceElement<DescriptionElementSource> implements
39
		IEntityElement<DescriptionElementSource>{//, IEnableableFormElement {
40
    private EntitySelectionElement<Reference> selection_descriptionElementSource;
41
	private EntitySelectionElement<TaxonName> selection_name;
42
	boolean isEnabled = true;
43

    
44
	public DescriptionElementSourceElement(CdmFormFactory cdmFormFactory,
45
			AbstractFormSection<?> formElement, DescriptionElementSource element,
46
			SelectionListener removeListener, int style, boolean isCommonNameReference) {
47
		super(cdmFormFactory, formElement, element, removeListener, style, isCommonNameReference);
48
		cdmFormFactory.createSelectionArbitrator(this);
49
	}
50

    
51
	/** {@inheritDoc} */
52
	@Override
53
	public void createControls(ICdmFormElement formElement, int style) {
54
		super.createControls(formElement, style);
55
		selection_name = formFactory
56
				.createSelectionElement(TaxonName.class,//getConversationHolder(),
57
				        formElement, "Name in Source",
58
						null, EntitySelectionElement.ALL, SWT.NULL);
59

    
60
		externalLinks = formFactory.createExternalLinksSection(getConversationHolder(), formElement, StoreUtil.getSectionStyle(ExternalLinksSection.class, DescriptionElementSource.class.getCanonicalName()));
61
        externalLinks.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
62
        if (getEntity() != null){
63
        	setEntity(entity);
64
        }
65
   
66
	}
67

    
68

    
69
	/** {@inheritDoc} */
70
	@Override
71
	public void setEntity(DescriptionElementSource entity) {
72
		super.setEntity(entity);
73
		if (selection_reference != null){
74
			if (PreferencesUtil.getBooleanValue(PreferencePredicate.ShowIdInSource.getKey())){
75
			    text_idInSource.setText(entity.getIdInSource());
76
			}
77
			if (PreferencesUtil.getBooleanValue(PreferencePredicate.ShowNamespaceInSource.getKey())){
78
			    text_idNamespace.setText(entity.getIdNamespace());
79
			}
80
	
81
			selection_reference.setEntity(entity.getCitation());
82
			text_referenceDetail.setText(entity.getCitationMicroReference());
83
			text_originaleNameString.setText(entity.getOriginalNameString());
84
			selection_name.setEntity(entity.getNameUsedInSource());
85
			combo_origsourcetype.setSelection(entity.getType());
86
			externalLinks.setEntity(entity);
87
		}
88
		
89
	}
90

    
91
	/** {@inheritDoc} */
92
	@Override
93
	public void setSelected(boolean selected) {
94

    
95
	}
96

    
97
	/** {@inheritDoc} */
98
	@Override
99
	public void handleEvent(Object eventSource) {
100
		if (eventSource == text_idInSource) {
101
			getEntity().setIdInSource(text_idInSource.getText());
102
		} else if (eventSource == text_idNamespace) {
103
			getEntity().setIdNamespace(text_idNamespace.getText());
104
		} else if (eventSource == selection_reference) {
105
		    getEntity().setCitation(selection_reference.getSelection());
106
		} else if (eventSource == text_referenceDetail) {
107
			getEntity().setCitationMicroReference(
108
					text_referenceDetail.getText());
109
		} else if (eventSource == text_originaleNameString) {
110
			getEntity().setOriginalNameString(
111
					text_originaleNameString.getText());
112
		} else if (eventSource == selection_name) {
113
			getEntity().setNameUsedInSource(selection_name.getSelection());
114
		}
115
		else if(eventSource == combo_origsourcetype){
116
		    getEntity().setType(combo_origsourcetype.getSelection());
117
		}
118

    
119
	}
120
	
121
	@Override
122
	public void setEnabled(boolean enabled) {
123
		super.setEnabled(enabled);
124
		externalLinks.setEnabled(isEnabled);
125
		
126
	}
127

    
128
	
129

    
130
}
(9-9/26)