Project

General

Profile

Download (4.69 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
package eu.etaxonomy.taxeditor.ui.section.description;
10

    
11
import java.util.Iterator;
12

    
13
import org.eclipse.swt.SWT;
14
import org.eclipse.swt.events.SelectionListener;
15
import org.eclipse.swt.widgets.Control;
16

    
17
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
18
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
19
import eu.etaxonomy.cdm.model.name.TaxonName;
20
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
21
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
22
import eu.etaxonomy.taxeditor.store.StoreUtil;
23
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
24
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
25
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
26
import eu.etaxonomy.taxeditor.ui.element.IEntityElement;
27
import eu.etaxonomy.taxeditor.ui.element.ISelectableElement;
28
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
29
import eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator;
30
import eu.etaxonomy.taxeditor.ui.section.common.ExternalLinksSection;
31
import eu.etaxonomy.taxeditor.ui.section.reference.OriginalSourceElement;
32
import eu.etaxonomy.taxeditor.ui.section.supplemental.AbstractOriginalSourceElement;
33
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
34

    
35
/**
36
 * @author n.hoffmann
37
 * @created Nov 16, 2009
38
 */
39
public class DescriptionElementSourceElement extends
40
		AbstractOriginalSourceElement<DescriptionElementSource> implements
41
		IEntityElement<DescriptionElementSource>{
42

    
43
	private EntitySelectionElement<TaxonName> selection_name;
44
	boolean isEnabled = true;
45

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

    
53
	@Override
54
	public void createControls(ICdmFormElement formElement, int style) {
55
		super.createControls(formElement, style);
56
		selection_name = formFactory
57
				.createSelectionElement(TaxonName.class,
58
				        formElement, "Name in Source",
59
						null, EntitySelectionElement.ALL, SWT.NULL);
60
		
61
		externalLinks = formFactory.createExternalLinksSection(formElement, StoreUtil.getSectionStyle(ExternalLinksSection.class, DescriptionElementSource.class.getCanonicalName()));
62
        externalLinks.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
63
        if (getEntity() != null){
64
        	setEntity(entity);
65
        }
66
	}
67

    
68
	@Override
69
	public void setEntity(DescriptionElementSource entity) {
70
		super.setEntity(entity);
71
		if (selection_reference != null ){
72
			if (PreferencesUtil.getBooleanValue(PreferencePredicate.ShowIdInSource.getKey())){
73
			    text_idInSource.setText(entity.getIdInSource());
74
			}
75
			if (PreferencesUtil.getBooleanValue(PreferencePredicate.ShowNamespaceInSource.getKey())){
76
			    text_idNamespace.setText(entity.getIdNamespace());
77
			}
78

    
79
			selection_reference.setEntity(entity.getCitation());
80
			text_referenceDetail.setText(entity.getCitationMicroReference());
81
			text_originalInfo.setText(entity.getOriginalInfo());
82
			selection_name.setEntity(entity.getNameUsedInSource());
83
			
84
			combo_origsourcetype.setSelection(entity.getType());
85
			externalLinks.setEntity(entity);
86
		}
87
		if (selection_specimen != null) {
88
			selection_specimen.setEnabled(selection_reference.getEntity()== null);
89
			selection_reference.setEnabled(selection_specimen.getEntity()== null);
90
		}
91
	}
92

    
93
	@Override
94
	public void setSelected(boolean selected) {}
95

    
96
	@Override
97
	public void handleEvent(Object eventSource) {
98
	    super.handleEvent(eventSource);
99
        if (eventSource == selection_name) {
100
            getEntity().setNameUsedInSource(selection_name.getSelection());
101
           
102
        }
103
        if (eventSource == selection_specimen) {
104
            getEntity().setSpecimen(selection_specimen.getSelection());
105
            this.selection_reference.setEnabled(selection_specimen.getSelection() == null);
106
        }
107
        if (eventSource == selection_reference) {
108

    
109
            this.selection_specimen.setEnabled(selection_reference.getSelection() == null);
110
        }
111
	}
112

    
113
	@Override
114
	public void setEnabled(boolean enabled) {
115
		super.setEnabled(enabled);
116
		externalLinks.setEnabled(isEnabled);
117
		if (selection_specimen != null) {
118
			selection_specimen.setEnabled(selection_reference.getEntity()== null);
119
			selection_reference.setEnabled(selection_specimen.getEntity()== null);
120
		}
121
	}
122
	 
123
}
(9-9/26)