You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by GitBox <gi...@apache.org> on 2021/03/30 05:27:15 UTC

[GitHub] [myfaces-tobago] lofwyr14 commented on a change in pull request #691: feature(attribute): auto spacing

lofwyr14 commented on a change in pull request #691:
URL: https://github.com/apache/myfaces-tobago/pull/691#discussion_r603790029



##########
File path: tobago-core/src/main/java/org/apache/myfaces/tobago/component/SupportsAutoSpacing.java
##########
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.tobago.component;
+
+import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
+
+import javax.faces.context.FacesContext;
+
+public interface SupportsAutoSpacing {
+  /**
+   * use {@link #getAutoSpacing(FacesContext)} to get the correct default value.
+   * return null if autoSpacing is not set manually
+   */
+  Boolean getAutoSpacing();
+
+  default boolean getAutoSpacing(final FacesContext facesContext) {
+    Boolean autoSpacing = getAutoSpacing();
+    if (autoSpacing != null) {
+      return autoSpacing;
+    } else {
+      final boolean insideHeader = facesContext.getAttributes().get(HtmlElements.TOBAGO_HEADER) != null;

Review comment:
       use Variable for facesContext.getAttributes()

##########
File path: tobago-core/src/main/java/org/apache/myfaces/tobago/component/SupportsAutoSpacing.java
##########
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.tobago.component;
+
+import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
+
+import javax.faces.context.FacesContext;
+
+public interface SupportsAutoSpacing {
+  /**
+   * use {@link #getAutoSpacing(FacesContext)} to get the correct default value.
+   * return null if autoSpacing is not set manually
+   */
+  Boolean getAutoSpacing();
+
+  default boolean getAutoSpacing(final FacesContext facesContext) {
+    Boolean autoSpacing = getAutoSpacing();
+    if (autoSpacing != null) {
+      return autoSpacing;
+    } else {
+      final boolean insideHeader = facesContext.getAttributes().get(HtmlElements.TOBAGO_HEADER) != null;
+      final boolean insideFooter = facesContext.getAttributes().get(HtmlElements.TOBAGO_FOOTER) != null;
+      final boolean insideSheet = facesContext.getAttributes().get(HtmlElements.TOBAGO_SHEET) != null;
+      final boolean insideLinks = facesContext.getAttributes().get(HtmlElements.TOBAGO_LINKS) != null;
+      final boolean insideButtons = facesContext.getAttributes().get(HtmlElements.TOBAGO_BUTTONS) != null;
+      final boolean insideBeforeFacet = facesContext.getAttributes().get(Facets.before) != null;
+      final boolean insideAfterFacet = facesContext.getAttributes().get(Facets.after) != null;
+      final boolean insideLabelFacet = facesContext.getAttributes().get(Facets.label) != null;
+      final boolean insideBarFacet = facesContext.getAttributes().get(Facets.bar) != null;
+      return !insideHeader && !insideFooter && !insideSheet && !insideLinks && !insideButtons && !insideBeforeFacet

Review comment:
       Don't use variables for these booleans




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org