fix #7717: add continued flag to timeperiod ui
authorKatja Luther <k.luther@bgbm.org>
Wed, 5 Sep 2018 10:56:23 +0000 (12:56 +0200)
committerKatja Luther <k.luther@bgbm.org>
Wed, 5 Sep 2018 10:56:23 +0000 (12:56 +0200)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CheckboxElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/DateDetailSection.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/PartialElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/mvc/element/DateElement.java

index adec1e278d14725be20bb50e1be465394d1268bc..09e794851d1a557ecc440a4989eee583b093683d 100644 (file)
@@ -87,6 +87,10 @@ public class CheckboxElement extends AbstractCdmFormElement implements Selection
                firePropertyChangeEvent(new CdmPropertyChangeEvent(this, e));
        }
 
+       public Button getMainControl(){
+           return checkbox;
+       }
+
        /** {@inheritDoc} */
        @Override
     public void widgetDefaultSelected(SelectionEvent e) {}
index 7c4b9da794841d616a86e3c5e5a22f6c6a655b1f..bba1fabf0a8f07ecd9ebd8c1b3d65442bbfc6a19 100644 (file)
@@ -15,6 +15,7 @@ public class DateDetailSection<T extends TimePeriod>
        protected TextWithLabelElement text_freeText;\r
        private PartialElement partialElement_start;\r
        private PartialElement partialElement_end;\r
+       private CheckboxElement period_continue;\r
        private TextWithLabelElement text_parseText;\r
     private TextWithLabelElement text_VerbatimDate = null;\r
        private int cursorPosition;\r
@@ -56,6 +57,8 @@ public class DateDetailSection<T extends TimePeriod>
                                "Start ", null, style);\r
                partialElement_end = formFactory.createPartialElement(this, "End ",\r
                                null, style);\r
+               period_continue = formFactory.createCheckbox(this, "Continue", false, style);\r
+               period_continue.getMainControl().setLayoutData(LayoutConstants.FILL_HORIZONTALLY(6,1));\r
                if (includeVerbatim){\r
                text_VerbatimDate = formFactory.createTextWithLabelElement(this,\r
                        "Verbatim Date", null, style);\r
@@ -129,7 +132,10 @@ public class DateDetailSection<T extends TimePeriod>
                partialElement_start.setPartial(start);\r
                Partial end = timePeriod.getEnd();\r
                partialElement_end.setPartial(end);\r
-\r
+               period_continue.setSelection(timePeriod.isContinued());\r
+               if (timePeriod.isContinued()){\r
+                   partialElement_end.setEnabled(false);\r
+               }\r
                ((Text) getText_parseText().getMainControl()).setSelection(cursorPosition);\r
                text_freeText.setText(timePeriod.getFreeText());\r
                if (includeVerbatim){\r
@@ -174,6 +180,7 @@ public class DateDetailSection<T extends TimePeriod>
                } else if (eventSource == partialElement_end) {\r
                        Partial end = partialElement_end.getPartial();\r
                        getEntity().setEnd(end);\r
+\r
                } else if (eventSource == getText_parseText()) {\r
                        cursorPosition = ((Text) getText_parseText().getMainControl())\r
                                        .getCaretPosition();\r
@@ -181,11 +188,18 @@ public class DateDetailSection<T extends TimePeriod>
                        setEntityInternally(newInstance);\r
                } else if (eventSource == text_freeText) {\r
                        getEntity().setFreeText(text_freeText.getText());\r
-               }else if (eventSource == text_VerbatimDate) {\r
-            VerbatimTimePeriod entity = (VerbatimTimePeriod)getEntity();\r
-            entity.setVerbatimDate(text_VerbatimDate.getText());\r
+               }else if (eventSource == period_continue) {\r
+                   boolean continued = period_continue.getSelection();\r
+            getEntity().setContinued(continued);\r
+            if (continued){\r
+                partialElement_end.setAllNull();\r
+                partialElement_end.setEnabled(false);\r
+            }else{\r
+                partialElement_end.setEnabled(true);\r
+            }\r
         }\r
                updateTitle();\r
+               updateParseField();\r
                firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));\r
        }\r
 \r
@@ -196,6 +210,10 @@ public class DateDetailSection<T extends TimePeriod>
                this.setText(title);\r
                layout();\r
        }\r
+       protected void updateParseField(){\r
+           getText_parseText().setText(getEntity().toString());\r
+           layout();\r
+    }\r
 \r
        /** {@inheritDoc} */\r
        @Override\r
index 3492f3902bce1890bbbe038e53342e683d40a1aa..a29b8047c3a0c938121d8c2c2dd507de342e00ff 100644 (file)
@@ -149,4 +149,20 @@ public class PartialElement extends AbstractCdmFormElement implements ISelectabl
        public void setSelected(boolean selected) {
                setBackground(selected ? SELECTED : getPersistentBackground());
        }
+
+       public void setEnabled(boolean enabled){
+           this.number_day.setEnabled(enabled);
+           this.number_month.setEnabled(enabled);
+           this.number_year.setEnabled(enabled);
+       }
+
+    /**
+     *
+     */
+    public void setAllNull() {
+        this.number_day.setNumber(null);
+        this.number_month.setNumber(null);
+        this.number_year.setNumber(null);
+
+    }
 }
index 204f9926fb455693889a488b73af05f021b45070..d517ef76e1c7afa2027f169f37f1c032ad9be8fa 100644 (file)
@@ -11,7 +11,6 @@ package eu.etaxonomy.taxeditor.ui.mvc.element;
 
 
 
-import org.apache.lucene.analysis.shingle.ShingleMatrixFilter.OneDimensionalNonWeightedTokenSettingsCodec;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.DisposeEvent;
 import org.eclipse.swt.events.DisposeListener;
@@ -23,14 +22,11 @@ import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.DateTime;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.Text;
 import org.eclipse.ui.forms.widgets.FormToolkit;
 import org.eclipse.ui.forms.widgets.TableWrapLayout;
 import org.joda.time.DateTimeZone;
-import org.joda.time.format.DateTimeFormatter;
 
 import eu.etaxonomy.taxeditor.model.ImageResources;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
@@ -48,9 +44,9 @@ public class DateElement extends AbstractCdmComposite<DateElementController>  {
     private org.joda.time.DateTime initialDateTime;
     private Text textDate;
     private final Button openDateDialog;
-    
+
     private static final String pattern = "yyyy-MM-dd HH:mm";
-   
+
 
     /**
      * Create the composite.
@@ -63,8 +59,8 @@ public class DateElement extends AbstractCdmComposite<DateElementController>  {
        if (initDateTime != null){
                this.initialDateTime = initDateTime.toDateTime(DateTimeZone.UTC);
         }
-        
-        
+
+
         addDisposeListener(new DisposeListener() {
             @Override
             public void widgetDisposed(DisposeEvent e) {
@@ -83,39 +79,39 @@ public class DateElement extends AbstractCdmComposite<DateElementController>  {
             tableWrapLayout.bottomMargin = 0;
             setLayout(tableWrapLayout);
         }
-     
+
         Composite composite = new Composite (this, SWT.NONE);
        GridLayout layout = new GridLayout ();
-    
+
        layout.numColumns = 2;
        layout.marginWidth = 0;
-               
+
        composite.setLayout(layout);
-       
-       
+
+
        textDate = toolkit.createText(composite, null, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION);
-       
+
         textDate.setEditable(editableText);
-       
+
         GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
         gridData.minimumWidth = 100;
-                       
+
         textDate.setLayoutData(gridData);
         openDateDialog = new Button (composite, SWT.PUSH);
         Image image = ImageResources.getImage(ImageResources.DATE);
    //     openDateDialog.setText ("Open Date Dialog");
         openDateDialog.setImage(image);
-       
+
         openDateDialog.addSelectionListener (new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent e){
                        final Shell dialog = new Shell (parent.getShell(), SWT.DIALOG_TRIM);
-               
+
                        dialog.setLayout (new GridLayout (3, false));
                        dialog.setText(label);
 
                        final DateTime calendar = new DateTime (dialog, SWT.CALENDAR | SWT.BORDER);
-                       
+
                        final DateTime time = new DateTime (dialog, SWT.TIME | SWT.SHORT);
                        if (initialDateTime != null){
                                calendar.setDate(initialDateTime.getYear(), initialDateTime.getMonthOfYear()-1, initialDateTime.getDayOfMonth());
@@ -123,7 +119,7 @@ public class DateElement extends AbstractCdmComposite<DateElementController>  {
                                time.setMinutes(initialDateTime.getMinuteOfHour());
 //                             time.setSeconds(initialDateTime.getSecondOfMinute());
                        }
-                       
+
 
 //                     new Label (dialog, SWT.NONE);
 //                     new Label (dialog, SWT.NONE);
@@ -142,7 +138,7 @@ public class DateElement extends AbstractCdmComposite<DateElementController>  {
                        dialog.open ();
                }
         });
-       
+
         toolkit.adapt(textDate, true, true);
     }
 
@@ -154,14 +150,14 @@ public class DateElement extends AbstractCdmComposite<DateElementController>  {
     public Text getTextDate() {
         return textDate;
     }
-    
-   
-    
-       
+
+
+
+
     public static org.joda.time.DateTime makeZonedTimeFromSWT(
-                                       org.eclipse.swt.widgets.DateTime widget, 
+                                       org.eclipse.swt.widgets.DateTime widget,
                                        org.eclipse.swt.widgets.DateTime dateTime) {
-                 //the first month of the year is 0                      
+                 //the first month of the year is 0
                  return new org.joda.time.DateTime(widget.getYear(),
                                  widget.getMonth()+1,
                                  widget.getDay(),
@@ -180,9 +176,9 @@ public class DateElement extends AbstractCdmComposite<DateElementController>  {
                  widget.setDay(dateTime.getDay());
                  widget.setHours(dateTime.getHours());
                  widget.setMinutes(dateTime.getMinutes());
-                 
+
        }
-               
+
        public void setData (org.joda.time.DateTime data) {
                        this.initialDateTime = data;
                        this.controller.setDateTime(data);