struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From musa...@apache.org
Subject svn commit: r535360 - in /struts/struts2/trunk/plugins/dojo/src/main: java/org/apache/struts2/dojo/components/ java/org/apache/struts2/dojo/views/jsp/ui/ resources/org/apache/struts2/static/dojo/struts/widget/ resources/template/ajax/
Date Fri, 04 May 2007 19:25:43 GMT
Author: musachy
Date: Fri May  4 12:25:42 2007
New Revision: 535360

URL: http://svn.apache.org/viewvc?view=rev&rev=535360
Log:
WW-1837 TabbedPanel selectedTab change event catch!

Added:
    struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/StrutsTabContainer.js
Modified:
    struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/TabbedPanel.java
    struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/TabbedPanelTag.java
    struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/__package__.js
    struts/struts2/trunk/plugins/dojo/src/main/resources/template/ajax/tabbedpanel.ftl

Modified: struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/TabbedPanel.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/TabbedPanel.java?view=diff&rev=535360&r1=535359&r2=535360
==============================================================================
--- struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/TabbedPanel.java
(original)
+++ struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/TabbedPanel.java
Fri May  4 12:25:42 2007
@@ -41,23 +41,43 @@
  * <!-- START SNIPPET: exdesc -->
  * The following is an example of a tabbedpanel and panel tag utilizing local and remote
content.<p/>
  * <!-- END SNIPPET: exdesc -->
- * <pre>
+ * 
  * <!-- START SNIPPET: example -->
- * &lt;s:tabbedpanel id=&quot;test&quot; &gt;
- *    &lt;s:div id=&quot;one&quot; label=&quot;one&quot; theme=&quot;ajax&quot;
labelposition=&quot;top&quot; &gt;
+ * <pre>
+ * &lt;s:tabbedpanel id="test" &gt;
+ *    &lt;s:div id="one" label="one" theme="ajax" labelposition="top" &gt;
  *        This is the first pane&lt;br/&gt;
  *        &lt;s:form&gt;
- *            &lt;s:textfield name=&quot;tt&quot; label=&quot;Test Text&quot;/&gt;
 &lt;br/&gt;
- *            &lt;s:textfield name=&quot;tt2&quot; label=&quot;Test Text2&quot;/&gt;
+ *            &lt;s:textfield name="tt" label="Test Text"/&gt;  &lt;br/&gt;
+ *            &lt;s:textfield name="tt2" label="Test Text2"/&gt;
  *        &lt;/s:form&gt;
  *    &lt;/s:div&gt;
- *    &lt;s:div id=&quot;three&quot; label=&quot;remote&quot; theme=&quot;ajax&quot;
href=&quot;/AjaxTest.action&quot; &gt;
+ *    &lt;s:div id="three" label="remote" theme="ajax" href="/AjaxTest.action" &gt;
  *        This is the remote tab
  *    &lt;/s:div&gt;
  * &lt;/s:tabbedpanel&gt;
+ * </pre>
  * <!-- END SNIPPET: example -->
+ * 
+ * <!-- START SNIPPET: example2 -->
+ * <p>Use notify topics to prevent a tab from being selected</p>
+ * <pre>
+ * &lt;script type="text/javascript"&gt;
+ * dojo.event.topic.subscribe("/beforeSelect", function(tab, cancel){
+ *     cancel.cancel = true;
+ * });
+ * &lt;/script&gt;
+ * 
+ * &lt;s:tabbedpanel id="test" beforeSelectTabNotifyTopics="/beforeSelect"&gt;
+ *    &lt;s:div id="three" label="remote" theme="ajax" href="/AjaxTest.action" &gt;
+ *        One Tab
+ *    &lt;/s:div&gt;
+ *    &lt;s:div id="three" label="remote" theme="ajax" href="/AjaxTest.action" &gt;
+ *        Another tab
+ *    &lt;/s:div&gt;
+ * &lt;/s:tabbedpanel&gt;
  * </pre>
- *
+ * <!-- END SNIPPET: example2 -->
  */
 @StrutsTag(name="tabbedpanel", tldTagClass="org.apache.struts2.dojo.views.jsp.ui.TabbedPanelTag",
description="Render a tabbedPanel widget.")
 public class TabbedPanel extends ClosingUIBean {
@@ -69,7 +89,9 @@
     protected String closeButton;
     protected String doLayout ;
     protected String templateCssPath;
-
+    protected String beforeSelectTabNotifyTopics;
+    protected String afterSelectTabNotifyTopics;
+    
     public TabbedPanel(ValueStack stack, HttpServletRequest request, HttpServletResponse
response) {
         super(stack, request, response);
     }
@@ -78,12 +100,12 @@
     protected void evaluateExtraParams() {
         super.evaluateExtraParams();
 
-        if(selectedTab != null)
+        if (selectedTab != null)
             addParameter("selectedTab", findString(selectedTab));
-        if(closeButton != null)
+        if (closeButton != null)
             addParameter("closeButton", findString(closeButton));
         addParameter("doLayout", doLayout != null ? findValue(doLayout, Boolean.class) :
Boolean.FALSE);
-        if(labelPosition != null) {
+        if (labelPosition != null) {
             //dojo has some weird name for label positions
             if(labelPosition.equalsIgnoreCase("left"))
                labelPosition = "left-h";
@@ -92,8 +114,13 @@
             addParameter("labelPosition", null);
             addParameter("labelPosition", labelPosition);
         }
-        if(templateCssPath != null)
+        if (templateCssPath != null)
             addParameter("templateCssPath", findString(templateCssPath));
+        if (beforeSelectTabNotifyTopics!= null)
+            addParameter("beforeSelectTabNotifyTopics", findString(beforeSelectTabNotifyTopics));
+        if (afterSelectTabNotifyTopics!= null)
+            addParameter("afterSelectTabNotifyTopics", findString(afterSelectTabNotifyTopics));
+        
     }
 
     @Override
@@ -144,5 +171,19 @@
     @StrutsTagAttribute(description="Template css path")
     public void setTemplateCssPath(String templateCssPath) {
         this.templateCssPath = templateCssPath;
+    }
+
+
+    @StrutsTagAttribute(description="Comma separated list of topics to be published when
a tab is clicked on (before it is selected)" +
+    		"The tab widget will be passed as the first argument to the topic. The event can be
cancelled setting to 'true' the 'cancel' property " +
+    		"of the second parameter passed to the topics.")
+    public void setBeforeSelectTabNotifyTopics(String selectedTabNotifyTopics) {
+        this.beforeSelectTabNotifyTopics = selectedTabNotifyTopics;
+    }
+
+    @StrutsTagAttribute(description="Comma separated list of topics to be published when
a tab is clicked on (after it is selected)." +
+        "The tab widget will be passed as the first argument to the topic.")
+    public void setAfterSelectTabNotifyTopics(String afterSelectTabNotifyTopics) {
+        this.afterSelectTabNotifyTopics = afterSelectTabNotifyTopics;
     }
 }

Modified: struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/TabbedPanelTag.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/TabbedPanelTag.java?view=diff&rev=535360&r1=535359&r2=535360
==============================================================================
--- struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/TabbedPanelTag.java
(original)
+++ struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/TabbedPanelTag.java
Fri May  4 12:25:42 2007
@@ -40,7 +40,9 @@
     private String closeButton;
     private String doLayout;
     private String templateCssPath;
-
+    private String beforeSelectTabNotifyTopics;
+    private String afterSelectTabNotifyTopics;
+    
     public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse
res) {
         return new TabbedPanel(stack, req, res);
     }
@@ -53,6 +55,8 @@
         tabbedPanel.setDoLayout(doLayout);
         tabbedPanel.setLabelposition(labelPosition);
         tabbedPanel.setTemplateCssPath(templateCssPath);
+        tabbedPanel.setBeforeSelectTabNotifyTopics(beforeSelectTabNotifyTopics);
+        tabbedPanel.setAfterSelectTabNotifyTopics(afterSelectTabNotifyTopics);
     }
 
     public void setSelectedTab(String selectedTab) {
@@ -69,5 +73,13 @@
 
     public void setTemplateCssPath(String templateCssPath) {
         this.templateCssPath = templateCssPath;
+    }
+
+    public void setBeforeSelectTabNotifyTopics(String beforeSelectTabNotifyTopics) {
+        this.beforeSelectTabNotifyTopics = beforeSelectTabNotifyTopics;
+    }
+
+    public void setAfterSelectTabNotifyTopics(String afterSelectTabNotifyTopics) {
+        this.afterSelectTabNotifyTopics = afterSelectTabNotifyTopics;
     }
 }

Added: struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/StrutsTabContainer.js
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/StrutsTabContainer.js?view=auto&rev=535360
==============================================================================
--- struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/StrutsTabContainer.js
(added)
+++ struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/StrutsTabContainer.js
Fri May  4 12:25:42 2007
@@ -0,0 +1,56 @@
+dojo.provide("struts.widget.StrutsTabContainer");
+
+dojo.require("dojo.widget.TabContainer");
+
+dojo.widget.defineWidget(
+  "struts.widget.StrutsTabContainer",
+  dojo.widget.TabContainer, {
+  widgetType : "StrutsTabContainer",
+
+  afterSelectTabNotifyTopics : "",
+  afterSelectTabNotifyTopicsArray : null,
+  beforeSelectTabNotifyTopics : "",
+  beforeSelectTabNotifyTopicsArray : null,
+
+  postCreate : function() {
+    struts.widget.StrutsTabContainer.superclass.postCreate.apply(this);
+    
+    //before topics
+    if(!dojo.string.isBlank(this.beforeSelectTabNotifyTopics)) {
+      this.beforeSelectTabNotifyTopicsArray = this.beforeSelectTabNotifyTopics.split(",");
+    }
+    
+    //after topics
+    if(!dojo.string.isBlank(this.afterSelectTabNotifyTopics)) {
+      this.afterSelectTabNotifyTopicsArray = this.afterSelectTabNotifyTopics.split(",");
+    }
+  },
+   
+  selectChild: function (tab, callingWidget)  {
+    var cancel = {"cancel" : false};
+    
+    if(this.beforeSelectTabNotifyTopicsArray) {
+      dojo.lang.forEach(this.beforeSelectTabNotifyTopicsArray, function(topic) {
+        try {
+          dojo.event.topic.publish(topic, tab, cancel);
+        } catch(ex){
+          dojo.debug(ex);
+        }
+      });   
+    }
+    
+    if(!cancel.cancel) {
+      struts.widget.StrutsTabContainer.superclass.selectChild.apply(this, [tab, callingWidget]);
+      
+      if(this.afterSelectTabNotifyTopicsArray) {
+        dojo.lang.forEach(this.afterSelectTabNotifyTopicsArray, function(topic) {
+          try {
+            dojo.event.topic.publish(topic, tab, cancel);
+          } catch(ex){
+            dojo.debug(ex);
+          }
+        });   
+      }
+    }  
+  }
+});

Modified: struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/__package__.js
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/__package__.js?view=diff&rev=535360&r1=535359&r2=535360
==============================================================================
--- struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/__package__.js
(original)
+++ struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/__package__.js
Fri May  4 12:25:42 2007
@@ -6,6 +6,7 @@
              "struts.widget.StrutsTimePicker",
              "struts.widget.StrutsDatePicker",
              "struts.widget.BindEvent",
-             "struts.widget.StrutsTreeSelector"]
+             "struts.widget.StrutsTreeSelector",
+             "struts.widget.StrutsTabContainer"]
 });
 dojo.provide("struts.widget.*");

Modified: struts/struts2/trunk/plugins/dojo/src/main/resources/template/ajax/tabbedpanel.ftl
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/dojo/src/main/resources/template/ajax/tabbedpanel.ftl?view=diff&rev=535360&r1=535359&r2=535360
==============================================================================
--- struts/struts2/trunk/plugins/dojo/src/main/resources/template/ajax/tabbedpanel.ftl (original)
+++ struts/struts2/trunk/plugins/dojo/src/main/resources/template/ajax/tabbedpanel.ftl Fri
May  4 12:25:42 2007
@@ -1,4 +1,4 @@
-<div dojoType="TabContainer"
+<div dojoType="struts:StrutsTabContainer"
   <#if parameters.cssStyle?if_exists != "">
     style="${parameters.cssStyle?html}"<#rt/>
   </#if>
@@ -25,6 +25,12 @@
   </#if>
   <#if parameters.templateCssPath?exists>
 	templateCssPath="<@s.url value='${parameters.templateCssPath}' encode="false" includeParams='none'/>"
+  </#if>
+  <#if parameters.beforeSelectTabNotifyTopics?if_exists != "">
+    beforeSelectTabNotifyTopics="${parameters.beforeSelectTabNotifyTopics?html}"<#rt/>
+  </#if>
+  <#if parameters.afterSelectTabNotifyTopics?if_exists != "">
+    afterSelectTabNotifyTopics="${parameters.afterSelectTabNotifyTopics?html}"<#rt/>
   </#if>
   <#include "/${parameters.templateDir}/simple/scripting-events.ftl" />
   <#include "/${parameters.templateDir}/simple/common-attributes.ftl" />



Mime
View raw message