diff options
author | Ahmed Ashour <asashour@yahoo.com> | 2017-09-13 15:18:53 +0200 |
---|---|---|
committer | Henri Sara <henri.sara@gmail.com> | 2017-09-14 08:44:50 +0300 |
commit | caf41dbac44b53c475e20ccc621c80c754033df9 (patch) | |
tree | 54f8260fb352be4ef3822ccd430f7e60e5c963ac /server | |
parent | ce25750a8fd3642cf1ed7d0dac708517d5bfd226 (diff) | |
download | vaadin-framework-caf41dbac44b53c475e20ccc621c80c754033df9.tar.gz vaadin-framework-caf41dbac44b53c475e20ccc621c80c754033df9.zip |
Simplify conditional logic.
Diffstat (limited to 'server')
3 files changed, 32 insertions, 70 deletions
diff --git a/server/src/main/java/com/vaadin/server/ComponentSizeValidator.java b/server/src/main/java/com/vaadin/server/ComponentSizeValidator.java index 20100e0e5a..19ece940e2 100644 --- a/server/src/main/java/com/vaadin/server/ComponentSizeValidator.java +++ b/server/src/main/java/com/vaadin/server/ComponentSizeValidator.java @@ -305,7 +305,6 @@ public class ComponentSizeValidator implements Serializable { this.component = component; this.info = info; } - } private static Deque<ComponentInfo> getHeightAttributes( @@ -435,7 +434,7 @@ public class ComponentSizeValidator implements Serializable { public static boolean parentCanDefineHeight(Component component) { Component parent = component.getParent(); if (parent == null) { - // main window, valid situation + // main window return true; } if (parent.getHeight() < 0) { @@ -446,37 +445,28 @@ public class ComponentSizeValidator implements Serializable { } if (parent instanceof AbstractOrderedLayout) { - boolean horizontal = true; if (parent instanceof VerticalLayout) { - horizontal = false; - } - if (horizontal && hasNonRelativeHeightComponent( - (AbstractOrderedLayout) parent)) { - return true; - } else { return false; } + return hasNonRelativeHeightComponent( + (AbstractOrderedLayout) parent); } else if (parent instanceof GridLayout) { GridLayout gl = (GridLayout) parent; Area componentArea = gl.getComponentArea(component); - boolean rowHasHeight = false; - for (int row = componentArea.getRow1(); !rowHasHeight - && row <= componentArea.getRow2(); row++) { - for (int column = 0; !rowHasHeight - && column < gl.getColumns(); column++) { + for (int row = componentArea.getRow1(); + row <= componentArea.getRow2(); row++) { + for (int column = 0; + column < gl.getColumns(); column++) { Component c = gl.getComponent(column, row); if (c != null) { - rowHasHeight = !hasRelativeHeight(c); + if (!hasRelativeHeight(c)) { + return true; + } } } } - if (!rowHasHeight) { - return false; - } else { - // Other components define row height - return true; - } + return false; } else if (isForm(parent)) { /* * If some other part of the form is not relative it determines @@ -503,9 +493,8 @@ public class ComponentSizeValidator implements Serializable { // Relative height if (parent.getParent() != null) { return parentCanDefineHeight(parent); - } else { - return true; } + return true; } else { // Absolute height return true; @@ -516,7 +505,7 @@ public class ComponentSizeValidator implements Serializable { * Comparability form component which is defined in the different jar. * * TODO : Normally this logic shouldn't be here. But it means that the whole - * this class has wrong design and impementation and should be refactored. + * this class has wrong design and implementation and should be refactored. */ private static boolean formHasNonRelativeWidthComponent(Component form) { HasComponents parent = (HasComponents) form; @@ -553,7 +542,7 @@ public class ComponentSizeValidator implements Serializable { public static boolean parentCanDefineWidth(Component component) { Component parent = component.getParent(); if (parent == null) { - // main window, valid situation + // main window return true; } if (parent instanceof Window) { @@ -566,37 +555,25 @@ public class ComponentSizeValidator implements Serializable { if (parent instanceof AbstractOrderedLayout) { AbstractOrderedLayout ol = (AbstractOrderedLayout) parent; - boolean horizontal = true; - if (ol instanceof VerticalLayout) { - horizontal = false; - } - if (!horizontal && hasNonRelativeWidthComponent(ol)) { - // valid situation, other components defined width - return true; - } else { - return false; - } + // VerticalLayout and a child defines height + return ol instanceof VerticalLayout + && hasNonRelativeWidthComponent(ol); } else if (parent instanceof GridLayout) { GridLayout gl = (GridLayout) parent; Area componentArea = gl.getComponentArea(component); - boolean columnHasWidth = false; - for (int col = componentArea.getColumn1(); !columnHasWidth - && col <= componentArea.getColumn2(); col++) { - for (int row = 0; !columnHasWidth - && row < gl.getRows(); row++) { + for (int col = componentArea.getColumn1(); + col <= componentArea.getColumn2(); col++) { + for (int row = 0; row < gl.getRows(); row++) { Component c = gl.getComponent(col, row); if (c != null) { - columnHasWidth = !hasRelativeWidth(c); + if (!hasRelativeWidth(c)) { + return true; + } } } } - if (!columnHasWidth) { - return false; - } else { - // Other components define column width - return true; - } + return false; } else if (parent instanceof AbstractSplitPanel || parent instanceof TabSheet || parent instanceof CustomComponent) { @@ -608,18 +585,11 @@ public class ComponentSizeValidator implements Serializable { return false; } else if (parent instanceof Window) { // Sub window can define width based on caption - if (parent.getCaption() != null - && !parent.getCaption().isEmpty()) { - return true; - } else { - return false; - } - } else if (parent instanceof Panel) { - // TODO Panel should be able to define width based on caption - return false; - } else { - return true; + return parent.getCaption() != null + && !parent.getCaption().isEmpty(); } + // TODO Panel should be able to define width based on caption + return !(parent instanceof Panel); } else if (hasRelativeWidth(parent)) { // Relative width if (parent.getParent() == null) { diff --git a/server/src/main/java/com/vaadin/server/widgetsetutils/ClassPathExplorer.java b/server/src/main/java/com/vaadin/server/widgetsetutils/ClassPathExplorer.java index 0ec39c9416..50b23f80a3 100644 --- a/server/src/main/java/com/vaadin/server/widgetsetutils/ClassPathExplorer.java +++ b/server/src/main/java/com/vaadin/server/widgetsetutils/ClassPathExplorer.java @@ -58,13 +58,8 @@ public class ClassPathExplorer { /** * File filter that only accepts directories. */ - private final static FileFilter DIRECTORIES_ONLY = (File f) -> { - if (f.exists() && f.isDirectory()) { - return true; - } else { - return false; - } - }; + private final static FileFilter DIRECTORIES_ONLY = (File f) -> + f.exists() && f.isDirectory(); /** * Contains information about widgetsets and themes found on the classpath diff --git a/server/src/main/java/com/vaadin/ui/AbstractComponent.java b/server/src/main/java/com/vaadin/ui/AbstractComponent.java index c31331c3e4..cce8d970dd 100644 --- a/server/src/main/java/com/vaadin/ui/AbstractComponent.java +++ b/server/src/main/java/com/vaadin/ui/AbstractComponent.java @@ -426,12 +426,9 @@ public abstract class AbstractComponent extends AbstractClientConnector return false; } else if (!super.isConnectorEnabled()) { return false; - } else if (getParent() instanceof SelectiveRenderer - && !((SelectiveRenderer) getParent()).isRendered(this)) { - return false; - } else { - return true; } + return !(getParent() instanceof SelectiveRenderer) + || ((SelectiveRenderer) getParent()).isRendered(this); } /* |