From 7ff754a502863f64cb56918f934af80d647453ce Mon Sep 17 00:00:00 2001 From: Yuriy Artamonov Date: Thu, 26 Feb 2015 11:44:32 +0000 Subject: [PATCH] Components which are placed on invisible tabs should be considered invisible #PL-4972 --- .../components/DesktopAbstractComponent.java | 5 +-- .../components/DesktopComponentsHelper.java | 16 ++++++++ .../gui/components/WebComponentsHelper.java | 17 ++++++++ .../gui/components/WebAbstractComponent.java | 4 +- .../gui/components/WebComponentsHelper.java | 39 ++++++++++++++++++- 5 files changed, 74 insertions(+), 7 deletions(-) diff --git a/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopAbstractComponent.java b/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopAbstractComponent.java index c8ccff3ff4..be7600fe8f 100644 --- a/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopAbstractComponent.java +++ b/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopAbstractComponent.java @@ -143,10 +143,7 @@ public abstract class DesktopAbstractComponent @Override public boolean isVisible() { - if (container != null) - return visible && container.isVisible(); - else - return visible; + return DesktopComponentsHelper.isRecursivelyVisible(getComposition()); } @Override diff --git a/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopComponentsHelper.java b/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopComponentsHelper.java index 7cb0a86228..303753d6da 100644 --- a/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopComponentsHelper.java +++ b/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopComponentsHelper.java @@ -284,6 +284,22 @@ public class DesktopComponentsHelper { * @return true if the component and all of its ancestors are visible */ public static boolean isRecursivelyVisible(java.awt.Component component) { + if (component.getParent() instanceof JTabbedPane) { + JTabbedPane jTabbedPane = (JTabbedPane) component.getParent(); + + boolean tabVisible = false; + for (java.awt.Component childComponent : jTabbedPane.getComponents()) { + if (childComponent == component) { + tabVisible = true; + break; + } + } + + if (!tabVisible) { + return false; + } + } + return component.isVisible() && (component.getParent() == null || isRecursivelyVisible(component.getParent())); } diff --git a/modules/web/src/com/haulmont/cuba/web/gui/components/WebComponentsHelper.java b/modules/web/src/com/haulmont/cuba/web/gui/components/WebComponentsHelper.java index 6954a935a1..fd5203a8bb 100644 --- a/modules/web/src/com/haulmont/cuba/web/gui/components/WebComponentsHelper.java +++ b/modules/web/src/com/haulmont/cuba/web/gui/components/WebComponentsHelper.java @@ -25,6 +25,7 @@ import com.vaadin.shared.ui.datefield.Resolution; import com.vaadin.ui.*; import com.vaadin.ui.Button; import com.vaadin.ui.Component; +import com.vaadin.ui.TabSheet; import com.vaadin.ui.Table; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.LogFactory; @@ -345,6 +346,14 @@ public class WebComponentsHelper { * @return component visibility */ public static boolean isComponentVisible(Component child) { + if (child.getParent() instanceof TabSheet) { + TabSheet tabSheet = (TabSheet) child.getParent(); + TabSheet.Tab tab = tabSheet.getTab(child); + if (!tab.isVisible()) { + return false; + } + } + return child.isVisible() && (child.getParent() == null || isComponentVisible(child.getParent())); } @@ -355,6 +364,14 @@ public class WebComponentsHelper { * @return component enabled state */ public static boolean isComponentEnabled(Component child) { + if (child.getParent() instanceof TabSheet) { + TabSheet tabSheet = (TabSheet) child.getParent(); + TabSheet.Tab tab = tabSheet.getTab(child); + if (!tab.isEnabled()) { + return false; + } + } + return child.isEnabled() && (child.getParent() == null || isComponentEnabled(child.getParent())) && isComponentVisible(child); } diff --git a/modules/web6/src/com/haulmont/cuba/web/gui/components/WebAbstractComponent.java b/modules/web6/src/com/haulmont/cuba/web/gui/components/WebAbstractComponent.java index 9a2e72090f..ea677a5a67 100644 --- a/modules/web6/src/com/haulmont/cuba/web/gui/components/WebAbstractComponent.java +++ b/modules/web6/src/com/haulmont/cuba/web/gui/components/WebAbstractComponent.java @@ -103,7 +103,7 @@ public class WebAbstractComponent @Override public boolean isEnabled() { - return getComposition().isEnabled(); + return WebComponentsHelper.isComponentEnabled(getComposition()); } /** @@ -127,7 +127,7 @@ public class WebAbstractComponent @Override public boolean isVisible() { - return getComposition().isVisible(); + return WebComponentsHelper.isComponentVisible(getComposition()); } @Override diff --git a/modules/web6/src/com/haulmont/cuba/web/gui/components/WebComponentsHelper.java b/modules/web6/src/com/haulmont/cuba/web/gui/components/WebComponentsHelper.java index f4299411d3..8ea1e4a921 100644 --- a/modules/web6/src/com/haulmont/cuba/web/gui/components/WebComponentsHelper.java +++ b/modules/web6/src/com/haulmont/cuba/web/gui/components/WebComponentsHelper.java @@ -6,7 +6,6 @@ package com.haulmont.cuba.web.gui.components; import com.haulmont.cuba.gui.components.*; import com.haulmont.cuba.gui.components.Formatter; -import com.haulmont.cuba.gui.components.Table; import com.haulmont.cuba.web.App; import com.haulmont.cuba.web.toolkit.VersionedThemeResource; import com.haulmont.cuba.web.toolkit.data.AggregationContainer; @@ -20,6 +19,7 @@ import com.vaadin.terminal.Resource; import com.vaadin.ui.*; import com.vaadin.ui.Button; import com.vaadin.ui.Component; +import com.vaadin.ui.TabSheet; import org.apache.commons.lang.StringUtils; import java.io.File; @@ -128,6 +128,43 @@ public class WebComponentsHelper { || (layout instanceof HorizontalActionsLayout); } + /** + * Tests if component visible and its container visible. + * + * @param child component + * @return component visibility + */ + public static boolean isComponentVisible(Component child) { + if (child.getParent() instanceof TabSheet) { + TabSheet tabSheet = (TabSheet) child.getParent(); + TabSheet.Tab tab = tabSheet.getTab(child); + if (!tab.isVisible()) { + return false; + } + } + + return ((AbstractComponent)child).isComponentVisible() && (child.getParent() == null || isComponentVisible(child.getParent())); + } + + /** + * Tests if component enabled and visible and its container enabled. + * + * @param child component + * @return component enabled state + */ + public static boolean isComponentEnabled(Component child) { + if (child.getParent() instanceof TabSheet) { + TabSheet tabSheet = (TabSheet) child.getParent(); + TabSheet.Tab tab = tabSheet.getTab(child); + if (!tab.isEnabled()) { + return false; + } + } + + return ((AbstractComponent)child).isComponentEnabled() && (child.getParent() == null || isComponentEnabled(child.getParent())) && + isComponentVisible(child); + } + public static Alignment convertAlignment(com.haulmont.cuba.gui.components.Component.Alignment alignment) { if (alignment == null) return null;