de294870ebe18393972e29494ad4ee6262be2822
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / key / PolytomousKeyDetailElement.java
1 /**
2 *
3 */
4 package eu.etaxonomy.taxeditor.ui.section.key;
5
6 import org.eclipse.swt.SWT;
7
8 import eu.etaxonomy.cdm.model.description.PolytomousKey;
9 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
10 import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
11 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
12 import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
13 import eu.etaxonomy.taxeditor.ui.element.NumberWithLabelElement;
14 import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
15 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
16 import eu.etaxonomy.taxeditor.ui.section.occurrence.GeoScopePolyKeyDetailSection;
17
18 /**
19 * @author n.hoffmann
20 *
21 */
22 public class PolytomousKeyDetailElement extends
23 AbstractCdmDetailElement<PolytomousKey> {
24
25 private TextWithLabelElement textLabel;
26 private NumberWithLabelElement numberStartNumber;
27 private TaxonomicScopeSection sectionTaxonomicScope;
28 private GeoScopePolyKeyDetailSection sectionGeoScopes;
29
30 public PolytomousKeyDetailElement(CdmFormFactory formFactory,
31 ICdmFormElement formElement) {
32 super(formFactory, formElement);
33 }
34
35 @Override
36 protected void createControls(ICdmFormElement formElement,
37 PolytomousKey entity, int style) {
38 textLabel = formFactory.createTextWithLabelElement(formElement, "Title", entity.getTitleCache(), style);
39
40 numberStartNumber = formFactory.createNumberTextWithLabelElement(formElement, "Start Number", entity.getStartNumber(), style);
41
42 sectionTaxonomicScope = formFactory.createTaxonomicScopeSection(getConversationHolder(), formElement, style);
43 sectionTaxonomicScope.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
44 sectionTaxonomicScope.setEntity(entity);
45
46 sectionGeoScopes = formFactory.createGeoScopePolyKeyDetailSection(getConversationHolder(), formElement, SWT.NULL);
47 sectionGeoScopes.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
48 sectionGeoScopes.setEntity(entity);
49 }
50
51 public String getText() {
52 return textLabel.getText();
53 }
54
55 @Override
56 public void handleEvent(Object eventSource) {
57 if(eventSource==textLabel){
58 getEntity().setTitleCache(textLabel.getText(), true);
59 }
60 else if(eventSource==numberStartNumber){
61 getEntity().setStartNumber(numberStartNumber.getInteger());
62 }
63 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
64 }
65 }