Project

General

Profile

Download (8.62 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * Copyright (C) 2013 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.occurrence;
10

    
11
import java.util.Collection;
12
import java.util.HashSet;
13
import java.util.Set;
14

    
15
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
16
import eu.etaxonomy.cdm.model.agent.AgentBase;
17
import eu.etaxonomy.cdm.model.agent.Person;
18
import eu.etaxonomy.cdm.model.agent.Team;
19
import eu.etaxonomy.cdm.model.common.CdmBase;
20
import eu.etaxonomy.cdm.model.common.LanguageString;
21
import eu.etaxonomy.cdm.model.location.NamedArea;
22
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
23
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
24
import eu.etaxonomy.taxeditor.store.CdmStore;
25
import eu.etaxonomy.taxeditor.store.StoreUtil;
26
import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
27
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
28
import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
29
import eu.etaxonomy.taxeditor.ui.element.GatheringEventUnitElement;
30
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
31
import eu.etaxonomy.taxeditor.ui.element.LanguageStringWithLabelElement;
32
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
33
import eu.etaxonomy.taxeditor.ui.element.MinMaxTextSection;
34
import eu.etaxonomy.taxeditor.ui.element.NumberWithLabelElement;
35
import eu.etaxonomy.taxeditor.ui.element.PointElement;
36
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
37
import eu.etaxonomy.taxeditor.ui.element.TimePeriodElement;
38
import eu.etaxonomy.taxeditor.ui.element.ToggleableTextElement;
39
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
40
import eu.etaxonomy.taxeditor.ui.selection.CollectorSelectionElement;
41
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
42

    
43
/**
44
 * @author pplitzner
45
 * @date 05.11.2013
46
 */
47
public class FieldUnitFacadeGeneralDetailElement extends AbstractCdmDetailElement<DerivedUnitFacade> {
48

    
49
    private ToggleableTextElement toggleableText_titleCache;
50
    private EnumComboElement<SpecimenOrObservationType> combo_specorobstype;
51
    private EntitySelectionElement<NamedArea> selection_country;
52
    private CollectingAreasDetailSection section_collectingAreas;
53
    private LanguageStringWithLabelElement languageText_locality;
54
    private PointElement element_point;
55
    private NumberWithLabelElement number_elevation;
56
    private TimePeriodElement element_date;
57
    private CollectorSelectionElement selection_collector;
58
    private CollectorSelectionElement selection_primary_collector;
59
    private TextWithLabelElement text_collectingNumber;
60
    private GatheringEventUnitElement element_elevation;
61
    private CheckboxElement checkIsPublish;
62

    
63
    public FieldUnitFacadeGeneralDetailElement(CdmFormFactory formFactory, ICdmFormElement formElement) {
64
        super(formFactory, formElement);
65
    }
66

    
67
    @Override
68
    protected void createControls(ICdmFormElement formElement, DerivedUnitFacade entity, int style) {
69
        toggleableText_titleCache = formFactory.createToggleableTextField(formElement, "Title Cache",
70
                entity.getTitleCache(), entity.isProtectedTitleCache(), style);
71

    
72
        if (!entity.getType().equals(SpecimenOrObservationType.FieldUnit)){
73
           combo_specorobstype = formFactory.createEnumComboElement(SpecimenOrObservationType.class, formElement, style);
74
           combo_specorobstype.setSelection(entity.getType());
75
        }
76

    
77
        selection_country = formFactory.createSelectionElement(NamedArea.class, //getConversationHolder(),
78
                formElement, "Country", entity.getCountry(), EntitySelectionElement.DELETABLE, style);
79
        if(PreferencesUtil.isCollectingAreaInGeneralSection()){
80
            section_collectingAreas = formFactory.createCollectingAreasDetailSection(getConversationHolder(), formElement, StoreUtil.getSectionStyle(CollectingAreasDetailSection.class, entity.getClass().getCanonicalName()));
81
            section_collectingAreas.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
82
            section_collectingAreas.setEntity(entity);
83
        }
84

    
85
        languageText_locality = formFactory.createLanguageStringWithLabelElement(formElement, "Locality",
86
                entity.getLocality(), style);
87
        element_point = formFactory.createPointElement(formElement, entity.getExactLocation(), style);
88
        element_elevation = formFactory.createGatheringEventUnitElement(
89
				formElement, "Elevation : ", entity, MinMaxTextSection.UnitType.ELEVATION,  style);
90

    
91
        element_date = formFactory.createTimePeriodElement(formElement, "Date", entity.getGatheringPeriod(), style);
92
        selection_collector = formFactory.createCollectorSelectionElement(formElement, "Collector", entity.getCollector(), EntitySelectionElement.ALL, style);
93
        selection_primary_collector = formFactory
94
	            .createCollectorSelectionElement(
95
	                    formElement, "Primary collector",
96
	                    entity.getCollector(), entity.getPrimaryCollector(), EntitySelectionElement.ALL,
97
	                    style);
98
        if (!(entity.getCollector() instanceof Team)){
99
	    	selection_primary_collector.setEnabled(false);
100
	    }
101
        selection_primary_collector.setIndent(8);
102
        text_collectingNumber = formFactory.createTextWithLabelElement(formElement, "Collecting number",
103
                entity.getFieldNumber(), style);
104
        checkIsPublish = formFactory.createCheckbox(formElement, "Publish", entity.innerFieldUnit().isPublish(), style);
105
    }
106

    
107
    @Override
108
    public void handleEvent(Object eventSource) {
109
        if (eventSource == toggleableText_titleCache) {
110
            getEntity().setTitleCache(toggleableText_titleCache.getText(), toggleableText_titleCache.getState());
111

    
112
        } else if (eventSource == selection_country) {
113
            getEntity().setCountry(selection_country.getSelection());
114
        } else if (eventSource == languageText_locality) {
115
            LanguageString locality = languageText_locality.updateLanguageString(getEntity().getLocality());
116
            getEntity().setLocality(locality);
117
        } else if (eventSource == element_point) {
118
            getEntity().setExactLocation(element_point.getPoint());
119
        } else if (eventSource == number_elevation) {
120
            getEntity().setAbsoluteElevation(number_elevation.getInteger());
121
        } else if (eventSource == element_date) {
122
            getEntity().setGatheringPeriod(element_date.getTimePeriod());
123
        } else if (eventSource == selection_collector) {
124
            getEntity().setCollector(selection_collector.getSelection());
125
            
126
            if (getEntity().getCollector() instanceof Team){
127
            	if (selection_primary_collector.getCollectorTeam() != null && selection_primary_collector.getEntity() != null ){
128
            		boolean collInNewTeam = false;
129
            		for (Person person:((Team)getEntity().getCollector()).getTeamMembers()){
130
            			collInNewTeam = person.getId() == selection_primary_collector.getEntity().getId();
131
            			if (collInNewTeam){
132
            				break;
133
            			}
134
            		}
135
            		if (!collInNewTeam){
136
            			selection_primary_collector.setEntity(null);
137
            		}
138
            	}
139
            	selection_primary_collector.setCollectorTeam((Team)getEntity().getCollector());
140
            }else{
141
            	selection_primary_collector.setEntity(null);
142
            }
143
            selection_primary_collector.setEnabled((getEntity().getCollector() instanceof Team));
144
            
145
        } else if (eventSource == selection_primary_collector) {
146
            getEntity().setPrimaryCollector((Person)selection_primary_collector.getSelection());
147
        } else if (eventSource == text_collectingNumber) {
148
            getEntity().setFieldNumber(text_collectingNumber.getText());
149
        } else if (eventSource == combo_specorobstype) {
150
            getEntity().setType(combo_specorobstype.getSelection());
151
        } else if (eventSource == checkIsPublish) {
152
            getEntity().innerFieldUnit().setPublish(checkIsPublish.getSelection());
153
        }
154

    
155
        toggleableText_titleCache.setText(getEntity().getTitleCache());
156

    
157
    }
158
    protected void updateControlStates(){
159
        if (getEntity() != null ){
160
            enabled = enabled && CdmStore.currentAuthentiationHasPermission(StoreUtil.getCdmEntity(getEntity()), requiredCrud);
161
        }else{
162
            enabled = true;
163
        }
164
        Set<Object> except = new HashSet<>(); 
165
        if (!selection_primary_collector.isEnabled() && enabled){
166
        	except.add(selection_primary_collector);
167
        }
168
        setEnabled(enabled, except);
169
        
170
    }
171

    
172
}
(23-23/38)