mirror of
https://gitee.com/jmix/cuba.git
synced 2024-11-29 17:57:38 +08:00
Save UI component settings only if users change them #753
This commit is contained in:
parent
f494f7a569
commit
5ed8a499fb
@ -39,13 +39,15 @@ public interface Collapsable extends Component {
|
||||
@Deprecated
|
||||
void removeExpandedStateChangeListener(Consumer<ExpandedStateChangeEvent> listener);
|
||||
|
||||
class ExpandedStateChangeEvent {
|
||||
class ExpandedStateChangeEvent implements HasUserOriginated {
|
||||
private final Collapsable component;
|
||||
private final boolean expanded;
|
||||
private final boolean userOriginated;
|
||||
|
||||
public ExpandedStateChangeEvent(Collapsable component, boolean expanded) {
|
||||
public ExpandedStateChangeEvent(Collapsable component, boolean expanded, boolean userOriginated) {
|
||||
this.component = component;
|
||||
this.expanded = expanded;
|
||||
this.userOriginated = userOriginated;
|
||||
}
|
||||
|
||||
public Collapsable getComponent() {
|
||||
@ -58,5 +60,10 @@ public interface Collapsable extends Component {
|
||||
public boolean isExpanded() {
|
||||
return expanded;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUserOriginated() {
|
||||
return userOriginated;
|
||||
}
|
||||
}
|
||||
}
|
@ -21,6 +21,7 @@ import com.haulmont.chile.core.model.MetaClass;
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.haulmont.cuba.gui.components.ComponentContainer;
|
||||
import com.haulmont.cuba.gui.components.Filter;
|
||||
import com.haulmont.cuba.gui.components.HasUserOriginated;
|
||||
import com.haulmont.cuba.gui.data.CollectionDatasource;
|
||||
import com.haulmont.cuba.gui.model.CollectionLoader;
|
||||
import com.haulmont.cuba.security.entity.FilterEntity;
|
||||
@ -145,13 +146,15 @@ public interface FilterDelegate {
|
||||
|
||||
void setCaptionChangedListener(Consumer<String> captionChangedListener);
|
||||
|
||||
class FDExpandedStateChangeEvent {
|
||||
class FDExpandedStateChangeEvent implements HasUserOriginated {
|
||||
private final FilterDelegate delegate;
|
||||
private final boolean expanded;
|
||||
private final boolean userOriginated;
|
||||
|
||||
public FDExpandedStateChangeEvent(FilterDelegate delegate, boolean expanded) {
|
||||
public FDExpandedStateChangeEvent(FilterDelegate delegate, boolean expanded, boolean userOriginated) {
|
||||
this.delegate = delegate;
|
||||
this.expanded = expanded;
|
||||
this.userOriginated = userOriginated;
|
||||
}
|
||||
|
||||
public FilterDelegate getComponent() {
|
||||
@ -164,6 +167,11 @@ public interface FilterDelegate {
|
||||
public boolean isExpanded() {
|
||||
return expanded;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUserOriginated() {
|
||||
return userOriginated;
|
||||
}
|
||||
}
|
||||
|
||||
void setExpandedStateChangeListener(Consumer<FDExpandedStateChangeEvent> listener);
|
||||
|
@ -171,6 +171,8 @@ public class FilterDelegateImpl implements FilterDelegate {
|
||||
protected int maxResults = -1;
|
||||
protected boolean useMaxResults;
|
||||
protected boolean textMaxResults;
|
||||
protected boolean maxResultValueChanged = false;
|
||||
protected boolean groupBoxExpandedChanged = false;
|
||||
protected Boolean manualApplyRequired;
|
||||
protected boolean folderActionsEnabled = true;
|
||||
protected boolean filtersLookupListenerEnabled = true;
|
||||
@ -233,7 +235,7 @@ public class FilterDelegateImpl implements FilterDelegate {
|
||||
protected void createLayout() {
|
||||
if (layout == null) {
|
||||
groupBoxLayout = componentsFactory.createComponent(GroupBoxLayout.class);
|
||||
groupBoxLayout.addExpandedStateChangeListener(e -> fireExpandStateChange());
|
||||
groupBoxLayout.addExpandedStateChangeListener(e -> fireExpandStateChange(e.isUserOriginated()));
|
||||
groupBoxLayout.setOrientation(GroupBoxLayout.Orientation.VERTICAL);
|
||||
groupBoxLayout.setWidth("100%");
|
||||
|
||||
@ -470,6 +472,7 @@ public class FilterDelegateImpl implements FilterDelegate {
|
||||
maxResultsLookupField.setStyleName("c-maxresults-select");
|
||||
|
||||
maxResultsField = textMaxResults ? maxResultsTextField : maxResultsLookupField;
|
||||
maxResultsField.addValueChangeListener(integerValueChangeEvent -> maxResultValueChanged = true);
|
||||
maxResultsLayout.add(maxResultsField);
|
||||
}
|
||||
|
||||
@ -1375,6 +1378,9 @@ public class FilterDelegateImpl implements FilterDelegate {
|
||||
setUseMaxResults(false);
|
||||
} else if (useMaxResults) {
|
||||
initMaxResults();
|
||||
|
||||
// set to false because it's initial value
|
||||
maxResultValueChanged = false;
|
||||
}
|
||||
|
||||
if (ftsSwitch != null && !isEntityAvailableForFts()) {
|
||||
@ -1401,6 +1407,9 @@ public class FilterDelegateImpl implements FilterDelegate {
|
||||
|
||||
if (useMaxResults) {
|
||||
initMaxResults();
|
||||
|
||||
// set to false because it's initial value
|
||||
maxResultValueChanged = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1781,6 +1790,9 @@ public class FilterDelegateImpl implements FilterDelegate {
|
||||
Integer maxResultsFromSettings = Integer.valueOf(maxResultsEl.getText());
|
||||
adapter.setMaxResults(maxResultsFromSettings);
|
||||
initMaxResults();
|
||||
|
||||
// set to false cause it's initial value from settings
|
||||
maxResultValueChanged = false;
|
||||
} catch (NumberFormatException ex) {
|
||||
log.error("Error on parsing maxResults setting value", ex);
|
||||
}
|
||||
@ -1831,31 +1843,32 @@ public class FilterDelegateImpl implements FilterDelegate {
|
||||
changed = true;
|
||||
}
|
||||
|
||||
Element groupBoxExpandedEl = element.element("groupBoxExpanded");
|
||||
if (groupBoxExpandedEl == null)
|
||||
groupBoxExpandedEl = element.addElement("groupBoxExpanded");
|
||||
if (groupBoxExpandedChanged) {
|
||||
Element groupBoxExpandedEl = element.element("groupBoxExpanded");
|
||||
if (groupBoxExpandedEl == null)
|
||||
groupBoxExpandedEl = element.addElement("groupBoxExpanded");
|
||||
|
||||
Boolean oldGroupBoxExpandedValue = Boolean.valueOf(groupBoxExpandedEl.getText());
|
||||
Boolean newGroupBoxExpandedValue = groupBoxLayout.isExpanded();
|
||||
if (!Objects.equals(oldGroupBoxExpandedValue, newGroupBoxExpandedValue)) {
|
||||
groupBoxExpandedEl.setText(newGroupBoxExpandedValue.toString());
|
||||
changed = true;
|
||||
Boolean oldGroupBoxExpandedValue =
|
||||
groupBoxExpandedEl.getText().isEmpty() ? true : Boolean.valueOf(groupBoxExpandedEl.getText());
|
||||
Boolean newGroupBoxExpandedValue = groupBoxLayout.isExpanded();
|
||||
if (!Objects.equals(oldGroupBoxExpandedValue, newGroupBoxExpandedValue)) {
|
||||
groupBoxExpandedEl.setText(newGroupBoxExpandedValue.toString());
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (isMaxResultsLayoutVisible()) {
|
||||
Element maxResultsEl = element.element("maxResults");
|
||||
if (maxResultsEl == null)
|
||||
maxResultsEl = element.addElement("maxResults");
|
||||
try {
|
||||
Integer oldMaxResultsValue = !Strings.isNullOrEmpty(maxResultsEl.getText()) ?
|
||||
Integer.valueOf(maxResultsEl.getText()) : null;
|
||||
if (maxResultValueChanged) {
|
||||
Element maxResultsEl = element.element("maxResults");
|
||||
if (maxResultsEl == null) {
|
||||
maxResultsEl = element.addElement("maxResults");
|
||||
}
|
||||
|
||||
Integer newMaxResultsValue = maxResultsField.getValue();
|
||||
if (newMaxResultsValue != null && !Objects.equals(oldMaxResultsValue, newMaxResultsValue)) {
|
||||
if (newMaxResultsValue != null) {
|
||||
maxResultsEl.setText(newMaxResultsValue.toString());
|
||||
changed = true;
|
||||
}
|
||||
} catch (NumberFormatException ex) {
|
||||
log.error("Error on parsing maxResults setting value", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2080,10 +2093,14 @@ public class FilterDelegateImpl implements FilterDelegate {
|
||||
expandedStateChangeListener = listener;
|
||||
}
|
||||
|
||||
protected void fireExpandStateChange() {
|
||||
protected void fireExpandStateChange(boolean userOriginated) {
|
||||
if (expandedStateChangeListener != null) {
|
||||
FDExpandedStateChangeEvent event = new FDExpandedStateChangeEvent(this, isExpanded());
|
||||
FDExpandedStateChangeEvent event = new FDExpandedStateChangeEvent(this, isExpanded(), userOriginated);
|
||||
expandedStateChangeListener.accept(event);
|
||||
|
||||
if (userOriginated) {
|
||||
groupBoxExpandedChanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ public class CubaGroupBox extends Panel implements ComponentContainer {
|
||||
public CubaGroupBox() {
|
||||
registerRpc((CubaGroupBoxServerRpc) expanded -> {
|
||||
if (getState().collapsable) {
|
||||
setExpanded(expanded);
|
||||
setExpanded(expanded, true);
|
||||
}
|
||||
});
|
||||
|
||||
@ -103,6 +103,10 @@ public class CubaGroupBox extends Panel implements ComponentContainer {
|
||||
}
|
||||
|
||||
public void setExpanded(boolean expanded) {
|
||||
setExpanded(expanded, false);
|
||||
}
|
||||
|
||||
public void setExpanded(boolean expanded, boolean invokedByUser) {
|
||||
if (expanded != getState(false).expanded) {
|
||||
getContent().setVisible(expanded);
|
||||
markAsDirtyRecursive();
|
||||
@ -110,7 +114,7 @@ public class CubaGroupBox extends Panel implements ComponentContainer {
|
||||
|
||||
getState().expanded = expanded;
|
||||
if (expandChangeHandler != null)
|
||||
expandChangeHandler.expandStateChanged(expanded);
|
||||
expandChangeHandler.expandStateChanged(expanded, invokedByUser);
|
||||
}
|
||||
|
||||
public boolean isCollapsable() {
|
||||
@ -182,7 +186,7 @@ public class CubaGroupBox extends Panel implements ComponentContainer {
|
||||
}
|
||||
|
||||
public interface ExpandChangeHandler {
|
||||
void expandStateChanged(boolean expanded);
|
||||
void expandStateChanged(boolean expanded, boolean invokedByUser);
|
||||
}
|
||||
|
||||
public void setShowAsPanel(boolean showAsPanel) {
|
||||
|
@ -82,6 +82,8 @@ import com.vaadin.ui.components.grid.Header;
|
||||
import com.vaadin.ui.components.grid.StaticSection;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.DocumentHelper;
|
||||
import org.dom4j.Element;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -155,6 +157,8 @@ public abstract class WebAbstractDataGrid<C extends Grid<E> & CubaEnhancedGrid<E
|
||||
protected Registration columnResizeListenerRegistration;
|
||||
protected Registration contextClickListenerRegistration;
|
||||
|
||||
protected Document defaultSettings;
|
||||
|
||||
// protected CubaGrid.EditorCloseListener editorCloseListener;
|
||||
// protected CubaGrid.BeforeEditorOpenListener beforeEditorOpenListener;
|
||||
// protected CubaGrid.EditorPreCommitListener editorPreCommitListener;
|
||||
@ -1956,6 +1960,13 @@ public abstract class WebAbstractDataGrid<C extends Grid<E> & CubaEnhancedGrid<E
|
||||
return;
|
||||
}
|
||||
|
||||
if (defaultSettings == null) {
|
||||
defaultSettings = DocumentHelper.createDocument();
|
||||
defaultSettings.setRootElement(defaultSettings.addElement("presentation"));
|
||||
// init default settings
|
||||
saveSettings(defaultSettings.getRootElement());
|
||||
}
|
||||
|
||||
Element columnsElem = element.element("columns");
|
||||
if (columnsElem != null) {
|
||||
List<Column<E>> modelColumns = getVisibleColumns();
|
||||
@ -2045,8 +2056,6 @@ public abstract class WebAbstractDataGrid<C extends Grid<E> & CubaEnhancedGrid<E
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean settingsChanged = false;
|
||||
|
||||
Element columnsElem = element.element("columns");
|
||||
|
||||
String sortColumnId = null;
|
||||
@ -2058,8 +2067,11 @@ public abstract class WebAbstractDataGrid<C extends Grid<E> & CubaEnhancedGrid<E
|
||||
}
|
||||
|
||||
boolean commonSettingsChanged = isCommonDataGridSettingsChanged(columnsElem);
|
||||
boolean sortChanged = isSortPropertySettingsChanged(sortColumnId, sortDirection);
|
||||
|
||||
if (commonSettingsChanged) {
|
||||
boolean settingsChanged = commonSettingsChanged || sortChanged;
|
||||
|
||||
if (settingsChanged) {
|
||||
if (columnsElem != null) {
|
||||
element.remove(columnsElem);
|
||||
}
|
||||
@ -2078,21 +2090,13 @@ public abstract class WebAbstractDataGrid<C extends Grid<E> & CubaEnhancedGrid<E
|
||||
colElem.addAttribute("collapsed", Boolean.toString(column.isCollapsed()));
|
||||
}
|
||||
|
||||
settingsChanged = true;
|
||||
}
|
||||
|
||||
if (isSortPropertySettingsChanged(sortColumnId, sortDirection) || commonSettingsChanged) {
|
||||
List<GridSortOrder<E>> sortOrders = component.getSortOrder();
|
||||
if (!sortOrders.isEmpty()) {
|
||||
GridSortOrder<E> sortOrder = sortOrders.get(0);
|
||||
|
||||
if (columnsElem != null) {
|
||||
columnsElem.addAttribute("sortColumnId", sortOrder.getSorted().getId());
|
||||
columnsElem.addAttribute("sortDirection", sortOrder.getDirection().toString());
|
||||
}
|
||||
columnsElem.addAttribute("sortColumnId", sortOrder.getSorted().getId());
|
||||
columnsElem.addAttribute("sortDirection", sortOrder.getDirection().toString());
|
||||
}
|
||||
|
||||
settingsChanged = true;
|
||||
}
|
||||
|
||||
return settingsChanged;
|
||||
@ -2100,7 +2104,7 @@ public abstract class WebAbstractDataGrid<C extends Grid<E> & CubaEnhancedGrid<E
|
||||
|
||||
protected boolean isCommonDataGridSettingsChanged(Element columnsElem) {
|
||||
if (columnsElem == null) {
|
||||
return true;
|
||||
return isDefaultDataGridSettingsChanged();
|
||||
}
|
||||
|
||||
List<Element> settingsColumnList = columnsElem.elements("columns");
|
||||
@ -2136,6 +2140,19 @@ public abstract class WebAbstractDataGrid<C extends Grid<E> & CubaEnhancedGrid<E
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean isDefaultDataGridSettingsChanged() {
|
||||
Element columnsElement = null;
|
||||
|
||||
if (defaultSettings != null) {
|
||||
columnsElement = defaultSettings.getRootElement().element("columns");
|
||||
if (columnsElement == null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return isCommonDataGridSettingsChanged(columnsElement);
|
||||
}
|
||||
|
||||
protected boolean isSortPropertySettingsChanged(String settingsSortColumnId, String settingsSortDirection) {
|
||||
List<GridSortOrder<E>> sortOrders = component.getSortOrder();
|
||||
|
||||
|
@ -1829,9 +1829,9 @@ public abstract class WebAbstractTable<T extends com.vaadin.v7.ui.Table & CubaEn
|
||||
boolean settingsChanged = false;
|
||||
|
||||
if (isUsePresentations()) {
|
||||
String textSelection = String.valueOf(component.isTextSelectionEnabled());
|
||||
if (!textSelection.equals(element.attributeValue("textSelection"))) {
|
||||
element.addAttribute("textSelection", textSelection);
|
||||
boolean textSelection = component.isTextSelectionEnabled();
|
||||
if (textSelection != Boolean.valueOf(element.attributeValue("textSelection"))) {
|
||||
element.addAttribute("textSelection", String.valueOf(textSelection));
|
||||
|
||||
settingsChanged = true;
|
||||
}
|
||||
@ -1848,49 +1848,57 @@ public abstract class WebAbstractTable<T extends com.vaadin.v7.ui.Table & CubaEn
|
||||
}
|
||||
|
||||
boolean commonSettingsChanged = isCommonTableSettingsChanged(columnsElem);
|
||||
boolean sortChanged = isSettingsSortPropertyChanged(settingsSortProperty, settingsSortAscending);
|
||||
|
||||
if (commonSettingsChanged) {
|
||||
if (commonSettingsChanged || sortChanged) {
|
||||
if (columnsElem != null) {
|
||||
element.remove(columnsElem);
|
||||
}
|
||||
columnsElem = element.addElement("columns");
|
||||
|
||||
Object[] visibleColumns = component.getVisibleColumns();
|
||||
for (Object column : visibleColumns) {
|
||||
Element colElem = columnsElem.addElement("columns");
|
||||
colElem.addAttribute("id", column.toString());
|
||||
saveCommonTableColumnSettings(columnsElem);
|
||||
|
||||
int width = component.getColumnWidth(column);
|
||||
if (width > -1)
|
||||
colElem.addAttribute("width", String.valueOf(width));
|
||||
MetaPropertyPath sortProperty = (MetaPropertyPath) component.getSortContainerPropertyId();
|
||||
boolean sortAscending = component.isSortAscending();
|
||||
|
||||
boolean visible = !component.isColumnCollapsed(column);
|
||||
colElem.addAttribute("visible", Boolean.toString(visible));
|
||||
}
|
||||
columnsElem.addAttribute("sortProperty", sortProperty == null ? "" : sortProperty.toString());
|
||||
columnsElem.addAttribute("sortAscending", Boolean.toString(sortAscending));
|
||||
|
||||
settingsChanged = true;
|
||||
}
|
||||
|
||||
if (isSettingsSortPropertyChanged(settingsSortProperty, settingsSortAscending) || commonSettingsChanged) {
|
||||
MetaPropertyPath sortProperty = (MetaPropertyPath) component.getSortContainerPropertyId();
|
||||
if (sortProperty != null) {
|
||||
boolean sortAscending = component.isSortAscending();
|
||||
|
||||
if (columnsElem != null) {
|
||||
columnsElem.addAttribute("sortProperty", sortProperty.toString());
|
||||
columnsElem.addAttribute("sortAscending", Boolean.toString(sortAscending));
|
||||
|
||||
settingsChanged = true;
|
||||
}
|
||||
}
|
||||
String settingsDefaultPresentation = Strings.nullToEmpty(element.attributeValue("presentation"));
|
||||
String defaultPresentation = getDefaultPresentationId() == null ? "" : String.valueOf(getDefaultPresentationId());
|
||||
if (!Objects.equals(settingsDefaultPresentation, defaultPresentation)) {
|
||||
settingsChanged = true;
|
||||
}
|
||||
|
||||
return settingsChanged;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves common table column settings (width, visible, id).
|
||||
*
|
||||
* @param columnsElem setting element for the columns
|
||||
*/
|
||||
protected void saveCommonTableColumnSettings(Element columnsElem) {
|
||||
Object[] visibleColumns = component.getVisibleColumns();
|
||||
for (Object column : visibleColumns) {
|
||||
Element colElem = columnsElem.addElement("columns");
|
||||
colElem.addAttribute("id", column.toString());
|
||||
|
||||
int width = component.getColumnWidth(column);
|
||||
if (width > -1)
|
||||
colElem.addAttribute("width", String.valueOf(width));
|
||||
|
||||
boolean visible = !component.isColumnCollapsed(column);
|
||||
colElem.addAttribute("visible", Boolean.toString(visible));
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isCommonTableSettingsChanged(Element columnsElem) {
|
||||
if (columnsElem == null) {
|
||||
return true;
|
||||
return isDefaultTableSettingsChanged();
|
||||
}
|
||||
|
||||
List<Element> settingsColumnList = columnsElem.elements("columns");
|
||||
@ -1926,11 +1934,23 @@ public abstract class WebAbstractTable<T extends com.vaadin.v7.ui.Table & CubaEn
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean isDefaultTableSettingsChanged() {
|
||||
Element columnsElement = null;
|
||||
|
||||
if (defaultSettings != null) {
|
||||
columnsElement = defaultSettings.getRootElement().element("columns");
|
||||
if (columnsElement == null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return isCommonTableSettingsChanged(columnsElement);
|
||||
}
|
||||
|
||||
protected boolean isSettingsSortPropertyChanged(String settingsSortProperty, String settingsSortAscending) {
|
||||
MetaPropertyPath sortProperty = (MetaPropertyPath) component.getSortContainerPropertyId();
|
||||
|
||||
if (settingsSortProperty == null && sortProperty == null) {
|
||||
return false;
|
||||
if (sortProperty == null) {
|
||||
return !Strings.isNullOrEmpty(settingsSortProperty);
|
||||
}
|
||||
|
||||
if (settingsSortProperty == null ||
|
||||
|
@ -59,7 +59,7 @@ public class WebFilter extends WebAbstractComponent<com.vaadin.ui.Component> imp
|
||||
component.setWidth(100, Sizeable.Unit.PERCENTAGE);
|
||||
component.addStyleName(FILTER_STYLENAME);
|
||||
|
||||
delegate.setExpandedStateChangeListener(e -> fireExpandStateChange(e.isExpanded()));
|
||||
delegate.setExpandedStateChangeListener(e -> fireExpandStateChange(e.isExpanded(), e.isUserOriginated()));
|
||||
delegate.setCaptionChangedListener(this::updateCaptions);
|
||||
}
|
||||
|
||||
@ -269,8 +269,8 @@ public class WebFilter extends WebAbstractComponent<com.vaadin.ui.Component> imp
|
||||
unsubscribe(ExpandedStateChangeEvent.class, listener);
|
||||
}
|
||||
|
||||
protected void fireExpandStateChange(boolean expanded) {
|
||||
ExpandedStateChangeEvent event = new ExpandedStateChangeEvent(this, expanded);
|
||||
protected void fireExpandStateChange(boolean expanded, boolean userOriginated) {
|
||||
ExpandedStateChangeEvent event = new ExpandedStateChangeEvent(this, expanded, userOriginated);
|
||||
publish(ExpandedStateChangeEvent.class, event);
|
||||
}
|
||||
|
||||
|
@ -45,6 +45,7 @@ public class WebGroupBox extends WebAbstractComponent<CubaGroupBox> implements G
|
||||
protected Orientation orientation = Orientation.VERTICAL;
|
||||
|
||||
protected boolean settingsEnabled = true;
|
||||
protected boolean settingsChanged = false;
|
||||
|
||||
protected Map<ShortcutAction, ShortcutListener> shortcuts;
|
||||
|
||||
@ -258,9 +259,13 @@ public class WebGroupBox extends WebAbstractComponent<CubaGroupBox> implements G
|
||||
unsubscribe(ExpandedStateChangeEvent.class, listener);
|
||||
}
|
||||
|
||||
protected void fireExpandStateChange(boolean expanded) {
|
||||
ExpandedStateChangeEvent event = new ExpandedStateChangeEvent(this, expanded);
|
||||
protected void fireExpandStateChange(boolean expanded, boolean invokedByUser) {
|
||||
ExpandedStateChangeEvent event = new ExpandedStateChangeEvent(this, expanded, invokedByUser);
|
||||
publish(ExpandedStateChangeEvent.class, event);
|
||||
|
||||
if (invokedByUser) {
|
||||
settingsChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -282,7 +287,7 @@ public class WebGroupBox extends WebAbstractComponent<CubaGroupBox> implements G
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isSettingsChanged(element)) {
|
||||
if (!settingsChanged) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -400,15 +405,4 @@ public class WebGroupBox extends WebAbstractComponent<CubaGroupBox> implements G
|
||||
return new com.haulmont.cuba.gui.components.MarginInfo(vMargin.hasTop(), vMargin.hasRight(), vMargin.hasBottom(),
|
||||
vMargin.hasLeft());
|
||||
}
|
||||
|
||||
protected boolean isSettingsChanged(Element element) {
|
||||
Element groupBoxElement = element.element("groupBox");
|
||||
|
||||
if (groupBoxElement == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String expanded = groupBoxElement.attributeValue("expanded"); // old value
|
||||
return isExpanded() != Boolean.parseBoolean(expanded);
|
||||
}
|
||||
}
|
@ -113,13 +113,20 @@ public class WebGroupTable<E extends Entity> extends WebAbstractTable<CubaGroupT
|
||||
}
|
||||
|
||||
boolean commonTableSettingsChanged = super.saveSettings(element);
|
||||
boolean groupTableSettingsChanged = isGroupTableSettingsChanged(element);
|
||||
boolean groupTableSettingsChanged = isGroupTableSettingsChanged(element.element("groupProperties"));
|
||||
|
||||
if (!groupTableSettingsChanged && !commonTableSettingsChanged) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (groupTableSettingsChanged) {
|
||||
|
||||
// add "column" if there is no such element
|
||||
if (element.element("columns") == null) {
|
||||
Element columnsElem = element.addElement("columns");
|
||||
saveCommonTableColumnSettings(columnsElem);
|
||||
}
|
||||
|
||||
Element groupPropertiesElement = element.element("groupProperties");
|
||||
if (groupPropertiesElement != null) {
|
||||
element.remove(groupPropertiesElement);
|
||||
@ -140,11 +147,9 @@ public class WebGroupTable<E extends Entity> extends WebAbstractTable<CubaGroupT
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean isGroupTableSettingsChanged(Element element) {
|
||||
Element groupPropertiesElement = element.element("groupProperties");
|
||||
|
||||
protected boolean isGroupTableSettingsChanged(Element groupPropertiesElement) {
|
||||
if (groupPropertiesElement == null) {
|
||||
return true;
|
||||
return isDefaultGroupTableSettingsChanged();
|
||||
}
|
||||
|
||||
List<Element> settingsProperties = groupPropertiesElement.elements("property");
|
||||
@ -173,6 +178,19 @@ public class WebGroupTable<E extends Entity> extends WebAbstractTable<CubaGroupT
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean isDefaultGroupTableSettingsChanged() {
|
||||
Element groupPropertiesElement = null;
|
||||
|
||||
if (defaultSettings != null) {
|
||||
groupPropertiesElement = defaultSettings.getRootElement().element("groupProperties");
|
||||
if (groupPropertiesElement == null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return isGroupTableSettingsChanged(groupPropertiesElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyColumnSettings(Element element) {
|
||||
super.applyColumnSettings(element);
|
||||
|
@ -34,6 +34,7 @@ public class WebResizableTextArea<V> extends WebAbstractTextArea<CubaTextArea, V
|
||||
|
||||
protected CubaResizableTextAreaWrapper wrapper;
|
||||
protected boolean settingsEnabled = true;
|
||||
protected boolean settingsChanged = false;
|
||||
|
||||
public WebResizableTextArea() {
|
||||
component = createTextFieldImpl();
|
||||
@ -43,6 +44,8 @@ public class WebResizableTextArea<V> extends WebAbstractTextArea<CubaTextArea, V
|
||||
wrapper.addResizeListener((oldWidth, oldHeight, width, height) -> {
|
||||
ResizeEvent e = new ResizeEvent(this, oldWidth, width, oldHeight, height);
|
||||
publish(ResizeEvent.class, e);
|
||||
|
||||
settingsChanged = true;
|
||||
});
|
||||
}
|
||||
|
||||
@ -146,7 +149,7 @@ public class WebResizableTextArea<V> extends WebAbstractTextArea<CubaTextArea, V
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isResizableTextAreaSettingsChanged(element)) {
|
||||
if (!settingsChanged) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -200,26 +203,4 @@ public class WebResizableTextArea<V> extends WebAbstractTextArea<CubaTextArea, V
|
||||
Preconditions.checkNotNullArgument(direction);
|
||||
wrapper.setResizableDirection(WebWrapperUtils.toVaadinResizeDirection(direction));
|
||||
}
|
||||
|
||||
protected boolean isResizableTextAreaSettingsChanged(Element element) {
|
||||
if (element == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String settingsWidth = element.attributeValue("width");
|
||||
String width = String.valueOf(getWidth()) + wrapper.getWidthUnits().toString();
|
||||
|
||||
if (!width.equals(settingsWidth)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String settingsHeight = element.attributeValue("height");
|
||||
String height = String.valueOf(getHeight()) + wrapper.getHeightUnits().toString();
|
||||
|
||||
if (!height.equals(settingsHeight)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -43,6 +43,7 @@ public class WebSplitPanel extends WebAbstractComponent<AbstractSplitPanel> impl
|
||||
|
||||
protected int orientation;
|
||||
protected boolean settingsEnabled = true;
|
||||
protected boolean settingsChanged = false;
|
||||
|
||||
protected float currentPosition = 0;
|
||||
protected boolean inverse = false;
|
||||
@ -109,6 +110,10 @@ public class WebSplitPanel extends WebAbstractComponent<AbstractSplitPanel> impl
|
||||
SplitPositionChangeEvent cubaEvent = new SplitPositionChangeEvent(this, currentPosition,
|
||||
event.getSplitPosition(), event.isUserOriginated());
|
||||
publish(SplitPositionChangeEvent.class, cubaEvent);
|
||||
|
||||
if (event.isUserOriginated()) {
|
||||
settingsChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -200,7 +205,7 @@ public class WebSplitPanel extends WebAbstractComponent<AbstractSplitPanel> impl
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isSplitPanelSettingsChanged(element)) {
|
||||
if (!settingsChanged) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -366,31 +371,4 @@ public class WebSplitPanel extends WebAbstractComponent<AbstractSplitPanel> impl
|
||||
public void removeSplitPositionChangeListener(Consumer<SplitPositionChangeEvent> listener) {
|
||||
unsubscribe(SplitPositionChangeEvent.class, listener);
|
||||
}
|
||||
|
||||
protected boolean isSplitPanelSettingsChanged(Element splitPanelElement) {
|
||||
if (splitPanelElement == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Element positionElement = splitPanelElement.element("position");
|
||||
if (positionElement == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String settingsUnit = positionElement.attributeValue("unit");
|
||||
String unit = String.valueOf(component.getSplitPositionUnit());
|
||||
|
||||
if (!unit.equals(settingsUnit)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String settingsValue = positionElement.attributeValue("value");
|
||||
String value = String.valueOf(component.getSplitPosition());
|
||||
|
||||
if (!value.equals(settingsValue)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user