You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@click.apache.org by sa...@apache.org on 2010/04/02 11:13:54 UTC

svn commit: r930196 - in /click/trunk/click/framework/src/org/apache/click: control/Panel.java util/PageImports.java

Author: sabob
Date: Fri Apr  2 09:13:53 2010
New Revision: 930196

URL: http://svn.apache.org/viewvc?rev=930196&view=rev
Log:
added active property allowing page imports to import only active panel resources

Modified:
    click/trunk/click/framework/src/org/apache/click/control/Panel.java
    click/trunk/click/framework/src/org/apache/click/util/PageImports.java

Modified: click/trunk/click/framework/src/org/apache/click/control/Panel.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/control/Panel.java?rev=930196&r1=930195&r2=930196&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/control/Panel.java (original)
+++ click/trunk/click/framework/src/org/apache/click/control/Panel.java Fri Apr  2 09:13:53 2010
@@ -259,6 +259,9 @@ public class Panel extends AbstractConta
     /** The path of the template to render. */
     protected String template;
 
+    /** The panel active value, <tt>"true"</tt> by default. */
+    protected boolean active = true;
+
     // Constructors -----------------------------------------------------------
 
     /**
@@ -347,6 +350,7 @@ public class Panel extends AbstractConta
      * @throws IllegalArgumentException if the control is null or the container
      *     already contains a control with the same name
      */
+    @Override
     public Control add(Control control) {
         super.add(control);
 
@@ -392,6 +396,7 @@ public class Panel extends AbstractConta
      * @return true if the control was removed from the container
      * @throws IllegalArgumentException if the control is null
      */
+    @Override
     public boolean remove(Control control) {
         boolean contains = super.remove(control);
 
@@ -418,7 +423,8 @@ public class Panel extends AbstractConta
     }
 
     /**
-     * Set whether the panel is disabled.
+     * Set the panel disabled flag. Disabled panels are not processed nor
+     * is their action event fired.
      *
      * @param disabled the disabled flag
      */
@@ -427,14 +433,38 @@ public class Panel extends AbstractConta
     }
 
     /**
+     * Return true if the panel is active.
+     *
+     * @return true if the panel is active
+     */
+    public boolean isActive() {
+        return active;
+    }
+
+    /**
+     * Set the panel active flag. The active property is normally managed and
+     * set by Panel containers.
+     *
+     * <b>Please note</b>: inactive panels do not have their page events
+     * ({@link #onInit}, {@link #onProcess(), {@link #onRender}) processed.
+     *
+     * @param active the active flag
+     */
+    public void setActive(boolean active) {
+        this.active = active;
+    }
+
+    /**
      * Return the panel id value. If no id attribute is defined then this method
      * will return the panel name. If no name is defined this method will return
      * <tt>null</tt>.
      *
+     * @see #setActive(boolean)
      * @see org.apache.click.Control#getId()
      *
      * @return the panel HTML id attribute value
      */
+    @Override
     public String getId() {
         if (id != null) {
             return id;
@@ -470,6 +500,7 @@ public class Panel extends AbstractConta
      *
      * @param id the id attribute for this panel
      */
+    @Override
     public void setId(String id) {
         this.id = id;
     }
@@ -592,6 +623,60 @@ public class Panel extends AbstractConta
     // Public Methods ---------------------------------------------------------
 
     /**
+     * Initialize the panel.
+     * <p/>
+     * <b>Please note</b>: {@link #isActive() inactive} panels are not
+     * initialized.
+     *
+     * @see org.apache.click.Control#onInit()
+     */
+    @Override
+    public void onInit() {
+        if (isActive()) {
+            super.onInit();
+        }
+    }
+
+    /**
+     * This method processes the Panel request returning true to continue
+     * processing or false otherwise.
+     * <p/>
+     * <b>Please note</b>: {@link #isDisabled() Disabled} and
+     * {@link #isActive() inactive} panels are not processed.
+     *
+     * @see org.apache.click.Control#onProcess().
+     *
+     * @return true to continue Panel event processing, false otherwise
+     */
+    @Override
+    public boolean onProcess() {
+        if (isDisabled()) {
+            return true;
+        }
+
+        if (!isActive()) {
+            return true;
+        }
+
+        return super.onProcess();
+    }
+
+    /**
+     * Perform any pre rendering logic and invoke the <tt>onRender()</tt> method
+     * of any child controls.
+     * <p/>
+     * <b>Please note</b>: {@link #isActive() inactive} panels are not rendered.
+     *
+     * @see org.apache.click.Control#onRender()
+     */
+    @Override
+    public void onRender() {
+        if (isActive()) {
+            super.onRender();
+        }
+    }
+
+    /**
      * Render the HTML string representation of the Panel. The panel will be
      * rendered by merging the {@link #template} with the template
      * model. The template model is created using {@link #createTemplateModel()}.
@@ -603,6 +688,7 @@ public class Panel extends AbstractConta
      *
      * @param buffer the specified buffer to render the control's output to
      */
+    @Override
     public void render(HtmlStringBuffer buffer) {
         Context context = getContext();
 

Modified: click/trunk/click/framework/src/org/apache/click/util/PageImports.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/util/PageImports.java?rev=930196&r1=930195&r2=930196&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/util/PageImports.java (original)
+++ click/trunk/click/framework/src/org/apache/click/util/PageImports.java Fri Apr  2 09:13:53 2010
@@ -28,6 +28,7 @@ import javax.servlet.http.HttpServletReq
 import org.apache.click.Control;
 import org.apache.click.Page;
 import org.apache.click.control.Container;
+import org.apache.click.control.Panel;
 import org.apache.click.control.Table;
 import org.apache.click.element.CssImport;
 import org.apache.click.element.CssStyle;
@@ -413,12 +414,20 @@ public class PageImports {
      * @param control the control to process
      */
     public void processControl(Control control) {
+        // Don't process inactive panels
+        if (control instanceof Panel) {
+            Panel panel = (Panel) control;
+            if (!panel.isActive()) {
+                return;
+            }
+        }
+
         processHeadElements(control.getHeadElements());
 
         if (control instanceof Container) {
             Container container = (Container) control;
             if (container.hasControls()) {
-                for (Control childControl  : container.getControls()) {
+                for (Control childControl : container.getControls()) {
                     processControl(childControl);
                 }
             }