further implementation for verbatimdate
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / element / DateDetailSection.java
index c54e04d0327bcee02c5d29920230bf9e69747e2c..2b897c936253c2f17adc48b97a13a674e94bb0e8 100644 (file)
@@ -1,9 +1,8 @@
-// $Id$
 /**
  * Copyright (C) 2007 EDIT
- * European Distributed Institute of Taxonomy 
+ * European Distributed Institute of Taxonomy
  * http://www.e-taxonomy.eu
- * 
+ *
  * The contents of this file are subject to the Mozilla Public License Version 1.1
  * See LICENSE.TXT at the top of this package for the full license terms.
  */
@@ -16,29 +15,38 @@ import org.joda.time.Partial;
 
 import eu.etaxonomy.cdm.common.CdmUtils;
 import eu.etaxonomy.cdm.model.common.TimePeriod;
+import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
 
 /**
  * <p>
  * DateDetailSection class.
  * </p>
- * 
+ *
  * @author n.hoffmann
  * @created Mar 31, 2010
  * @version 1.0
  */
 public class DateDetailSection extends AbstractFormSection<TimePeriod> {
 
-       private final TextWithLabelElement text_freeText;
-       private final PartialElement partialElement_start;
-       private final PartialElement partialElement_end;
-       private final TextWithLabelElement text_parseText;
+       protected TextWithLabelElement text_freeText;
+       private PartialElement partialElement_start;
+       private PartialElement partialElement_end;
+       private TextWithLabelElement text_parseText;
        private int cursorPosition;
 
-       /**
+       public int getCursorPosition() {
+        return cursorPosition;
+    }
+
+    public void setCursorPosition(int cursorPosition) {
+        this.cursorPosition = cursorPosition;
+    }
+
+    /**
         * <p>
         * Constructor for DateDetailSection.
         * </p>
-        * 
+        *
         * @param formFactory
         *            a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
         *            object.
@@ -53,13 +61,13 @@ public class DateDetailSection extends AbstractFormSection<TimePeriod> {
                super(formFactory, parentElement, style);
 
                partialElement_start = formFactory.createPartialElement(this,
-                               "Start: ", null, style);
-               partialElement_end = formFactory.createPartialElement(this, "End: ",
+                               "Start ", null, style);
+               partialElement_end = formFactory.createPartialElement(this, "End ",
                                null, style);
 
-               text_parseText = formFactory.createTextWithLabelElement(this, "Parse",
-                               null, style);
-               text_parseText.getMainControl().setLayoutData(
+               setText_parseText(formFactory.createTextWithLabelElement(this, "Parse",
+                               null, style));
+               getText_parseText().getMainControl().setLayoutData(
                                LayoutConstants.FILL_HORIZONTALLY(6, 1));
 
                text_freeText = formFactory.createTextWithLabelElement(this,
@@ -67,6 +75,7 @@ public class DateDetailSection extends AbstractFormSection<TimePeriod> {
                text_freeText.getMainControl().setLayoutData(
                                LayoutConstants.FILL_HORIZONTALLY(6, 1));
 
+
                formFactory.addPropertyChangeListener(this);
        }
 
@@ -77,12 +86,12 @@ public class DateDetailSection extends AbstractFormSection<TimePeriod> {
                }
                return super.getEntity();
        }
-       
+
        /**
         * <p>
         * Setter for the field <code>timePeriod</code>.
         * </p>
-        * 
+        *
         * @param timePeriod
         *            a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object.
         */
@@ -90,20 +99,20 @@ public class DateDetailSection extends AbstractFormSection<TimePeriod> {
        public void setEntity(TimePeriod timePeriod) {
                setEntityInternally(timePeriod);
                updateTitle();
-               text_parseText.setText(timePeriod.toString());
+               getText_parseText().setText(timePeriod.toString());
        }
-       
+
        /**
         * When setting the entity through parsing we do not want to alter the parse field
         * @param timePeriod
         */
-       private void setEntityInternally(TimePeriod timePeriod){
+       protected void setEntityInternally(TimePeriod timePeriod){
                Partial start = timePeriod.getStart();
                partialElement_start.setPartial(start);
                Partial end = timePeriod.getEnd();
                partialElement_end.setPartial(end);
 
-               ((Text) text_parseText.getMainControl()).setSelection(cursorPosition);
+               ((Text) getText_parseText().getMainControl()).setSelection(cursorPosition);
                text_freeText.setText(timePeriod.getFreeText());
 
                super.setEntity(timePeriod);
@@ -136,17 +145,17 @@ public class DateDetailSection extends AbstractFormSection<TimePeriod> {
                                event.getException()));
        }
 
-       private void handleEvent(Object eventSource) {
+       protected void handleEvent(Object eventSource) {
                if (eventSource == partialElement_start) {
                        Partial start = partialElement_start.getPartial();
                        getEntity().setStart(start);
                } else if (eventSource == partialElement_end) {
                        Partial end = partialElement_end.getPartial();
                        getEntity().setEnd(end);
-               } else if (eventSource == text_parseText) {
-                       cursorPosition = ((Text) text_parseText.getMainControl())
+               } else if (eventSource == getText_parseText()) {
+                       cursorPosition = ((Text) getText_parseText().getMainControl())
                                        .getCaretPosition();
-                       setEntityInternally(TimePeriod.parseString(text_parseText.getText()));
+                       setEntityInternally(TimePeriodParser.parseString(getText_parseText().getText()));
                } else if (eventSource == text_freeText) {
                        getEntity().setFreeText(text_freeText.getText());
                }
@@ -154,15 +163,15 @@ public class DateDetailSection extends AbstractFormSection<TimePeriod> {
                firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
        }
 
-       private void updateTitle(){
+       protected void updateTitle(){
                String title = CdmUtils.Nz(getEntity().toString());
                this.setText(title);
                layout();
        }
-       
+
        /*
         * (non-Javadoc)
-        * 
+        *
         * @see eu.etaxonomy.taxeditor.forms.AbstractFormSection#dispose()
         */
        /** {@inheritDoc} */
@@ -172,4 +181,12 @@ public class DateDetailSection extends AbstractFormSection<TimePeriod> {
                super.dispose();
        }
 
+    public TextWithLabelElement getText_parseText() {
+        return text_parseText;
+    }
+
+    public void setText_parseText(TextWithLabelElement text_parseText) {
+        this.text_parseText = text_parseText;
+    }
+
 }