Change behavior of Component isVisible / isEnabled methods #924

This commit is contained in:
Yuriy Artamonov 2018-04-12 15:22:44 +04:00
parent 4108054ac4
commit 336bab45f8
34 changed files with 126 additions and 113 deletions

View File

@ -83,8 +83,8 @@ public class ComponentCaption extends JPanel {
toolTipButton = null;
}
setVisible(owner.isVisible());
setEnabled(owner.isEnabled());
setVisible(owner.isVisibleRecursive());
setEnabled(owner.isEnabledRecursive());
}
protected void removeToolTipButtonActionListener() {

View File

@ -191,6 +191,11 @@ public abstract class DesktopAbstractComponent<C extends JComponent>
@Override
public boolean isEnabled() {
return this.enabled;
}
@Override
public boolean isEnabledRecursive() {
return DesktopComponentsHelper.isRecursivelyEnabled(getComposition());
}
@ -235,6 +240,11 @@ public abstract class DesktopAbstractComponent<C extends JComponent>
@Override
public boolean isVisible() {
return this.visible;
}
@Override
public boolean isVisibleRecursive() {
return DesktopComponentsHelper.isRecursivelyVisible(getComposition());
}
@ -255,16 +265,6 @@ public abstract class DesktopAbstractComponent<C extends JComponent>
}
}
@Override
public boolean isVisibleItself() {
return visible;
}
@Override
public boolean isEnabledItself() {
return enabled;
}
@Override
public void requestFocus() {
SwingUtilities.invokeLater(() ->

View File

@ -32,10 +32,8 @@ import com.haulmont.cuba.gui.components.Field;
import com.haulmont.cuba.gui.components.PropertyBoundComponent;
import com.haulmont.cuba.gui.components.RequiredValueMissingException;
import com.haulmont.cuba.gui.components.ValidationException;
import com.haulmont.cuba.gui.components.compatibility.ComponentValueListenerWrapper;
import com.haulmont.cuba.gui.components.validators.BeanValidator;
import com.haulmont.cuba.gui.data.Datasource;
import com.haulmont.cuba.gui.data.ValueListener;
import com.haulmont.cuba.gui.model.InstanceContainer;
import org.apache.commons.lang.StringUtils;
@ -125,7 +123,7 @@ public abstract class DesktopAbstractField<C extends JComponent> extends Desktop
@Override
public void validate() throws ValidationException {
if (!isVisible() || !isEditableWithParent() || !isEnabled())
if (!isVisibleRecursive() || !isEditableWithParent() || !isEnabledRecursive())
return;
Object value = getValue();

View File

@ -75,7 +75,7 @@ public abstract class DesktopAbstractTextField<T extends JTextComponent> extends
impl.setEnabled(enabled);
impl.setEditable(editable);
impl.setDocument(doc);
impl.setVisible(isVisible());
impl.setVisible(isVisibleRecursive());
TextFieldListener listener = createTextListener();
impl.addKeyListener(listener);
@ -341,7 +341,7 @@ public abstract class DesktopAbstractTextField<T extends JTextComponent> extends
}
protected void flush() {
if (isEditable() && isEnabled()) {
if (isEditable() && isEnabledRecursive()) {
Object newValue = validateRawValue(getImpl().getText());
if ("".equals(newValue))
newValue = null;

View File

@ -326,7 +326,7 @@ public class DesktopDateField extends DesktopAbstractField<JPanel> implements Da
@Override
public void validate() throws ValidationException {
if (!isVisible() || !isEditableWithParent() || !isEnabled())
if (!isVisibleRecursive() || !isEditableWithParent() || !isEnabledRecursive())
return;
try {
@ -669,7 +669,7 @@ public class DesktopDateField extends DesktopAbstractField<JPanel> implements Da
}
protected void flush() {
if (isEditable() && isEnabled()) {
if (isEditable() && isEnabledRecursive()) {
try {
datePicker.getEditor().commitEdit();
} catch (ParseException e) {

View File

@ -311,8 +311,8 @@ public class DesktopFieldGroup extends DesktopAbstractComponent<JPanel>
for (FieldConfig fc : getColumnOrderedFields()) {
Component component = fc.getComponent();
if (component != null
&& component.isEnabled()
&& component.isVisible()
&& component.isEnabledRecursive()
&& component.isVisibleRecursive()
&& component instanceof Focusable
&& ((Focusable) component).isFocusable()) {
@ -440,7 +440,7 @@ public class DesktopFieldGroup extends DesktopAbstractComponent<JPanel>
} else {
label.setPreferredSize(new Dimension(label.getPreferredSize().width, 25));
}
label.setVisible(fieldComponent.isVisible());
label.setVisible(fieldComponent.isVisibleRecursive());
CC labelCc = new CC();
MigLayoutHelper.applyAlignment(labelCc, Alignment.TOP_LEFT);
@ -886,7 +886,7 @@ public class DesktopFieldGroup extends DesktopAbstractComponent<JPanel>
@Override
public void validate() throws ValidationException {
if (!isVisible() || !isEditableWithParent() || !isEnabled()) {
if (!isVisibleRecursive() || !isEditableWithParent() || !isEnabledRecursive()) {
return;
}
@ -1007,7 +1007,7 @@ public class DesktopFieldGroup extends DesktopAbstractComponent<JPanel>
toolTipButton.setToolTipText(contextHelpText);
}
toolTipButton.setVisible(component.isVisible()
toolTipButton.setVisible(component.isVisibleRecursive()
&& (StringUtils.isNotEmpty(contextHelpText) || hasContextHelpIconClickListeners));
}
@ -1272,7 +1272,7 @@ public class DesktopFieldGroup extends DesktopAbstractComponent<JPanel>
@Override
public Boolean isVisible() {
if (component != null) {
return component.isVisible();
return component.isVisibleRecursive();
}
return targetVisible;
}

View File

@ -419,13 +419,13 @@ public class DesktopPopupButton extends DesktopAbstractActionsHolderComponent<JB
}
@Override
public boolean isVisibleItself() {
return DesktopPopupButton.this.isVisibleItself();
public boolean isVisibleRecursive() {
return DesktopPopupButton.this.isVisibleRecursive();
}
@Override
public boolean isEnabledItself() {
return action.isEnabled();
public boolean isEnabledRecursive() {
return DesktopPopupButton.this.isEnabledRecursive();
}
@Override

View File

@ -371,7 +371,7 @@ public class DesktopSuggestionField extends DesktopAbstractOptionsField<JCompone
}
protected void handleSearchResults(List<?> searchResultItems) {
if (isVisible() && isEnabled() && isEditable()) {
if (isVisibleRecursive() && isEnabledRecursive() && isEditable()) {
items.clear();
List<SearchObjectWrapper> wrappers = new ArrayList<>();
for (int i = 0; i < searchResultItems.size() && i < suggestionsLimit; i++) {

View File

@ -63,7 +63,7 @@ public class DesktopTextArea extends DesktopAbstractTextField<JTextArea> impleme
impl.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (isEnabled() && isEditable()
if (isEnabledRecursive() && isEditable()
&& e.getKeyCode() == KeyEvent.VK_TAB
&& e.getModifiers() == KeyEvent.CTRL_MASK) {

View File

@ -449,7 +449,7 @@ public class DesktopTimeField extends DesktopAbstractField<JFormattedTextField>
}
protected void flush() {
if (isEditable() && isEnabled()) {
if (isEditable() && isEnabledRecursive()) {
Object newValue;
try {
newValue = validateRawValue(getImpl().getText());

View File

@ -1224,16 +1224,6 @@ public class DesktopWindow implements Window, Component.Disposable,
throw new UnsupportedOperationException();
}
@Override
public boolean isVisibleItself() {
return true;
}
@Override
public boolean isEnabledItself() {
return panel.isEnabled();
}
@Override
public void requestFocus() {
}

View File

@ -536,7 +536,7 @@ public class DesktopWindowManager extends WindowManager {
if (focusComponentId != null) {
com.haulmont.cuba.gui.components.Component focusComponent = window.getComponent(focusComponentId);
if (focusComponent != null) {
if (focusComponent.isEnabled() && focusComponent.isVisible()) {
if (focusComponent.isEnabledRecursive() && focusComponent.isVisibleRecursive()) {
focusComponent.requestFocus();
focused = true;
}

View File

@ -114,7 +114,7 @@ public class AttributeAccessSupport {
}
}
if (component instanceof Field) {
if (componentState.required && ((Field) component).isEditable() && component.isVisible()) {
if (componentState.required && ((Field) component).isEditable() && component.isVisibleRecursive()) {
((Field) component).setRequired(true);
}
}

View File

@ -314,7 +314,7 @@ public class LayoutAnalyzer {
expanded.getId() : expanded.getClass().getSimpleName();
for (Component innerComponent : components) {
if (innerComponent != expanded
&& innerComponent.isVisible()
&& innerComponent.isVisibleRecursive()
&& isSizeIgnored(container, innerComponent)) {
String id = innerComponent.getId() != null ?
innerComponent.getId() : innerComponent.getClass().getSimpleName();

View File

@ -286,10 +286,10 @@ public class AttributePermissionsFrame extends AbstractFrame {
attributeTargetsDs.addItemChangeListener(e -> {
MultiplePermissionTarget item = e.getItem();
boolean itemExists = item != null;
if (!selectedEntityPanel.isVisible() && itemExists) {
if (!selectedEntityPanel.isVisibleRecursive() && itemExists) {
selectedEntityPanel.setVisible(true);
}
if (selectedEntityPanel.isVisible() && (item == null)) {
if (selectedEntityPanel.isVisibleRecursive() && (item == null)) {
selectedEntityPanel.setVisible(false);
}

View File

@ -204,10 +204,10 @@ public class EntityPermissionsFrame extends AbstractFrame {
entityFilter.addEnterPressListener(e -> applyFilter());
entityTargetsDs.addItemChangeListener(e -> {
if (!selectedEntityPanel.isVisible() && (e.getItem() != null)) {
if (!selectedEntityPanel.isVisibleRecursive() && (e.getItem() != null)) {
selectedEntityPanel.setVisible(true);
}
if (selectedEntityPanel.isVisible() && (e.getItem() == null)) {
if (selectedEntityPanel.isVisibleRecursive() && (e.getItem() == null)) {
selectedEntityPanel.setVisible(false);
}

View File

@ -110,10 +110,10 @@ public class ScreenPermissionsFrame extends AbstractFrame {
companion.initPermissionColoredColumns(screenPermissionsTree);
screenPermissionsTreeDs.addItemChangeListener(e -> {
if (!selectedScreenPanel.isVisible() && (e.getItem() != null)) {
if (!selectedScreenPanel.isVisibleRecursive() && (e.getItem() != null)) {
selectedScreenPanel.setVisible(true);
}
if (selectedScreenPanel.isVisible() && (e.getItem() == null)) {
if (selectedScreenPanel.isVisibleRecursive() && (e.getItem() == null)) {
selectedScreenPanel.setVisible(false);
}

View File

@ -101,7 +101,7 @@ public class ChangePasswordDialog extends AbstractWindow {
public void ready() {
super.ready();
if (currentPasswordField.isVisible() && currentPasswordField.isEnabled()) {
if (currentPasswordField.isVisibleRecursive() && currentPasswordField.isEnabledRecursive()) {
currentPasswordField.requestFocus();
}

View File

@ -122,6 +122,11 @@ public class AbstractFrame implements Frame, Frame.Wrapper, Component.Wrapper, C
return frame.isEnabled();
}
@Override
public boolean isEnabledRecursive() {
return frame.isEnabledRecursive();
}
@Override
public void setEnabled(boolean enabled) {
frame.setEnabled(enabled);
@ -138,13 +143,8 @@ public class AbstractFrame implements Frame, Frame.Wrapper, Component.Wrapper, C
}
@Override
public boolean isVisibleItself() {
return frame.isVisibleItself();
}
@Override
public boolean isEnabledItself() {
return frame.isEnabledItself();
public boolean isVisibleRecursive() {
return frame.isVisibleRecursive();
}
@Override

View File

@ -50,8 +50,7 @@ public interface Component {
BOTTOM_CENTER
}
// vaadin8 convert to enumeration
// todo use com.haulmont.cuba.gui.components.SizeUnit
// vaadin8 JavaDoc for deprecated
@Deprecated
int UNITS_PIXELS = 0;
@Deprecated
@ -84,7 +83,8 @@ public interface Component {
void setDebugId(String id);
/**
* Are the component and its parent enabled?
* Is the component enabled?
* vaadin8 add JavaDoc
*/
boolean isEnabled();
/** Set component enabled state */
@ -103,21 +103,42 @@ public interface Component {
void setResponsive(boolean responsive);
/**
* Are the component and its parent visible?
* Is the component visible?
* vaadin8 add JavaDoc
*/
boolean isVisible();
/** Set component visibility */
void setVisible(boolean visible);
/**
* Is the component visible regardless of the parent?
* @return
*/
boolean isVisibleItself();
boolean isVisibleRecursive();
/**
* @return
*/
boolean isEnabledRecursive();
/**
* Is the component visible regardless of the parent?
*
* @deprecated Use {{@link #isVisible()} instead.
*/
@Deprecated
default boolean isVisibleItself() {
return isVisible();
}
/**
* Is the component enabled regardless of the parent?
*
* @deprecated Use {{@link #isEnabled()} instead.
*/
boolean isEnabledItself();
@Deprecated
default boolean isEnabledItself() {
return isEnabled();
}
/** Set focus to this component */
// vaadin8 move to Focusable

View File

@ -19,7 +19,9 @@ package com.haulmont.cuba.gui.components;
import com.haulmont.chile.core.model.MetaClass;
import com.haulmont.chile.core.model.MetaPropertyPath;
import com.haulmont.cuba.core.entity.Entity;
import com.haulmont.cuba.core.global.*;
import com.haulmont.cuba.core.global.AppBeans;
import com.haulmont.cuba.core.global.MessageTools;
import com.haulmont.cuba.core.global.Metadata;
import com.haulmont.cuba.gui.ComponentsHelper;
import com.haulmont.cuba.gui.data.CollectionDatasource;
import com.haulmont.cuba.gui.data.Datasource;
@ -833,13 +835,13 @@ public interface Table<E extends Entity>
}
@Override
public boolean isVisibleItself() {
throw new UnsupportedOperationException();
public boolean isVisibleRecursive() {
return true;
}
@Override
public boolean isEnabledItself() {
throw new UnsupportedOperationException();
public boolean isEnabledRecursive() {
return true;
}
@Override

View File

@ -992,7 +992,7 @@ public class FilterDelegateImpl implements FilterDelegate {
protected String getControlsLayoutStyleName() {
String styleName = "filter-control-no-border";
if (conditionsLayout.isVisible() && !conditionsLayout.getComponents().isEmpty()) {
if (conditionsLayout.isVisibleRecursive() && !conditionsLayout.getComponents().isEmpty()) {
styleName = CONDITIONS_LOCATION_TOP.equals(conditionsLocation) ? "filter-control-with-top-border"
: "filter-control-with-bottom-border";
}

View File

@ -223,13 +223,13 @@ public class ParamWrapper implements Component, Component.HasValue<Object> {
}
@Override
public boolean isVisibleItself() {
throw new UnsupportedOperationException();
public boolean isVisibleRecursive() {
return false;
}
@Override
public boolean isEnabledItself() {
throw new UnsupportedOperationException();
public boolean isEnabledRecursive() {
return false;
}
@Override

View File

@ -134,7 +134,7 @@ public class CustomConditionFrame extends ConditionFrame<CustomCondition> {
fillEntitySelect(param);
//recreate default value component based on param type
if (!initializing && defaultValueLayout.isVisible()) {
if (!initializing && defaultValueLayout.isVisibleRecursive()) {
ParamType paramType = (ParamType) e.getValue();
if ((isEntity || isEnum) && (entitySelect.getValue() == null)) {
defaultValueLayout.remove(defaultValueComponent);
@ -151,7 +151,7 @@ public class CustomConditionFrame extends ConditionFrame<CustomCondition> {
inExprCb.addValueChangeListener(e -> {
condition.getParam().setInExpr(BooleanUtils.isTrue((Boolean) e.getValue()));
//recreate default value component based on "in list" checkbox value
if (!initializing && defaultValueLayout.isVisible()) {
if (!initializing && defaultValueLayout.isVisibleRecursive()) {
condition.getParam().setDefaultValue(null);
createDefaultValueComponent();
}
@ -177,7 +177,7 @@ public class CustomConditionFrame extends ConditionFrame<CustomCondition> {
});
entitySelect.addValueChangeListener(e -> {
if (initializing || !defaultValueLayout.isVisible()) {
if (initializing || !defaultValueLayout.isVisibleRecursive()) {
return;
}
if (e.getValue() == null) {

View File

@ -427,7 +427,7 @@ public class WebWindowManager extends WindowManager {
String focusComponentId = window.getFocusComponent();
if (focusComponentId != null) {
com.haulmont.cuba.gui.components.Component focusComponent = window.getComponent(focusComponentId);
if (focusComponent != null && focusComponent.isEnabled() && focusComponent.isVisible()) {
if (focusComponent != null && focusComponent.isEnabledRecursive() && focusComponent.isVisibleRecursive()) {
focusComponent.requestFocus();
focused = true;
}

View File

@ -337,7 +337,7 @@ public class AppLoginWindow extends AbstractWindow implements Window.TopLevelWin
protected void doLogin(Credentials credentials) throws LoginException {
if (credentials instanceof AbstractClientCredentials) {
((AbstractClientCredentials) credentials).setOverrideLocale(localesSelect.isVisible());
((AbstractClientCredentials) credentials).setOverrideLocale(localesSelect.isVisibleRecursive());
}
connection.login(credentials);
}

View File

@ -104,7 +104,7 @@ public class LogDownloadOptionsWindow extends AbstractWindow {
public void downloadTail() {
LogDataProvider logDataProvider;
if (remoteContextBox.isVisible()) {
if (remoteContextBox.isVisibleRecursive()) {
logDataProvider = new LogDataProvider(connection, logFileName, remoteContextField.getValue(), false);
} else {
logDataProvider = new LogDataProvider(connection, logFileName, false);
@ -118,7 +118,7 @@ public class LogDownloadOptionsWindow extends AbstractWindow {
public void downloadFull() {
LogDataProvider logDataProvider;
if (remoteContextBox.isVisible()) {
if (remoteContextBox.isVisibleRecursive()) {
logDataProvider = new LogDataProvider(connection, logFileName, remoteContextField.getValue(), true);
} else {
logDataProvider = new LogDataProvider(connection, logFileName, true);

View File

@ -43,10 +43,12 @@ import com.haulmont.cuba.gui.settings.Settings;
import com.haulmont.cuba.web.AppUI;
import com.haulmont.cuba.web.WebConfig;
import com.haulmont.cuba.web.WebWindowManager;
import com.haulmont.cuba.web.gui.components.*;
import com.haulmont.cuba.web.gui.components.WebComponentsHelper;
import com.haulmont.cuba.web.gui.components.WebFrameActionsHolder;
import com.haulmont.cuba.web.gui.components.WebWrapperUtils;
import com.haulmont.cuba.web.gui.icons.IconResolver;
import com.haulmont.cuba.web.widgets.CubaSingleModeContainer;
import com.haulmont.cuba.web.widgets.CubaVerticalActionsLayout;
import com.haulmont.cuba.web.gui.icons.IconResolver;
import com.vaadin.server.ClientConnector;
import com.vaadin.server.Page;
import com.vaadin.server.Sizeable.Unit;
@ -976,7 +978,17 @@ public class WebWindow implements Window, Component.Wrapper,
@Override
public boolean isVisible() {
return true;
return getComposition().isVisible();
}
@Override
public boolean isVisibleRecursive() {
return isVisible(); // vaadin8 is this correct?
}
@Override
public boolean isEnabledRecursive() {
return isEnabled(); // vaadin8 is this correct?
}
@Override
@ -984,16 +996,6 @@ public class WebWindow implements Window, Component.Wrapper,
throw new UnsupportedOperationException();
}
@Override
public boolean isVisibleItself() {
return true;
}
@Override
public boolean isEnabledItself() {
return component.isEnabled();
}
@Override
public void requestFocus() {
}

View File

@ -184,6 +184,11 @@ public abstract class WebAbstractComponent<T extends com.vaadin.ui.Component>
@Override
public boolean isEnabled() {
return getComposition().isEnabled();
}
@Override
public boolean isEnabledRecursive() {
return WebComponentsHelper.isComponentEnabled(getComposition());
}
@ -194,6 +199,11 @@ public abstract class WebAbstractComponent<T extends com.vaadin.ui.Component>
@Override
public boolean isVisible() {
return getComposition().isVisible();
}
@Override
public boolean isVisibleRecursive() {
return WebComponentsHelper.isComponentVisible(getComposition());
}
@ -202,16 +212,6 @@ public abstract class WebAbstractComponent<T extends com.vaadin.ui.Component>
getComposition().setVisible(visible);
}
@Override
public boolean isVisibleItself() {
return component.isVisible();
}
@Override
public boolean isEnabledItself() {
return component.isEnabled();
}
@Override
public String getIcon() {
return icon;

View File

@ -311,7 +311,7 @@ public abstract class WebAbstractField<T extends com.vaadin.v7.ui.AbstractField,
setValidationError(null);
}
if (!isVisible() || !isEditableWithParent() || !isEnabled()) {
if (!isVisibleRecursive() || !isEditableWithParent() || !isEnabledRecursive()) {
return;
}

View File

@ -180,7 +180,7 @@ public class WebCurrencyField<V> extends WebAbstractField<CubaCurrencyField, V>
setValidationError(null);
}
if (!isVisible() || !isEditableWithParent() || !isEnabled()) {
if (!isVisibleRecursive() || !isEditableWithParent() || !isEnabledRecursive()) {
return;
}

View File

@ -676,7 +676,7 @@ public class WebFieldGroup extends WebAbstractComponent<CubaFieldGroupLayout>
@Override
public void validate() throws ValidationException {
if (!isVisible() || !isEditableWithParent() || !isEnabled()) {
if (!isVisibleRecursive() || !isEditableWithParent() || !isEnabledRecursive()) {
return;
}
@ -716,8 +716,8 @@ public class WebFieldGroup extends WebAbstractComponent<CubaFieldGroupLayout>
for (FieldConfig fc : getColumnOrderedFields()) {
Component component = fc.getComponent();
if (component != null
&& component.isEnabled()
&& component.isVisible()
&& component.isEnabledRecursive()
&& component.isVisibleRecursive()
&& component instanceof Focusable
&& ((Focusable) component).isFocusable()) {

View File

@ -93,7 +93,7 @@ public class WebLookupField<V> extends WebAbstractOptionsField<CubaComboBox, V>
component.addShortcutListener(new ShortcutListener("clearShortcut", KeyCode.DELETE, new int[]{ModifierKey.SHIFT}) {
@Override
public void handleAction(Object sender, Object target) {
if (!isRequired() && isEnabled() && isEditable()) {
if (!isRequired() && isEnabledRecursive() && isEditableWithParent()) {
setValue(null);
}
}

View File

@ -204,7 +204,7 @@ public abstract class WebV8AbstractField<T extends com.vaadin.ui.AbstractField<P
setValidationError(null);
}
if (!isVisible() || !isEditableWithParent() || !isEnabled()) {
if (!isVisibleRecursive() || !isEditableWithParent() || !isEnabledRecursive()) {
return;
}