Project

General

Profile

« Previous | Next » 

Revision 9dda5772

Added by Cherian Mathew almost 9 years ago

CdmFormFactory : added createmethods for GatheringEventUnitElement, MinMaxTextSection and createDefinedTermComboElement
MinMaxTextSection : new section for the min / max / text values of elevation / distance to ground / distance to water surface of the gathering event part of the DerivedUnitFacade
GatheringEventUnitElement : new element for elevation / distance to ground / distance to water surface units

View differences:

.gitattributes
1272 1272
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CdmPropertyChangeEvent.java -text
1273 1273
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CheckboxElement.java -text
1274 1274
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/DateDetailSection.java -text
1275
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/GatheringEventUnitElement.java -text
1275 1276
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/ICdmFormElement.java -text
1276 1277
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/IEnableableFormElement.java -text
1277 1278
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/IEntityElement.java -text
......
1288 1289
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/LabelElement.java -text
1289 1290
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/LanguageStringWithLabelElement.java -text
1290 1291
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/LayoutConstants.java -text
1292
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/MinMaxTextSection.java -text
1291 1293
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/MultilanguageTextElement.java -text
1292 1294
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/NumberWithLabelElement.java -text
1293 1295
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/PartialElement.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CdmFormFactory.java
40 40
import org.springframework.security.core.GrantedAuthority;
41 41

  
42 42
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
43
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
43 44
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
44 45
import eu.etaxonomy.cdm.model.agent.Person;
45 46
import eu.etaxonomy.cdm.model.agent.Team;
......
89 90
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
90 91
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
91 92
import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;
93
import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
92 94
import eu.etaxonomy.cdm.model.reference.Reference;
93 95
import eu.etaxonomy.cdm.model.taxon.Taxon;
94 96
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
......
96 98
import eu.etaxonomy.taxeditor.store.StoreUtil;
97 99
import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
98 100
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
101
import eu.etaxonomy.taxeditor.ui.element.MinMaxTextSection.UnitType;
99 102
import eu.etaxonomy.taxeditor.ui.openurl.IOpenUrlEnabled;
100 103
import eu.etaxonomy.taxeditor.ui.openurl.OpenUrlSelectorElement;
101 104
import eu.etaxonomy.taxeditor.ui.password.EditPasswordElement;
......
795 798
		parentElement.addElement(element);
796 799
		return element;
797 800
	}
801
	
802
	/**
803
	 * <p>
804
	 * createTermComboElement
805
	 * </p>
806
	 * 
807
	 * @param termComboType
808
	 *            a
809
	 *            {@link eu.eu.etaxonomy.taxeditor.ui.element.CdmFormFactory.TermComboType}
810
	 *            object.
811
	 * @param parentElement
812
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
813
	 *            object.
814
	 * @param labelString
815
	 *            a {@link java.lang.String} object.
816
	 * @param selection
817
	 *            a {@link eu.etaxonomy.cdm.model.common.DefinedTermBase}
818
	 *            object.
819
	 * @param style
820
	 *            a int.
821
	 * @return a {@link eu.etaxonomy.taxeditor.ui.combo.TermComboElement}
822
	 *         object.
823
	 */
824
	
825
	public <T extends DefinedTermBase> TermComboElement<T> createDefinedTermComboElement(
826
			TermType termType, 
827
			ICdmFormElement parentElement,
828
			String labelString, 
829
			T selection, 
830
			int style) {
831
		TermComboElement<T> element = new TermComboElement<T>(this, parentElement, termType, labelString, selection, style);
832
		adapt(element);
833
		parentElement.addElement(element);
834
		return element;
835
	}
798 836

  
799 837
	/**
800 838
	 * <p>
......
1051 1089
		parentElement.addElement(element);
1052 1090
		return element;
1053 1091
	}
1092
	
1093
	/**
1094
	 * <p>
1095
	 * createGatheringEventUnitElement
1096
	 * </p>
1097
	 * 
1098
	 * @param parentElement
1099
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1100
	 *            object.
1101
	 * @param labelString
1102
	 *            a {@link java.lang.String} object.
1103
	 * @param timePeriod
1104
	 *            a {@link eu.etaxonomy.cdm.model.common.GatheringEvent} object.
1105
	 * @param style
1106
	 *            a int.
1107
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.GatheringEventUnitElement}
1108
	 *         object.
1109
	 */
1110
	public GatheringEventUnitElement createGatheringEventUnitElement(
1111
			ICdmFormElement parentElement, 
1112
			String labelString,
1113
			DerivedUnitFacade gatheringEvent, 
1114
			MinMaxTextSection.UnitType unitType,			
1115
			int style) {
1116
		GatheringEventUnitElement element = new GatheringEventUnitElement(this, 
1117
				parentElement,
1118
				labelString, 
1119
				gatheringEvent, 
1120
				unitType,
1121
				style);
1122
		adapt(element);
1123
		parentElement.addElement(element);
1124
		return element;
1125
	}
1054 1126

  
1055 1127
	/**
1056 1128
	 * <p>
......
1096 1168
		adapt(section);
1097 1169
		return section;
1098 1170
	}
1171
	
1172
	/**
1173
	 * <p>
1174
	 * createDateDetailSection
1175
	 * </p>
1176
	 * 
1177
	 * @param parentElement
1178
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1179
	 *            object.
1180
	 * @param style
1181
	 *            a int.
1182
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.MinMaxTextSection}
1183
	 *         object.
1184
	 */
1185
	public MinMaxTextSection createMinMaxTextSection(ICdmFormElement parentElement, UnitType unitType, int style) {
1186
		MinMaxTextSection section = new MinMaxTextSection(this, parentElement, unitType, style);
1187
		parentElement.addElement(section);
1188
		adapt(section);
1189
		return section;
1190
	}
1099 1191

  
1100 1192
	/**
1101 1193
	 * <p>
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/GatheringEventUnitElement.java
1
// $Id$
2
/**
3
 * Copyright (C) 2007 EDIT
4
 * European Distributed Institute of Taxonomy 
5
 * http://www.e-taxonomy.eu
6
 * 
7
 * The contents of this file are subject to the Mozilla Public License Version 1.1
8
 * See LICENSE.TXT at the top of this package for the full license terms.
9
 */
10

  
11
package eu.etaxonomy.taxeditor.ui.element;
12

  
13
import org.eclipse.jface.util.PropertyChangeEvent;
14
import org.eclipse.swt.graphics.Color;
15
import org.eclipse.swt.widgets.Label;
16
import org.eclipse.ui.forms.widgets.Section;
17

  
18
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
19
import eu.etaxonomy.cdm.model.common.TimePeriod;
20
import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
21

  
22
/**
23
 * <p>
24
 * GatheringEventUnitElement class.
25
 * </p>
26
 * 
27
 * @author c.mathew
28
 * @created 23 Jul. 2013
29
 * @version 1.0
30
 */
31
public class GatheringEventUnitElement extends AbstractCdmFormElement implements ISelectable {
32
	
33
	private final Label label;
34
	private final MinMaxTextSection section_minMaxText;
35

  
36
	/**
37
	 * <p>
38
	 * Constructor for TimePeriodElement.
39
	 * </p>
40
	 * 
41
	 * @param style
42
	 *            a int.
43
	 * @param formFactory
44
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
45
	 *            object.
46
	 * @param parentElement
47
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
48
	 *            object.
49
	 * @param labelString
50
	 *            a {@link java.lang.String} object.
51
	 * @param timePeriod
52
	 *            a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object.
53
	 */
54
	public GatheringEventUnitElement(CdmFormFactory formFactory,
55
			ICdmFormElement parentElement, 
56
			String labelString,
57
			DerivedUnitFacade gatheringEvent, 
58
			MinMaxTextSection.UnitType unitType,
59
			final int style) {
60
		super(formFactory, parentElement);
61

  
62
		label = formFactory.createLabel(getLayoutComposite(), labelString);
63
		addControl(label);
64

  
65
		section_minMaxText = formFactory.createMinMaxTextSection(this,
66
				unitType,
67
				Section.TWISTIE);
68
		
69
		addControl(section_minMaxText);	
70

  
71
		section_minMaxText.setEntity(gatheringEvent);
72
		
73
		formFactory.addPropertyChangeListener(this);
74
	}
75

  
76

  
77
	/** {@inheritDoc} */
78
	@Override
79
	public void propertyChange(PropertyChangeEvent event) {
80
		if (event == null) {
81
			return;
82
		}
83
		Object eventSource = event.getSource();
84

  
85
		if (getElements().contains(eventSource)) {
86
			handleEvent(eventSource);
87
		}
88
	}
89

  
90
	private void handleEvent(Object eventSource) {
91
		if (eventSource == section_minMaxText) {			
92
			firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
93
		}
94
	}
95

  
96
	/** {@inheritDoc} */
97
	@Override
98
	public void setBackground(Color color) {
99
		label.setBackground(color);
100
		section_minMaxText.setBackground(color);
101
	}
102
	
103
	@Override
104
	public void setSelected(boolean selected) {
105
		setBackground(selected ? SELECTED : getPersistentBackground());
106
	}
107

  
108
	public void setLabel(String string) {
109
		label.setText(string);
110
	}
111
}
112

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/MinMaxTextSection.java
1
// $Id$
2
/**
3
 * Copyright (C) 2007 EDIT
4
 * European Distributed Institute of Taxonomy 
5
 * http://www.e-taxonomy.eu
6
 * 
7
 * The contents of this file are subject to the Mozilla Public License Version 1.1
8
 * See LICENSE.TXT at the top of this package for the full license terms.
9
 */
10

  
11
package eu.etaxonomy.taxeditor.ui.element;
12

  
13
import org.eclipse.jface.util.PropertyChangeEvent;
14
import org.eclipse.swt.layout.RowLayout;
15

  
16
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
17
import eu.etaxonomy.cdm.common.CdmUtils;
18
import eu.etaxonomy.cdm.model.common.TimePeriod;
19
import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
20

  
21
/**
22
 * <p>
23
 * MinMaxTextSection class.
24
 * </p>
25
 * 
26
 * @author c.mathew
27
 * @created 23 Jul 2013
28
 * @version 1.0
29
 */
30
public class MinMaxTextSection extends AbstractFormSection<DerivedUnitFacade> {
31

  
32
	private final TextWithLabelElement text_freeText;
33
	private final NumberWithLabelElement text_minVal;
34
	private final NumberWithLabelElement text_maxVal;
35
	private int cursorPosition;
36
	
37
	// unit types handled by this section
38
	public enum UnitType {
39
		ELEVATION,
40
		DIST_TO_GROUND,
41
		DIST_TO_WATER
42
	}
43

  
44
	private UnitType unitType = UnitType.ELEVATION;
45

  
46
	/**
47
	 * <p>
48
	 * Constructor for DateDetailSection.
49
	 * </p>
50
	 * 
51
	 * @param formFactory
52
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
53
	 *            object.
54
	 * @param parentElement
55
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
56
	 *            object.
57
	 * @param style
58
	 *            a int.
59
	 */
60
	protected MinMaxTextSection(CdmFormFactory formFactory,
61
			ICdmFormElement parentElement, UnitType unitType, int style) {
62
		super(formFactory, parentElement, style);
63
		this.unitType = unitType;
64
		getLayoutComposite().setLayout(LayoutConstants.LAYOUT(2, false));
65

  
66
		text_minVal = formFactory.createNumberTextWithLabelElement(this,
67
				"Min : ", getMinimum(), style);
68
		
69
		text_maxVal = formFactory.createNumberTextWithLabelElement(this,
70
				"Max : ", getMaximum(), style);
71
	
72
		text_freeText = formFactory.createTextWithLabelElement(this,
73
				"Freetext : ", getFreetext(), style);
74

  
75
		formFactory.addPropertyChangeListener(this);
76
	}
77

  
78
	/**
79
	 * <p>
80
	 * Setter for the field <code>timePeriod</code>.
81
	 * </p>
82
	 * 
83
	 * @param timePeriod
84
	 *            a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object.
85
	 */
86
	@Override
87
	public void setEntity(DerivedUnitFacade gatheringEvent) {
88
		super.setEntity(gatheringEvent);
89
		updateValues();
90
	}
91

  
92
	private void updateValues() {
93
		if(getEntity() != null) {
94
			switch(unitType) {
95
			case ELEVATION:
96
				if(getEntity().getAbsoluteElevation() != null) {
97
					text_minVal.setNumber(getEntity().getAbsoluteElevation());
98
				}
99
				if(getEntity().getAbsoluteElevationMaximum() != null) {
100
					text_maxVal.setNumber(getEntity().getAbsoluteElevation());
101
				}
102
				if(getEntity().getAbsoluteElevationText() != null) {
103
					text_freeText.setText(getEntity().getAbsoluteElevationText());
104
				}
105
				break;
106
			case DIST_TO_GROUND:
107
				if(getEntity().getDistanceToGround() != null) {
108
					text_minVal.setNumber(getEntity().getDistanceToGround());
109
				}
110
				if(getEntity().getDistanceToGroundMax() != null) {
111
					text_maxVal.setNumber(getEntity().getDistanceToGroundMax());
112
				}
113
				if(getEntity().getDistanceToGroundText() != null) {
114
					text_freeText.setText(getEntity().getDistanceToGroundText());
115
				}
116
				break;			
117
			case DIST_TO_WATER:
118
				if(getEntity().getDistanceToWaterSurface() != null) {
119
					text_minVal.setNumber(getEntity().getDistanceToWaterSurface());
120
				}
121
				if(getEntity().getDistanceToWaterSurfaceMax() != null) {
122
					text_maxVal.setNumber(getEntity().getDistanceToWaterSurfaceMax());
123
				}
124
				if(getEntity().getDistanceToWaterSurfaceText() != null) {
125
					text_freeText.setText(getEntity().getDistanceToWaterSurfaceText());
126
				}
127
				break;		
128
			default:
129
				break;
130
			}
131

  
132
		}
133
	}
134
	/** {@inheritDoc} */
135
	@Override
136
	public void propertyChange(PropertyChangeEvent event) {
137
		if (event == null) {
138
			return;
139
		}
140
		Object eventSource = event.getSource();
141

  
142
		if (getElements().contains(eventSource)) {
143
			if (event instanceof CdmPropertyChangeEvent) {
144
				if (((CdmPropertyChangeEvent) event).hasException()) {
145
					handleException((CdmPropertyChangeEvent) event);
146
					return;
147
				}
148
			}
149
			handleEvent(eventSource);
150
		}
151
	}
152

  
153
	/**
154
	 * @param event
155
	 */
156
	private void handleException(CdmPropertyChangeEvent event) {
157
		firePropertyChangeEvent(new CdmPropertyChangeEvent(this,
158
				event.getException()));
159
	}
160

  
161
	private void handleEvent(Object eventSource) {
162
		if (eventSource == text_minVal) {			
163
			updateMinimum();
164
		} else if (eventSource == text_maxVal) {
165
			updateMaximum();
166
		} else if (eventSource == text_freeText) {
167
			updateFreetext();		
168
		} 
169
		firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
170
	}
171

  
172

  
173
	
174
	/*
175
	 * (non-Javadoc)
176
	 * 
177
	 * @see eu.etaxonomy.taxeditor.forms.AbstractFormSection#dispose()
178
	 */
179
	/** {@inheritDoc} */
180
	@Override
181
	public void dispose() {
182
		formFactory.removePropertyChangeListener(this);
183
		super.dispose();
184
	}
185
	
186
	private void updateMinimum() {
187
		switch(unitType) {
188
		case ELEVATION:
189
			getEntity().setAbsoluteElevation(text_minVal.getInteger());
190
			break;
191
		case DIST_TO_GROUND:
192
			getEntity().setDistanceToGround(text_minVal.getDouble());
193
			break;			
194
		case DIST_TO_WATER:
195
			getEntity().setDistanceToWaterSurface(text_minVal.getDouble());
196
			break;				
197
		}
198
	}
199
	
200
	private Number getMinimum() {
201
		if(getEntity() == null) {
202
			return null;
203
		}
204
		switch(unitType) {
205
		case ELEVATION:
206
			return getEntity().getAbsoluteElevation();			
207
		case DIST_TO_GROUND:
208
			return getEntity().getDistanceToGround();			
209
		case DIST_TO_WATER:
210
			return getEntity().getDistanceToWaterSurface();					
211
		}
212
		return null;
213
	}
214
	
215
	private void updateMaximum() {
216
		switch(unitType) {
217
		case ELEVATION:
218
			getEntity().setAbsoluteElevationMax(text_maxVal.getInteger());
219
			break;
220
		case DIST_TO_GROUND:
221
			getEntity().setDistanceToGroundMax(text_maxVal.getDouble());
222
			break;			
223
		case DIST_TO_WATER:
224
			getEntity().setDistanceToWaterSurfaceMax(text_maxVal.getDouble());
225
			break;				
226
		}
227
	}
228
	
229
	private Number getMaximum() {
230
		if(getEntity() == null) {
231
			return null;
232
		}
233
		switch(unitType) {
234
		case ELEVATION:
235
			return getEntity().getAbsoluteElevationMaximum();			
236
		case DIST_TO_GROUND:
237
			return getEntity().getDistanceToGroundMax();			
238
		case DIST_TO_WATER:
239
			return getEntity().getDistanceToWaterSurfaceMax();					
240
		}
241
		return null;
242
	}
243
	
244
	private void updateFreetext() {
245
		switch(unitType) {
246
		case ELEVATION:
247
			getEntity().setAbsoluteElevationText(text_freeText.getText());
248
			break;
249
		case DIST_TO_GROUND:
250
			getEntity().setDistanceToGroundText(text_freeText.getText());
251
			break;			
252
		case DIST_TO_WATER:
253
			getEntity().setDistanceToWaterSurfaceText(text_freeText.getText());
254
			break;				
255
		}
256
	}	
257
	
258
	private String getFreetext() {
259
		if(getEntity() == null) {
260
			return null;
261
		}
262
		switch(unitType) {
263
		case ELEVATION:
264
			return getEntity().getAbsoluteElevationText();			
265
		case DIST_TO_GROUND:
266
			return getEntity().getDistanceToGroundText();			
267
		case DIST_TO_WATER:
268
			return getEntity().getDistanceToWaterSurfaceText();					
269
		}
270
		return null;
271
	}
272

  
273
}
274

  

Also available in: Unified diff