ref #6612 Custom Textfield with switch for all protectable cache fields
authorAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Thu, 11 May 2017 12:16:50 +0000 (14:16 +0200)
committerAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Thu, 11 May 2017 12:16:50 +0000 (14:16 +0200)
pom.xml
src/main/java/eu/etaxonomy/cdm/vaadin/AppWidgetSet.gwt.xml
src/main/java/eu/etaxonomy/cdm/vaadin/component/common/TimePeriodField.java [moved from src/main/java/eu/etaxonomy/cdm/vaadin/component/TimePeriodField.java with 98% similarity]
src/main/java/eu/etaxonomy/cdm/vaadin/ui/RegistrationUI.java
src/main/java/eu/etaxonomy/cdm/vaadin/view/reference/ReferencePopupEditor.java
src/main/java/eu/etaxonomy/vaadin/component/SwitchableTextField.java [new file with mode: 0644]
src/main/java/eu/etaxonomy/vaadin/mvp/AbstractPopupEditor.java
src/main/java/eu/etaxonomy/vaadin/ui/DevDayWidgetset.gwt.xml
src/main/webapp/VAADIN/themes/edit-valo/custom-fields.scss

diff --git a/pom.xml b/pom.xml
index dfaded2f14128fa2d520c7c40fea0d99567a95d4..a11f1cf62522dec5e382a53718507bda50e685a3 100755 (executable)
--- a/pom.xml
+++ b/pom.xml
       <artifactId>contextmenu</artifactId>
       <version>4.5</version>
     </dependency>
+    <dependency>
+       <groupId>org.vaadin.teemu</groupId>
+       <artifactId>switch</artifactId>
+       <version>3.0.0</version>
+    </dependency>
+    <dependency>
+       <groupId>com.vaadin.addon</groupId>
+       <artifactId>vaadin-onoffswitch</artifactId>
+       <version>0.0.1</version>
+    </dependency>
 <!--     <dependency>
         only in the edit repo
       <groupId>org.vaadin.addons</groupId>
index d20cdd827b7e134c2413a52eb6e161aa3cd083aa..566f8c47aa173d643a46fb13ffa702170e0ca437 100644 (file)
@@ -40,4 +40,8 @@
     
 
     
+
+    <inherits name="org.vaadin.teemu.switchui.SwitchComponentWidgetset" />
+
+    <inherits name="com.vaadin.addon.onoffswitch.WidgetSet" />
 </module>
similarity index 98%
rename from src/main/java/eu/etaxonomy/cdm/vaadin/component/TimePeriodField.java
rename to src/main/java/eu/etaxonomy/cdm/vaadin/component/common/TimePeriodField.java
index 6e541429eebe6428a7fe5a6b8dfd5110dcf7e2db..8a5b7853064ec48c95f2afc503e36cdc92a38a83 100644 (file)
@@ -6,7 +6,7 @@
 * 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.
 */
-package eu.etaxonomy.cdm.vaadin.component;
+package eu.etaxonomy.cdm.vaadin.component.common;
 
 import java.util.HashSet;
 import java.util.Set;
@@ -28,6 +28,7 @@ import com.vaadin.ui.themes.ValoTheme;
 
 import eu.etaxonomy.cdm.model.common.TimePeriod;
 import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
+import eu.etaxonomy.cdm.vaadin.component.PartialDateField;
 import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationStyles;
 import eu.etaxonomy.cdm.vaadin.util.formatter.DateTimeFormat;
 import eu.etaxonomy.cdm.vaadin.util.formatter.TimePeriodFormatter;
index 251ea28d0d45b9eeb9dc31371ec7ef0997b141bc..9e423d101dc76b34119e36d22e53b85e6a39e8d9 100644 (file)
@@ -77,8 +77,9 @@ public class RegistrationUI extends UI {
     }
     //---------------------------------------------
 
-    //private final String INITIAL_VIEW = "workflow/edit/100002";
+    // public static final String INITIAL_VIEW = "workflow/edit/10";
     public static final String INITIAL_VIEW =  DashBoardView.NAME;
+    static boolean debugMode = false;
 
     /*
      * this HACKY solution forces the bean to be instantiated, TODO do it properly
@@ -116,9 +117,6 @@ public class RegistrationUI extends UI {
 
         eventBus.publishEvent(new UIInitializedEvent());
 
-        //navigate to initial view
-        eventBus.publishEvent(new NavigationEvent(INITIAL_VIEW));
-
         String brand = "phycobank";
         //TODO create annotation:
         // @Styles(files={""}, branding="brand")
@@ -128,5 +126,27 @@ public class RegistrationUI extends UI {
         // the 'vaadin://' protocol refers to the VAADIN folder
         Resource registryCssFile = new ExternalResource("vaadin://branding/" + brand + "/css/branding.css");
         Page.getCurrent().getStyles().add(registryCssFile);
+
+        //navigate to initial view
+        String state = pageFragmentAsState();
+
+        if(debugMode && state != null){
+            eventBus.publishEvent(new NavigationEvent(state));
+        } else {
+            eventBus.publishEvent(new NavigationEvent(INITIAL_VIEW));
+        }
+    }
+
+    /**
+     * @return
+     */
+    private String pageFragmentAsState() {
+        Page page = Page.getCurrent();
+        String fragment = page.getUriFragment();
+        String state = null;
+        if(fragment.startsWith("!")){
+            state = fragment.substring(1, fragment.length());
+        }
+        return state;
     }
 }
index 3f16b24c8f54c2fe9a324ced999bc5a6c4fcacae..9ae1b61e759da372e90281ee5df910556510c035 100644 (file)
@@ -22,7 +22,7 @@ import com.vaadin.ui.TextField;
 
 import eu.etaxonomy.cdm.model.reference.Reference;
 import eu.etaxonomy.cdm.model.reference.ReferenceType;
-import eu.etaxonomy.cdm.vaadin.component.TimePeriodField;
+import eu.etaxonomy.cdm.vaadin.component.common.TimePeriodField;
 import eu.etaxonomy.cdm.vaadin.security.AccessRestrictedView;
 import eu.etaxonomy.vaadin.mvp.AbstractCdmPopupEditor;
 
@@ -86,9 +86,9 @@ public class ReferencePopupEditor extends AbstractCdmPopupEditor<Reference, Refe
         typeSelect.setRows(1);
         addField(typeSelect, "type", 3, row);
         row++;
-        addTextField("Reference cache", "titleCache", 0, row, GRID_COLS-1, row).setWidth(100, Unit.PERCENTAGE);
+        addSwitchableTextField("Reference cache", "titleCache", "protectedTitleCache", 0, row, GRID_COLS-1, row).setWidth(100, Unit.PERCENTAGE);
         row++;
-        addTextField("Abbrev. cache", "abbrevTitleCache", 0, row, GRID_COLS-1, row).setWidth(100, Unit.PERCENTAGE);
+        addSwitchableTextField("Abbrev. cache", "abbrevTitleCache", "protectedAbbrevTitleCache", 0, row, GRID_COLS-1, row).setWidth(100, Unit.PERCENTAGE);
         row++;
         titleField = addTextField("Title", "title", 0, row, GRID_COLS-1, row);
         titleField.setRequired(true);
diff --git a/src/main/java/eu/etaxonomy/vaadin/component/SwitchableTextField.java b/src/main/java/eu/etaxonomy/vaadin/component/SwitchableTextField.java
new file mode 100644 (file)
index 0000000..6787786
--- /dev/null
@@ -0,0 +1,165 @@
+/**
+* Copyright (C) 2017 EDIT
+* 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.
+*/
+package eu.etaxonomy.vaadin.component;
+
+import org.vaadin.teemu.switchui.Switch;
+
+import com.vaadin.data.fieldgroup.FieldGroup;
+import com.vaadin.ui.Component;
+import com.vaadin.ui.CssLayout;
+import com.vaadin.ui.CustomField;
+import com.vaadin.ui.TextField;
+
+
+/**
+ * @author a.kohlbecker
+ * @since May 11, 2017
+ *
+ */
+public class SwitchableTextField extends CustomField<String> {
+
+    private static final long serialVersionUID = -4760153886584883137L;
+
+    private static final String PRIMARY_STYLE = "v-switchable-textfield";
+
+    CssLayout root = new CssLayout();
+    private TextField textField = new TextField();
+    private SwitchButton unlockSwitch = new SwitchButton();
+
+    /**
+     * @param caption
+     */
+    public SwitchableTextField(String caption) {
+        super();
+        textField.setCaption(caption);
+        unlockSwitch.addValueChangeListener(e -> {
+            textField.setEnabled(unlockSwitch.getValue());
+        });
+        unlockSwitch.setValueSetLister(e -> {
+            textField.setEnabled(unlockSwitch.getValue());
+        });
+    }
+
+    /**
+     * {@inheritDoc}textField
+     */
+    @Override
+    protected Component initContent() {
+        root = new CssLayout();
+        root.addComponent(textField);
+        root.setWidth(getWidth(), getWidthUnits());
+        textField.setWidth(getWidth(), getWidthUnits());
+        root.addComponent(unlockSwitch);
+        setPrimaryStyleName(PRIMARY_STYLE);
+        return root;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Class<? extends String> getType() {
+        return String.class;
+    }
+
+    /**
+     * @return the serialversionuid
+     */
+    public static long getSerialversionuid() {
+        return serialVersionUID;
+    }
+
+    /**
+     * @return the textField
+     */
+    public TextField getTextField() {
+        return textField;
+    }
+
+    /**
+     * @return the unlockSwitch
+     */
+    public Switch getUnlockSwitch() {
+        return unlockSwitch;
+    }
+
+    public void bindTo(FieldGroup fieldGroup, Object textPropertyId, Object switchPropertyId){
+        fieldGroup.bind(textField, textPropertyId);
+        fieldGroup.bind(unlockSwitch, switchPropertyId);
+        textField.setEnabled(unlockSwitch.getValue());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setWidthUndefined() {
+        super.setWidthUndefined();
+        root.setWidthUndefined();
+        textField.setWidthUndefined();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setWidth(String width) {
+        super.setWidth(width);
+        root.setWidth(width);
+        textField.setWidth(width);
+    }
+
+    @Override
+    public void setWidth(float width, Unit unit){
+        super.setWidth(width, unit);
+        if(root != null){
+            root.setWidth(width, unit);
+            textField.setWidth(width, unit);
+        }
+    }
+
+    @Override
+    public void setStyleName(String style) {
+        super.setStyleName(style);
+        textField.setStyleName(style);
+        unlockSwitch.setStyleName(style);
+    }
+
+    @Override
+    public void addStyleName(String style) {
+        super.addStyleName(style);
+        textField.addStyleName(style);
+        unlockSwitch.addStyleName(style);
+    }
+
+    private class SwitchButton extends Switch {
+
+        private static final long serialVersionUID = 2557108593729214773L;
+
+        private ValueChangeListener valueSetListener = null;
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override
+        protected void setInternalValue(Boolean newValue) {
+            super.setInternalValue(newValue);
+            if(valueSetListener != null){
+                valueSetListener.valueChange(new ValueChangeEvent(this));
+            }
+        }
+
+        public void setValueSetLister(ValueChangeListener valueSetListener){
+            this.valueSetListener = valueSetListener;
+        }
+
+
+
+    }
+}
index c9e8723618f1b4694713d86da6ba31e378a35c3a..7b47e4b57f357a816c82b7bf6ff2a009821401ef 100644 (file)
@@ -41,6 +41,7 @@ import com.vaadin.ui.TextField;
 import com.vaadin.ui.VerticalLayout;
 import com.vaadin.ui.themes.ValoTheme;
 
+import eu.etaxonomy.vaadin.component.SwitchableTextField;
 import eu.etaxonomy.vaadin.ui.view.DoneWithPopupEvent;
 import eu.etaxonomy.vaadin.ui.view.DoneWithPopupEvent.Reason;
 
@@ -217,6 +218,25 @@ public abstract class AbstractPopupEditor<DTO extends Object, P extends Abstract
         return addField(new TextField(caption), propertyId, column, row);
     }
 
+    protected SwitchableTextField addSwitchableTextField(String caption, String textPropertyId, String switchPropertyId, int column1, int row1,
+            int column2, int row2)
+            throws OverlapsException, OutOfBoundsException {
+
+        SwitchableTextField field = new SwitchableTextField(caption);
+        field.bindTo(fieldGroup, textPropertyId, switchPropertyId);
+        addComponent(field, column1, row1, column2, row2);
+        return field;
+    }
+
+    protected SwitchableTextField addSwitchableTextField(String caption, String textPropertyId, String switchPropertyId, int column, int row)
+            throws OverlapsException, OutOfBoundsException {
+
+        SwitchableTextField field = new SwitchableTextField(caption);
+        field.bindTo(fieldGroup, textPropertyId, switchPropertyId);
+        addComponent(field, column, row);
+        return field;
+    }
+
     protected PopupDateField addDateField(String caption, String propertyId) {
         return addField(new PopupDateField(caption), propertyId);
     }
index 2093adcaea27eee947cf11e94a0c45b650455f97..d6fd5faae9cd193f9877bf011cf88ec3be34691b 100644 (file)
@@ -14,4 +14,8 @@
     
 
     
+
+    <inherits name="org.vaadin.teemu.switchui.SwitchComponentWidgetset" />
+
+    <inherits name="com.vaadin.addon.onoffswitch.WidgetSet" />
 </module>
index bf612fa821b0e08d7ee493192fdd4db2e542a006..e6c4678a3f24758447fdcd8e3c54b22e2b617821 100644 (file)
@@ -24,5 +24,23 @@ body .edit-valo { // increasing specifity to allow overriding the valo default f
           color: $helper-color;
           background-color: valo-font-color($helper-color);
           border-radius: $v-border-radius;
-      }
+   }
+  
+  // v-switchable-textfield
+  .v-switchable-textfield {
+    height: $v-line-height * 2;
+    .v-caption {
+        display: block;
+    }   
+    .v-textfield {
+        padding-right: $v-unit-size;
+    }
+    .v-switch {
+        z-index: 10;
+        width: $v-unit-size;
+        position: absolute;
+        right: 1px;
+        bottom: 1px;
+    }
+  }
 } 
\ No newline at end of file