From 8a85f18d755cdcd97cbab88ddc664cdc6bea0b39 Mon Sep 17 00:00:00 2001 From: Gleb Gorelov Date: Mon, 3 Apr 2017 18:59:19 +0400 Subject: [PATCH] PL-8777 Support for Buffered mode for field components --- .../gui/components/DesktopCheckBox.java | 27 ++++++++ .../gui/components/DesktopDateField.java | 27 ++++++++ .../gui/components/DesktopLookupField.java | 27 ++++++++ .../gui/components/DesktopPasswordField.java | 27 ++++++++ .../gui/components/DesktopPickerField.java | 27 ++++++++ .../gui/components/DesktopSearchField.java | 27 ++++++++ .../DesktopSuggestionPickerField.java | 27 ++++++++ .../gui/components/DesktopTextArea.java | 27 ++++++++ .../gui/components/DesktopTextField.java | 27 ++++++++ .../gui/components/DesktopTimeField.java | 27 ++++++++ .../cuba/gui/components/CheckBox.java | 2 +- .../cuba/gui/components/Component.java | 41 ++++++++++++ .../cuba/gui/components/DateField.java | 2 +- .../cuba/gui/components/LookupField.java | 2 +- .../cuba/gui/components/PickerField.java | 2 +- .../cuba/gui/components/TextInputField.java | 2 +- .../cuba/gui/components/TimeField.java | 2 +- .../gui/src/com/haulmont/cuba/gui/window.xsd | 25 ++++++- .../layout/loaders/AbstractFieldLoader.java | 8 +++ .../loaders/AbstractTextFieldLoader.java | 1 + .../xml/layout/loaders/CheckBoxLoader.java | 7 ++ .../xml/layout/loaders/DateFieldLoader.java | 2 + .../xml/layout/loaders/LookupFieldLoader.java | 2 + .../xml/layout/loaders/PickerFieldLoader.java | 2 + .../xml/layout/loaders/TimeFieldLoader.java | 2 + .../web/gui/components/WebAbstractField.java | 20 ++++++ .../gui/components/WebAbstractTextField.java | 25 +++++++ .../cuba/web/gui/components/WebCheckBox.java | 25 +++++++ .../cuba/web/gui/components/WebDateField.java | 65 ++++++++++++++++++- .../web/gui/components/WebLookupField.java | 25 +++++++ .../gui/components/WebLookupPickerField.java | 28 ++++++++ .../web/gui/components/WebPickerField.java | 28 +++++++- .../web/gui/components/WebRichTextArea.java | 25 +++++++ .../gui/components/WebSearchPickerField.java | 28 ++++++++ .../gui/components/WebSuggestionField.java | 25 +++++++ .../components/WebSuggestionPickerField.java | 25 +++++++ .../cuba/web/gui/components/WebTimeField.java | 25 +++++++ .../cuba/web/toolkit/ui/CubaDateField.java | 6 ++ 38 files changed, 710 insertions(+), 12 deletions(-) diff --git a/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopCheckBox.java b/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopCheckBox.java index 23c9e36ae5..b437ab9f6f 100644 --- a/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopCheckBox.java +++ b/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopCheckBox.java @@ -214,4 +214,31 @@ public class DesktopCheckBox extends DesktopAbstractField implements public boolean isChecked() { return impl.isSelected(); } + + @Override + public void commit() { + // do nothing + } + + @Override + public void discard() { + // do nothing + } + + @Override + public boolean isBuffered() { + // do nothing + return false; + } + + @Override + public void setBuffered(boolean buffered) { + // do nothing + } + + @Override + public boolean isModified() { + // do nothing + return false; + } } \ No newline at end of file diff --git a/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopDateField.java b/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopDateField.java index 1ebbdc35c6..d6e5c942aa 100644 --- a/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopDateField.java +++ b/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopDateField.java @@ -633,6 +633,33 @@ public class DesktopDateField extends DesktopAbstractField implements Da return new Dimension(110, DesktopComponentsHelper.FIELD_HEIGHT); } + @Override + public void commit() { + // do nothing + } + + @Override + public void discard() { + // do nothing + } + + @Override + public boolean isBuffered() { + // do nothing + return false; + } + + @Override + public void setBuffered(boolean buffered) { + // do nothing + } + + @Override + public boolean isModified() { + // do nothing + return false; + } + public class FocusableComposition extends JPanel implements FocusableComponent, Flushable { @Override diff --git a/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopLookupField.java b/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopLookupField.java index 96394a0f79..47cc970352 100644 --- a/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopLookupField.java +++ b/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopLookupField.java @@ -738,6 +738,33 @@ public class DesktopLookupField extends DesktopAbstractOptionsField return Collections.singleton(getValue()); } + @Override + public void commit() { + // do nothing + } + + @Override + public void discard() { + // do nothing + } + + @Override + public boolean isBuffered() { + // do nothing + return false; + } + + @Override + public void setBuffered(boolean buffered) { + // do nothing + } + + @Override + public boolean isModified() { + // do nothing + return false; + } + protected class NullOption extends EntityWrapper { public NullOption() { super(new AbstractNotPersistentEntity() { diff --git a/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopPasswordField.java b/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopPasswordField.java index bf2abb197e..cf70827880 100644 --- a/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopPasswordField.java +++ b/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopPasswordField.java @@ -62,6 +62,33 @@ public class DesktopPasswordField extends DesktopAbstractTextField public Collection getLookupSelectedItems() { return Collections.singleton(getValue()); } + + @Override + public void commit() { + // do nothing + } + + @Override + public void discard() { + // do nothing + } + + @Override + public boolean isBuffered() { + // do nothing + return false; + } + + @Override + public void setBuffered(boolean buffered) { + // do nothing + } + + @Override + public boolean isModified() { + // do nothing + return false; + } } diff --git a/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopSearchField.java b/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopSearchField.java index 04611d79cd..de3773abc1 100644 --- a/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopSearchField.java +++ b/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopSearchField.java @@ -716,6 +716,33 @@ public class DesktopSearchField extends DesktopAbstractOptionsField return Collections.singleton(getValue()); } + @Override + public void commit() { + // do nothing + } + + @Override + public void discard() { + // do nothing + } + + @Override + public boolean isBuffered() { + // do nothing + return false; + } + + @Override + public void setBuffered(boolean buffered) { + // do nothing + } + + @Override + public boolean isModified() { + // do nothing + return false; + } + protected class NullOption extends EntityWrapper { public NullOption() { super(new AbstractNotPersistentEntity() { diff --git a/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopSuggestionPickerField.java b/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopSuggestionPickerField.java index 393fd43510..c358c5fcbd 100644 --- a/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopSuggestionPickerField.java +++ b/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopSuggestionPickerField.java @@ -174,6 +174,33 @@ public class DesktopSuggestionPickerField extends DesktopSuggestionField impleme return Collections.singleton(getValue()); } + @Override + public void commit() { + // do nothing + } + + @Override + public void discard() { + // do nothing + } + + @Override + public boolean isBuffered() { + // do nothing + return false; + } + + @Override + public void setBuffered(boolean buffered) { + // do nothing + } + + @Override + public boolean isModified() { + // do nothing + return false; + } + private class Picker extends com.haulmont.cuba.desktop.sys.vcl.Picker { @Override protected void initEditor() { diff --git a/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopTextArea.java b/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopTextArea.java index 16fd555885..6357a3355f 100644 --- a/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopTextArea.java +++ b/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopTextArea.java @@ -280,6 +280,33 @@ public class DesktopTextArea extends DesktopAbstractTextField impleme this.textChangeEventMode = mode; } + @Override + public void commit() { + // do nothing + } + + @Override + public void discard() { + // do nothing + } + + @Override + public boolean isBuffered() { + // do nothing + return false; + } + + @Override + public void setBuffered(boolean buffered) { + // do nothing + } + + @Override + public boolean isModified() { + // do nothing + return false; + } + protected class TextAreaFlushableField extends JTextArea implements Flushable { @Override diff --git a/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopTextField.java b/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopTextField.java index 27f4b2fc9f..b20a3426c4 100644 --- a/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopTextField.java +++ b/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopTextField.java @@ -241,6 +241,33 @@ public class DesktopTextField extends DesktopAbstractTextField i enterPressListeners.remove(listener); } + @Override + public void commit() { + // do nothing + } + + @Override + public void discard() { + // do nothing + } + + @Override + public boolean isBuffered() { + // do nothing + return false; + } + + @Override + public void setBuffered(boolean buffered) { + // do nothing + } + + @Override + public boolean isModified() { + // do nothing + return false; + } + protected class FlushableTextField extends JTextField implements Flushable { @Override diff --git a/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopTimeField.java b/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopTimeField.java index 2b5eb01802..131a17a2f5 100644 --- a/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopTimeField.java +++ b/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopTimeField.java @@ -386,6 +386,33 @@ public class DesktopTimeField extends DesktopAbstractField return timeFormat.contains("a"); } + @Override + public void commit() { + // do nothing + } + + @Override + public void discard() { + // do nothing + } + + @Override + public boolean isBuffered() { + // do nothing + return false; + } + + @Override + public void setBuffered(boolean buffered) { + // do nothing + } + + @Override + public boolean isModified() { + // do nothing + return false; + } + protected class FieldListener implements FocusListener, KeyListener { private static final int ENTER_CODE = 10; diff --git a/modules/gui/src/com/haulmont/cuba/gui/components/CheckBox.java b/modules/gui/src/com/haulmont/cuba/gui/components/CheckBox.java index 9256e77b5b..ae86507e66 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/components/CheckBox.java +++ b/modules/gui/src/com/haulmont/cuba/gui/components/CheckBox.java @@ -16,7 +16,7 @@ */ package com.haulmont.cuba.gui.components; -public interface CheckBox extends Field, Component.Focusable { +public interface CheckBox extends Field, Component.Buffered, Component.Focusable { String NAME = "checkBox"; @SuppressWarnings("unchecked") diff --git a/modules/gui/src/com/haulmont/cuba/gui/components/Component.java b/modules/gui/src/com/haulmont/cuba/gui/components/Component.java index e1babbbf74..af72a62aa3 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/components/Component.java +++ b/modules/gui/src/com/haulmont/cuba/gui/components/Component.java @@ -691,6 +691,47 @@ public interface Component { void validate() throws ValidationException; } + interface Buffered { + /** + * Updates all changes since the previous commit to the data source. + */ + void commit(); + + /** + * Discards all changes since last commit. The object updates its value from the data source. + */ + void discard(); + + /** + * @return {@code true} if buffered mode is on, {@code false} otherwise + */ + boolean isBuffered(); + + /** + * Sets the buffered mode. + *

+ * When in buffered mode, an internal buffer will be used to store changes + * until {@link #commit()} is called. Calling {@link #discard()} will revert + * the internal buffer to the value of the data source. + *

+ * When in non-buffered mode both read and write operations will be done + * directly on the data source. In this mode the {@link #commit()} and + * {@link #discard()} methods serve no purpose. + * + * @param buffered {@code true} if buffered mode should be turned on, {@code false} otherwise + */ + void setBuffered(boolean buffered); + + /** + * Tests if the value stored in the object has been modified since it was + * last updated from the data source. + * + * @return {@code true} if the value in the object has been modified + * since the last data source update, {@code false} if not. + */ + boolean isModified(); + } + interface HasPresentations extends HasSettings { void usePresentations(boolean b); boolean isUsePresentations(); diff --git a/modules/gui/src/com/haulmont/cuba/gui/components/DateField.java b/modules/gui/src/com/haulmont/cuba/gui/components/DateField.java index b5cfb207c8..7502c586ba 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/components/DateField.java +++ b/modules/gui/src/com/haulmont/cuba/gui/components/DateField.java @@ -19,7 +19,7 @@ package com.haulmont.cuba.gui.components; import java.util.Date; import java.util.TimeZone; -public interface DateField extends Field, Component.Focusable { +public interface DateField extends Field, Component.Buffered, Component.Focusable { String NAME = "dateField"; enum Resolution { diff --git a/modules/gui/src/com/haulmont/cuba/gui/components/LookupField.java b/modules/gui/src/com/haulmont/cuba/gui/components/LookupField.java index 821022d6d5..5a6fd481a1 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/components/LookupField.java +++ b/modules/gui/src/com/haulmont/cuba/gui/components/LookupField.java @@ -17,7 +17,7 @@ package com.haulmont.cuba.gui.components; -public interface LookupField extends OptionsField, Component.HasInputPrompt, LookupComponent, Component.Focusable { +public interface LookupField extends OptionsField, Component.HasInputPrompt, Component.Buffered, LookupComponent, Component.Focusable { String NAME = "lookupField"; diff --git a/modules/gui/src/com/haulmont/cuba/gui/components/PickerField.java b/modules/gui/src/com/haulmont/cuba/gui/components/PickerField.java index eb9c407e44..07aa7436fe 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/components/PickerField.java +++ b/modules/gui/src/com/haulmont/cuba/gui/components/PickerField.java @@ -54,7 +54,7 @@ import java.util.Map; * * @see LookupPickerField */ -public interface PickerField extends Field, Component.ActionsHolder, LookupComponent, Component.Focusable { +public interface PickerField extends Field, Component.ActionsHolder, Component.Buffered, LookupComponent, Component.Focusable { String NAME = "pickerField"; diff --git a/modules/gui/src/com/haulmont/cuba/gui/components/TextInputField.java b/modules/gui/src/com/haulmont/cuba/gui/components/TextInputField.java index d366a79160..8aaed664bc 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/components/TextInputField.java +++ b/modules/gui/src/com/haulmont/cuba/gui/components/TextInputField.java @@ -19,7 +19,7 @@ package com.haulmont.cuba.gui.components; import java.util.EventObject; -public interface TextInputField extends Field, Component.Focusable { +public interface TextInputField extends Field, Component.Buffered, Component.Focusable { /** * Defines case conversion for text input fields, diff --git a/modules/gui/src/com/haulmont/cuba/gui/components/TimeField.java b/modules/gui/src/com/haulmont/cuba/gui/components/TimeField.java index 6e2a8ce00f..1fff25c325 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/components/TimeField.java +++ b/modules/gui/src/com/haulmont/cuba/gui/components/TimeField.java @@ -18,7 +18,7 @@ package com.haulmont.cuba.gui.components; import java.util.Date; -public interface TimeField extends Field, Component.Focusable { +public interface TimeField extends Field, Component.Buffered, Component.Focusable { String NAME = "timeField"; boolean getShowSeconds(); diff --git a/modules/gui/src/com/haulmont/cuba/gui/window.xsd b/modules/gui/src/com/haulmont/cuba/gui/window.xsd index 13b80e605f..a0e9d56ff4 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/window.xsd +++ b/modules/gui/src/com/haulmont/cuba/gui/window.xsd @@ -783,6 +783,10 @@ + + + + @@ -998,6 +1002,7 @@ + @@ -1095,6 +1100,7 @@ + @@ -1117,6 +1123,7 @@ + @@ -1152,6 +1159,8 @@ + + @@ -1161,6 +1170,8 @@ + + @@ -1168,7 +1179,9 @@ - + + + @@ -1187,6 +1200,7 @@ + @@ -1228,6 +1242,7 @@ + @@ -1250,6 +1265,8 @@ + + @@ -1277,6 +1294,7 @@ + @@ -1330,6 +1348,7 @@ + @@ -1350,6 +1369,7 @@ + @@ -1373,6 +1393,7 @@ + @@ -1771,7 +1792,7 @@ - + diff --git a/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/AbstractFieldLoader.java b/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/AbstractFieldLoader.java index b1196dbae6..5c0ece2cf5 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/AbstractFieldLoader.java +++ b/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/AbstractFieldLoader.java @@ -18,6 +18,7 @@ package com.haulmont.cuba.gui.xml.layout.loaders; import com.haulmont.chile.core.model.MetaProperty; import com.haulmont.chile.core.model.MetaPropertyPath; +import com.haulmont.cuba.gui.components.Component; import com.haulmont.cuba.gui.components.Field; import org.apache.commons.lang.StringUtils; import org.dom4j.Element; @@ -87,4 +88,11 @@ public abstract class AbstractFieldLoader extends AbstractDatas } } } + + protected void loadBuffered(Component.Buffered component, Element element) { + String buffered = element.attributeValue("buffered"); + if (StringUtils.isNotEmpty(buffered)) { + component.setBuffered(Boolean.parseBoolean(buffered)); + } + } } \ No newline at end of file diff --git a/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/AbstractTextFieldLoader.java b/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/AbstractTextFieldLoader.java index f3e9ee55dd..da02d0cf28 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/AbstractTextFieldLoader.java +++ b/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/AbstractTextFieldLoader.java @@ -26,6 +26,7 @@ public abstract class AbstractTextFieldLoader extends public void loadComponent() { super.loadComponent(); + loadBuffered(resultComponent, element); loadTabIndex(resultComponent, element); } diff --git a/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/CheckBoxLoader.java b/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/CheckBoxLoader.java index 30850f09f8..30ecc04af7 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/CheckBoxLoader.java +++ b/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/CheckBoxLoader.java @@ -25,4 +25,11 @@ public class CheckBoxLoader extends AbstractFieldLoader { resultComponent = (CheckBox) factory.createComponent(CheckBox.NAME); loadId(resultComponent, element); } + + @Override + public void loadComponent() { + super.loadComponent(); + + loadBuffered(resultComponent, element); + } } \ No newline at end of file diff --git a/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/DateFieldLoader.java b/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/DateFieldLoader.java index fe68c44ff5..bd8fb8bb77 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/DateFieldLoader.java +++ b/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/DateFieldLoader.java @@ -92,6 +92,8 @@ public class DateFieldLoader extends AbstractFieldLoader { } resultComponent.setDateFormat(formatStr); + loadBuffered(resultComponent, element); + loadRangeStart(resultComponent, element); loadRangeEnd(resultComponent, element); } diff --git a/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/LookupFieldLoader.java b/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/LookupFieldLoader.java index 330c65326e..bb2e128dd3 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/LookupFieldLoader.java +++ b/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/LookupFieldLoader.java @@ -61,6 +61,8 @@ public class LookupFieldLoader extends AbstractFieldLoader { resultComponent.setPageLength(Integer.parseInt(pageLength)); } + loadBuffered(resultComponent, element); + loadTextInputAllowed(); loadInputPrompt(resultComponent, element); diff --git a/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/PickerFieldLoader.java b/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/PickerFieldLoader.java index ab234eacc1..e32f02d81f 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/PickerFieldLoader.java +++ b/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/PickerFieldLoader.java @@ -59,6 +59,8 @@ public class PickerFieldLoader extends AbstractFieldLoader { resultComponent.addClearAction(); } } + + loadBuffered(resultComponent, element); } @Override diff --git a/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/TimeFieldLoader.java b/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/TimeFieldLoader.java index 6120babaed..d277375dfd 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/TimeFieldLoader.java +++ b/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/TimeFieldLoader.java @@ -43,6 +43,8 @@ public class TimeFieldLoader extends AbstractFieldLoader { if (StringUtils.isNotEmpty(showSeconds)) { resultComponent.setShowSeconds(Boolean.parseBoolean(showSeconds)); } + + loadBuffered(resultComponent, element); } @Override diff --git a/modules/web/src/com/haulmont/cuba/web/gui/components/WebAbstractField.java b/modules/web/src/com/haulmont/cuba/web/gui/components/WebAbstractField.java index d14856dd3f..d9e9795ad1 100644 --- a/modules/web/src/com/haulmont/cuba/web/gui/components/WebAbstractField.java +++ b/modules/web/src/com/haulmont/cuba/web/gui/components/WebAbstractField.java @@ -386,6 +386,26 @@ public abstract class WebAbstractField } } + protected void commit() { + component.commit(); + } + + protected void discard() { + component.discard(); + } + + protected boolean isBuffered() { + return component.isBuffered(); + } + + protected void setBuffered(boolean buffered) { + component.setBuffered(buffered); + } + + protected boolean isModified() { + return component.isModified(); + } + protected boolean isEmpty(Object value) { return value == null; } diff --git a/modules/web/src/com/haulmont/cuba/web/gui/components/WebAbstractTextField.java b/modules/web/src/com/haulmont/cuba/web/gui/components/WebAbstractTextField.java index 67d4396668..7bf854fc6d 100644 --- a/modules/web/src/com/haulmont/cuba/web/gui/components/WebAbstractTextField.java +++ b/modules/web/src/com/haulmont/cuba/web/gui/components/WebAbstractTextField.java @@ -206,6 +206,31 @@ public abstract class WebAbstractTextField component.setTabIndex(tabIndex); } + @Override + public void commit() { + super.commit(); + } + + @Override + public void discard() { + super.discard(); + } + + @Override + public boolean isBuffered() { + return super.isBuffered(); + } + + @Override + public void setBuffered(boolean buffered) { + super.setBuffered(buffered); + } + + @Override + public boolean isModified() { + return super.isModified(); + } + protected class TextFieldStringToDatatypeConverter extends StringToDatatypeConverter { public TextFieldStringToDatatypeConverter(Datatype datatype) { super(datatype); diff --git a/modules/web/src/com/haulmont/cuba/web/gui/components/WebCheckBox.java b/modules/web/src/com/haulmont/cuba/web/gui/components/WebCheckBox.java index 60b0428025..af59fff6a3 100644 --- a/modules/web/src/com/haulmont/cuba/web/gui/components/WebCheckBox.java +++ b/modules/web/src/com/haulmont/cuba/web/gui/components/WebCheckBox.java @@ -99,4 +99,29 @@ public class WebCheckBox extends WebAbstractField implem ((CubaCheckBox) component).setCaptionManagedByLayout(true); } } + + @Override + public void commit() { + super.commit(); + } + + @Override + public void discard() { + super.discard(); + } + + @Override + public boolean isBuffered() { + return super.isBuffered(); + } + + @Override + public void setBuffered(boolean buffered) { + super.setBuffered(buffered); + } + + @Override + public boolean isModified() { + return super.isModified(); + } } \ No newline at end of file diff --git a/modules/web/src/com/haulmont/cuba/web/gui/components/WebDateField.java b/modules/web/src/com/haulmont/cuba/web/gui/components/WebDateField.java index a40189754c..5b08a95d1f 100644 --- a/modules/web/src/com/haulmont/cuba/web/gui/components/WebDateField.java +++ b/modules/web/src/com/haulmont/cuba/web/gui/components/WebDateField.java @@ -75,6 +75,8 @@ public class WebDateField extends WebAbstractField impleme protected Datasource.ItemChangeListener itemChangeListener; protected WeakItemChangeListener weakItemChangeListener; + protected boolean buffered = false; + public WebDateField() { innerLayout = new com.vaadin.ui.CssLayout(); innerLayout.setPrimaryStyleName("c-datefield-layout"); @@ -300,6 +302,58 @@ public class WebDateField extends WebAbstractField impleme updateInstance(); } + @Override + public void commit() { + if (updatingInstance) { + return; + } + + updatingInstance = true; + try { + if (datasource != null && metaPropertyPath != null) { + Date value = constructDate(); + + if (datasource.getItem() != null) { + InstanceUtils.setValueEx(datasource.getItem(), metaPropertyPath.getPath(), value); + setModified(false); + } + } + } finally { + updatingInstance = false; + } + + Object newValue = getValue(); + fireValueChanged(newValue); + } + + @Override + public void discard() { + if (datasource != null && datasource.getItem() != null) { + Date value = getEntityValue(datasource.getItem()); + setValueToFields(toUserDate(value)); + fireValueChanged(value); + } + } + + @Override + public boolean isBuffered() { + return buffered; + } + + @Override + public void setBuffered(boolean buffered) { + this.buffered = buffered; + } + + @Override + public boolean isModified() { + return dateField.isModified(); + } + + protected void setModified(boolean modified) { + dateField.setModified(modified); + } + protected Date toUserDate(Date date) { return timeZone == null ? date : timeZones.convert(date, TimeZone.getDefault(), timeZone); } @@ -358,8 +412,13 @@ public class WebDateField extends WebAbstractField impleme if (datasource != null && metaPropertyPath != null) { Date value = constructDate(); - if (datasource.getItem() != null) { - InstanceUtils.setValueEx(datasource.getItem(), metaPropertyPath.getPath(), value); + if (!isBuffered()) { + if (datasource.getItem() != null) { + InstanceUtils.setValueEx(datasource.getItem(), metaPropertyPath.getPath(), value); + setModified(false); + } + } else { + setModified(true); } } } finally { @@ -436,7 +495,7 @@ public class WebDateField extends WebAbstractField impleme if (updatingInstance) { return; } - if (e.getProperty().equals(metaPropertyPath.toString())) { + if (!isBuffered() && e.getProperty().equals(metaPropertyPath.toString())) { setValueToFields(toUserDate((Date) e.getValue())); fireValueChanged(e.getValue()); } diff --git a/modules/web/src/com/haulmont/cuba/web/gui/components/WebLookupField.java b/modules/web/src/com/haulmont/cuba/web/gui/components/WebLookupField.java index fc78222c84..f86281f489 100644 --- a/modules/web/src/com/haulmont/cuba/web/gui/components/WebLookupField.java +++ b/modules/web/src/com/haulmont/cuba/web/gui/components/WebLookupField.java @@ -464,6 +464,31 @@ public class WebLookupField extends WebAbstractOptionsField implem return Collections.singleton(getValue()); } + @Override + public void commit() { + super.commit(); + } + + @Override + public void discard() { + super.discard(); + } + + @Override + public boolean isBuffered() { + return super.isBuffered(); + } + + @Override + public void setBuffered(boolean buffered) { + super.setBuffered(buffered); + } + + @Override + public boolean isModified() { + return super.isModified(); + } + protected interface LookupFieldDsWrapper { void forceItemSetNotification(); } diff --git a/modules/web/src/com/haulmont/cuba/web/gui/components/WebLookupPickerField.java b/modules/web/src/com/haulmont/cuba/web/gui/components/WebLookupPickerField.java index 328b0ffdd4..0f3eef6e14 100644 --- a/modules/web/src/com/haulmont/cuba/web/gui/components/WebLookupPickerField.java +++ b/modules/web/src/com/haulmont/cuba/web/gui/components/WebLookupPickerField.java @@ -244,6 +244,34 @@ public class WebLookupPickerField extends WebLookupField implements LookupPicker } } + @Override + public void commit() { + super.commit(); + pickerField.commit(); + } + + @Override + public void discard() { + super.discard(); + pickerField.discard(); + } + + @Override + public boolean isBuffered() { + return pickerField.isBuffered(); + } + + @Override + public void setBuffered(boolean buffered) { + super.setBuffered(buffered); + pickerField.setBuffered(buffered); + } + + @Override + public boolean isModified() { + return pickerField.isModified(); + } + @Override protected void setEditableToComponent(boolean editable) { super.setEditableToComponent(editable); diff --git a/modules/web/src/com/haulmont/cuba/web/gui/components/WebPickerField.java b/modules/web/src/com/haulmont/cuba/web/gui/components/WebPickerField.java index 9fd75230d8..bb755de242 100644 --- a/modules/web/src/com/haulmont/cuba/web/gui/components/WebPickerField.java +++ b/modules/web/src/com/haulmont/cuba/web/gui/components/WebPickerField.java @@ -232,7 +232,7 @@ public class WebPickerField extends WebAbstractField datasource.addItemChangeListener(weakItemChangeListener); itemPropertyChangeListener = e -> { - if (e.getProperty().equals(metaPropertyPath.toString())) { + if (!isBuffered() && e.getProperty().equals(metaPropertyPath.toString())) { setValue(e.getValue()); } }; @@ -443,6 +443,32 @@ public class WebPickerField extends WebAbstractField component.getField().setTabIndex(tabIndex); } + @Override + public void commit() { + super.commit(); + } + + @Override + public void discard() { + super.discard(); + } + + @Override + public boolean isBuffered() { + return super.isBuffered(); + } + + @Override + public void setBuffered(boolean buffered) { + super.setBuffered(buffered); + } + + @Override + public boolean isModified() { + return super.isModified(); + } + + protected class PickerButton extends WebButton { public PickerButton() { } diff --git a/modules/web/src/com/haulmont/cuba/web/gui/components/WebRichTextArea.java b/modules/web/src/com/haulmont/cuba/web/gui/components/WebRichTextArea.java index 0df5d780cc..7caa8d69e4 100644 --- a/modules/web/src/com/haulmont/cuba/web/gui/components/WebRichTextArea.java +++ b/modules/web/src/com/haulmont/cuba/web/gui/components/WebRichTextArea.java @@ -98,4 +98,29 @@ public class WebRichTextArea extends WebAbstractField implemen public void setTabIndex(int tabIndex) { component.setTabIndex(tabIndex); } + + @Override + public void commit() { + super.commit(); + } + + @Override + public void discard() { + super.discard(); + } + + @Override + public boolean isBuffered() { + return super.isBuffered(); + } + + @Override + public void setBuffered(boolean buffered) { + super.setBuffered(buffered); + } + + @Override + public boolean isModified() { + return super.isModified(); + } } \ No newline at end of file diff --git a/modules/web/src/com/haulmont/cuba/web/gui/components/WebSearchPickerField.java b/modules/web/src/com/haulmont/cuba/web/gui/components/WebSearchPickerField.java index fe4bc754b7..7b2ef1a225 100644 --- a/modules/web/src/com/haulmont/cuba/web/gui/components/WebSearchPickerField.java +++ b/modules/web/src/com/haulmont/cuba/web/gui/components/WebSearchPickerField.java @@ -226,6 +226,34 @@ public class WebSearchPickerField extends WebSearchField implements SearchPicker } } + @Override + public void commit() { + super.commit(); + pickerField.commit(); + } + + @Override + public void discard() { + super.discard(); + pickerField.discard(); + } + + @Override + public boolean isBuffered() { + return pickerField.isBuffered(); + } + + @Override + public void setBuffered(boolean buffered) { + super.setBuffered(buffered); + pickerField.setBuffered(buffered); + } + + @Override + public boolean isModified() { + return pickerField.isModified(); + } + @Override protected void setEditableToComponent(boolean editable) { super.setEditableToComponent(editable); diff --git a/modules/web/src/com/haulmont/cuba/web/gui/components/WebSuggestionField.java b/modules/web/src/com/haulmont/cuba/web/gui/components/WebSuggestionField.java index d38311de05..154378f20f 100644 --- a/modules/web/src/com/haulmont/cuba/web/gui/components/WebSuggestionField.java +++ b/modules/web/src/com/haulmont/cuba/web/gui/components/WebSuggestionField.java @@ -300,4 +300,29 @@ public class WebSuggestionField extends WebAbstractField im public void setTabIndex(int tabIndex) { component.setTabIndex(tabIndex); } + + @Override + public void commit() { + throw new UnsupportedOperationException(); + } + + @Override + public void discard() { + throw new UnsupportedOperationException(); + } + + @Override + public boolean isBuffered() { + return false; + } + + @Override + public void setBuffered(boolean buffered) { + throw new UnsupportedOperationException("Buffered mode isn't supported"); + } + + @Override + public boolean isModified() { + throw new UnsupportedOperationException(); + } } \ No newline at end of file diff --git a/modules/web/src/com/haulmont/cuba/web/gui/components/WebSuggestionPickerField.java b/modules/web/src/com/haulmont/cuba/web/gui/components/WebSuggestionPickerField.java index 2783b8be55..082e0fd9b6 100644 --- a/modules/web/src/com/haulmont/cuba/web/gui/components/WebSuggestionPickerField.java +++ b/modules/web/src/com/haulmont/cuba/web/gui/components/WebSuggestionPickerField.java @@ -251,4 +251,29 @@ public class WebSuggestionPickerField extends WebSuggestionField implements Sugg public Collection getLookupSelectedItems() { return Collections.singleton(getValue()); } + + @Override + public void commit() { + throw new UnsupportedOperationException(); + } + + @Override + public void discard() { + throw new UnsupportedOperationException(); + } + + @Override + public boolean isBuffered() { + return false; + } + + @Override + public void setBuffered(boolean buffered) { + throw new UnsupportedOperationException("Buffered mode isn't supported"); + } + + @Override + public boolean isModified() { + throw new UnsupportedOperationException(); + } } diff --git a/modules/web/src/com/haulmont/cuba/web/gui/components/WebTimeField.java b/modules/web/src/com/haulmont/cuba/web/gui/components/WebTimeField.java index 2e5c0c2f55..68bfdc92b0 100644 --- a/modules/web/src/com/haulmont/cuba/web/gui/components/WebTimeField.java +++ b/modules/web/src/com/haulmont/cuba/web/gui/components/WebTimeField.java @@ -322,4 +322,29 @@ public class WebTimeField extends WebAbstractField implemen public void setTabIndex(int tabIndex) { component.setTabIndex(tabIndex); } + + @Override + public void commit() { + super.commit(); + } + + @Override + public void discard() { + super.discard(); + } + + @Override + public boolean isBuffered() { + return super.isBuffered(); + } + + @Override + public void setBuffered(boolean buffered) { + super.setBuffered(buffered); + } + + @Override + public boolean isModified() { + return super.isModified(); + } } \ No newline at end of file diff --git a/modules/web/src/com/haulmont/cuba/web/toolkit/ui/CubaDateField.java b/modules/web/src/com/haulmont/cuba/web/toolkit/ui/CubaDateField.java index 3de58c3c93..418a0d432b 100644 --- a/modules/web/src/com/haulmont/cuba/web/toolkit/ui/CubaDateField.java +++ b/modules/web/src/com/haulmont/cuba/web/toolkit/ui/CubaDateField.java @@ -59,6 +59,12 @@ public class CubaDateField extends com.vaadin.ui.DateField implements Action.Con return (CubaDateFieldState) super.getState(markAsDirty); } + public void setModified(boolean modified) { + if (getState(false).modified != modified) { + getState().modified = modified; + } + } + @Override protected void setValue(Date newValue, boolean repaintIsNotNeeded) throws Converter.ConversionException { if (newValue == MARKER_DATE)