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 --> - * <s:tabbedpanel id="test" > - * <s:div id="one" label="one" theme="ajax" labelposition="top" > + * <pre> + * <s:tabbedpanel id="test" > + * <s:div id="one" label="one" theme="ajax" labelposition="top" > * This is the first pane<br/> * <s:form> - * <s:textfield name="tt" label="Test Text"/> <br/> - * <s:textfield name="tt2" label="Test Text2"/> + * <s:textfield name="tt" label="Test Text"/> <br/> + * <s:textfield name="tt2" label="Test Text2"/> * </s:form> * </s:div> - * <s:div id="three" label="remote" theme="ajax" href="/AjaxTest.action" > + * <s:div id="three" label="remote" theme="ajax" href="/AjaxTest.action" > * This is the remote tab * </s:div> * </s:tabbedpanel> + * </pre> * <!-- END SNIPPET: example --> + * + * <!-- START SNIPPET: example2 --> + * <p>Use notify topics to prevent a tab from being selected</p> + * <pre> + * <script type="text/javascript"> + * dojo.event.topic.subscribe("/beforeSelect", function(tab, cancel){ + * cancel.cancel = true; + * }); + * </script> + * + * <s:tabbedpanel id="test" beforeSelectTabNotifyTopics="/beforeSelect"> + * <s:div id="three" label="remote" theme="ajax" href="/AjaxTest.action" > + * One Tab + * </s:div> + * <s:div id="three" label="remote" theme="ajax" href="/AjaxTest.action" > + * Another tab + * </s:div> + * </s:tabbedpanel> * </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" />