From 4ee4d98028702ae16a2ef5bd197c005ca07bbeea Mon Sep 17 00:00:00 2001 From: Musachy Barroso Date: Tue, 17 Apr 2007 23:03:44 +0000 Subject: [PATCH] WW-1883 Deprecate topic attributes in Tree tag git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@529800 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/struts2/dojo/components/Tree.java | 66 +++-- .../struts2/dojo/views/jsp/ui/TreeTag.java | 51 ++-- .../dojo/struts/widget/StrutsTreeSelector.js | 66 ++++- .../apache/struts2/static/dojo/struts_dojo.js | 147 +++++++++- .../dojo/struts_dojo.js.uncompressed.js | 273 +++++++++++++++++- .../src/main/resources/template/ajax/tree.ftl | 25 +- 6 files changed, 556 insertions(+), 72 deletions(-) diff --git a/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Tree.java b/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Tree.java index 5c0e5f59f..f73c2e1d3 100644 --- a/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Tree.java +++ b/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Tree.java @@ -77,9 +77,9 @@ public class Tree extends ClosingUIBean { private static final String OPEN_TEMPLATE = "tree"; private String toggle = "fade"; - private String treeSelectedTopic; - private String treeExpandedTopic; - private String treeCollapsedTopic; + private String selectedNotifyTopics; + private String expandedNotifyTopics; + private String collapsedNotifyTopics; protected String rootNodeAttr; protected String childCollectionProperty; protected String nodeTitleProperty; @@ -127,16 +127,16 @@ public class Tree extends ClosingUIBean { addParameter("toggle", findString(toggle)); } - if (treeSelectedTopic != null) { - addParameter("treeSelectedTopic", findString(treeSelectedTopic)); + if (selectedNotifyTopics != null) { + addParameter("selectedNotifyTopics", findString(selectedNotifyTopics)); } - if (treeExpandedTopic != null) { - addParameter("treeExpandedTopic", findString(treeExpandedTopic)); + if (expandedNotifyTopics != null) { + addParameter("expandedNotifyTopics", findString(expandedNotifyTopics)); } - if (treeCollapsedTopic != null) { - addParameter("treeCollapsedTopic", findString(treeCollapsedTopic)); + if (collapsedNotifyTopics != null) { + addParameter("collapsedNotifyTopics", findString(collapsedNotifyTopics)); } if (rootNodeAttr != null) { @@ -242,31 +242,19 @@ public class Tree extends ClosingUIBean { this.toggle = toggle; } - public String getTreeSelectedTopic() { - return treeSelectedTopic; + @StrutsTagAttribute(description="Deprecated. Use 'selectedNotifyTopics' instead.") + public void setTreeSelectedTopic(String selectedNotifyTopic) { + this.selectedNotifyTopics = selectedNotifyTopic; } - @StrutsTagAttribute(description="The treeSelectedTopic property") - public void setTreeSelectedTopic(String treeSelectedTopic) { - this.treeSelectedTopic = treeSelectedTopic; + @StrutsTagAttribute(description="Deprecated. Use 'expandedNotifyTopics' instead.") + public void setTreeExpandedTopics(String expandedNotifyTopic) { + this.expandedNotifyTopics = expandedNotifyTopic; } - public String getTreeExpandedTopic() { - return treeExpandedTopic; - } - - @StrutsTagAttribute(description="The treeExpandedTopic property.") - public void setTreeExpandedTopic(String treeExpandedTopic) { - this.treeExpandedTopic = treeExpandedTopic; - } - - public String getTreeCollapsedTopic() { - return treeCollapsedTopic; - } - - @StrutsTagAttribute(description="The treeCollapsedTopic property.") - public void setTreeCollapsedTopic(String treeCollapsedTopic) { - this.treeCollapsedTopic = treeCollapsedTopic; + @StrutsTagAttribute(description="Deprecated. Use 'collapsedNotifyTopics' instead.") + public void setTreeCollapsedTopics(String collapsedNotifyTopic) { + this.collapsedNotifyTopics = collapsedNotifyTopic; } public String getRootNode() { @@ -463,5 +451,23 @@ public class Tree extends ClosingUIBean { public void setName(String name) { super.setName(name); } + + @StrutsTagAttribute(description="Comma separated lis of topics to be published when a node" + + " is collapsed. An object with a 'node' property will be passed as parameter to the topics.") + public void setCollapsedNotifyTopics(String collapsedNotifyTopics) { + this.collapsedNotifyTopics = collapsedNotifyTopics; + } + + @StrutsTagAttribute(description="Comma separated lis of topics to be published when a node" + + " is expanded. An object with a 'node' property will be passed as parameter to the topics.") + public void setExpandedNotifyTopics(String expandedNotifyTopics) { + this.expandedNotifyTopics= expandedNotifyTopics; + } + + @StrutsTagAttribute(description="Comma separated lis of topics to be published when a node" + + " is selected. An object with a 'node' property will be passed as parameter to the topics.") + public void setSelectedNotifyTopics(String selectedNotifyTopics) { + this.selectedNotifyTopics = selectedNotifyTopics; + } } diff --git a/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/TreeTag.java b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/TreeTag.java index e50f9ffc7..a00e2c533 100644 --- a/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/TreeTag.java +++ b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/TreeTag.java @@ -37,9 +37,9 @@ public class TreeTag extends AbstractClosingTag { private static final long serialVersionUID = 2735218501058548013L; private String toggle; - private String treeSelectedTopic; - private String treeExpandedTopic; - private String treeCollapsedTopic; + private String selectedNotifyTopics; + private String expandedNotifyTopics; + private String collapsedNotifyTopics; private String rootNode; private String childCollectionProperty; private String nodeTitleProperty; @@ -80,12 +80,12 @@ public class TreeTag extends AbstractClosingTag { tree.setRootNode(rootNode); if (toggle != null) tree.setToggle(toggle); - if (treeCollapsedTopic != null) - tree.setTreeCollapsedTopic(treeCollapsedTopic); - if (treeExpandedTopic != null) - tree.setTreeExpandedTopic(treeExpandedTopic); - if (treeSelectedTopic != null) - tree.setTreeSelectedTopic(treeSelectedTopic); + if (selectedNotifyTopics != null) + tree.setSelectedNotifyTopics(selectedNotifyTopics); + if (expandedNotifyTopics != null) + tree.setExpandedNotifyTopics(expandedNotifyTopics); + if (collapsedNotifyTopics != null) + tree.setCollapsedNotifyTopics(collapsedNotifyTopics); if (showRootGrid != null) tree.setShowRootGrid(showRootGrid); @@ -127,28 +127,19 @@ public class TreeTag extends AbstractClosingTag { this.toggle = toggle; } - public String getTreeSelectedTopic() { - return treeSelectedTopic; - } - + @Deprecated public void setTreeSelectedTopic(String treeSelectedTopic) { - this.treeSelectedTopic = treeSelectedTopic; - } - - public String getTreeExpandedTopic() { - return treeExpandedTopic; + this.selectedNotifyTopics = treeSelectedTopic; } + @Deprecated public void setTreeExpandedTopic(String treeExpandedTopic) { - this.treeExpandedTopic = treeExpandedTopic; - } - - public String getTreeCollapsedTopic() { - return treeCollapsedTopic; + this.expandedNotifyTopics = treeExpandedTopic; } + @Deprecated public void setTreeCollapsedTopic(String treeCollapsedTopic) { - this.treeCollapsedTopic = treeCollapsedTopic; + this.collapsedNotifyTopics = treeCollapsedTopic; } public String getRootNode() { @@ -302,5 +293,17 @@ public class TreeTag extends AbstractClosingTag { public void setShowGrid(String showGrid) { this.showGrid = showGrid; } + + public void setCollapsedNotifyTopics(String collapsedNotifyTopics) { + this.collapsedNotifyTopics = collapsedNotifyTopics; + } + + public void setExpandedNotifyTopics(String expandedNotifyTopics) { + this.expandedNotifyTopics = expandedNotifyTopics; + } + + public void setSelectedNotifyTopics(String selectedNotifyTopics) { + this.selectedNotifyTopics = selectedNotifyTopics; + } } diff --git a/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/StrutsTreeSelector.js b/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/StrutsTreeSelector.js index e63f977be..26f6c9c60 100644 --- a/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/StrutsTreeSelector.js +++ b/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/StrutsTreeSelector.js @@ -6,7 +6,15 @@ dojo.widget.defineWidget( "struts.widget.StrutsTreeSelector", dojo.widget.TreeSelector, { widgetType : "StrutsTreeSelector", - + + selectedNotifyTopics : "", + collapsedNotifyTopics : "", + expandedNotifyTopics : "", + + selectedNotifyTopicsArray : null, + collapsedNotifyTopicsArray : null, + expandedNotifyTopicsArray : null, + eventNamesDefault: { select : "select", destroy : "destroy", @@ -16,10 +24,26 @@ dojo.widget.defineWidget( collapse: "collapse" }, + initialize: function () { + struts.widget.StrutsTreeSelector.superclass.initialize.apply(this); + + if(!dojo.string.isBlank(this.selectedNotifyTopics)) { + this.selectedNotifyTopicsArray = this.selectedNotifyTopics.split(","); + } + + if(!dojo.string.isBlank(this.selectedNotifyTopics)) { + this.collapsedNotifyTopicsArray = this.collapsedNotifyTopics.split(","); + } + + if(!dojo.string.isBlank(this.selectedNotifyTopics)) { + this.expandedNotifyTopicsArray = this.expandedNotifyTopics.split(","); + } + }, + listenTree: function(tree) { dojo.event.topic.subscribe(tree.eventNames.collapse, this, "collapse"); dojo.event.topic.subscribe(tree.eventNames.expand, this, "expand"); - struts.widget.StrutsTreeSelector.superclass.unlistenTree.apply(this, [tree]); + struts.widget.StrutsTreeSelector.superclass.listenTree.apply(this, [tree]); }, unlistenTree: function(tree) { @@ -28,14 +52,48 @@ dojo.widget.defineWidget( struts.widget.StrutsTreeSelector.superclass.unlistenTree.apply(this, [tree]); }, + publishTopics : function(topics, node) { + if(topics != null) { + for(var i = 0; i < topics.length; i++) { + var topic = topics[i]; + if(!dojo.string.isBlank(topic)) { + try { + dojo.event.topic.publish(topic, node); + } catch(ex) { + dojo.debug(ex); + } + } + } + } + }, + + select:function (message) { + var node = message.source; + var e = message.event; + if (this.selectedNode === node) { + if (e.ctrlKey || e.shiftKey || e.metaKey) { + this.deselect(); + return; + } + dojo.event.topic.publish(this.eventNames.dblselect, {node:node}); + return; + } + if (this.selectedNode) { + this.deselect(); + } + this.doSelect(node); + + this.publishTopics(this.selectedNotifyTopicsArray, {node: node}); + }, + expand: function(message) { var node = message.source; - dojo.event.topic.publish(this.eventNames.expand, {node: node} ); + this.publishTopics(this.expandedNotifyTopicsArray, {node: node}); }, collapse: function(message) { var node = message.source; - dojo.event.topic.publish(this.eventNames.collapse, {node: node} ); + this.publishTopics(this.collapsedNotifyTopicsArray, {node: node}); }, }); \ No newline at end of file diff --git a/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts_dojo.js b/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts_dojo.js index 1c41245af..6c7640d2f 100644 --- a/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts_dojo.js +++ b/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts_dojo.js @@ -17151,6 +17151,151 @@ self.reloadContents(); } } }}); -dojo.kwCompoundRequire({common:["struts.widget.Bind","struts.widget.BindDiv","struts.widget.BindAnchor","struts.widget.ComboBox","struts.widget.StrutsTimePicker","struts.widget.StrutsDatePicker","struts.widget.BindEvent"]}); +dojo.provide("dojo.widget.TreeSelector"); +dojo.widget.defineWidget("dojo.widget.TreeSelector",dojo.widget.HtmlWidget,function(){ +this.eventNames={}; +this.listenedTrees=[]; +},{widgetType:"TreeSelector",selectedNode:null,dieWithTree:false,eventNamesDefault:{select:"select",destroy:"destroy",deselect:"deselect",dblselect:"dblselect"},initialize:function(){ +for(name in this.eventNamesDefault){ +if(dojo.lang.isUndefined(this.eventNames[name])){ +this.eventNames[name]=this.widgetId+"/"+this.eventNamesDefault[name]; +} +} +},destroy:function(){ +dojo.event.topic.publish(this.eventNames.destroy,{source:this}); +return dojo.widget.HtmlWidget.prototype.destroy.apply(this,arguments); +},listenTree:function(tree){ +dojo.event.topic.subscribe(tree.eventNames.titleClick,this,"select"); +dojo.event.topic.subscribe(tree.eventNames.iconClick,this,"select"); +dojo.event.topic.subscribe(tree.eventNames.collapse,this,"onCollapse"); +dojo.event.topic.subscribe(tree.eventNames.moveFrom,this,"onMoveFrom"); +dojo.event.topic.subscribe(tree.eventNames.removeNode,this,"onRemoveNode"); +dojo.event.topic.subscribe(tree.eventNames.treeDestroy,this,"onTreeDestroy"); +this.listenedTrees.push(tree); +},unlistenTree:function(tree){ +dojo.event.topic.unsubscribe(tree.eventNames.titleClick,this,"select"); +dojo.event.topic.unsubscribe(tree.eventNames.iconClick,this,"select"); +dojo.event.topic.unsubscribe(tree.eventNames.collapse,this,"onCollapse"); +dojo.event.topic.unsubscribe(tree.eventNames.moveFrom,this,"onMoveFrom"); +dojo.event.topic.unsubscribe(tree.eventNames.removeNode,this,"onRemoveNode"); +dojo.event.topic.unsubscribe(tree.eventNames.treeDestroy,this,"onTreeDestroy"); +for(var i=0;i - <#if parameters.treeSelectedTopic?exists || parameters.treeExpandedTopic?exists - || parameters.treeCollapsedTopic?exists> - <#assign eventNames = "" > - <#if parameters.treeSelectedTopic?exists> - <#assign eventNames = "select:" + parameters.treeSelectedTopic?html + ";"> - - <#if parameters.treeExpandedTopic?exists> - <#assign eventNames = eventNames + "expand:" + parameters.treeExpandedTopic?html + ";"> + <#if parameters.selectedNotifyTopics?exists || parameters.expandedNotifyTopics?exists + || parameters.collapsedNotifyTopics?exists> + + selectedNotifyTopics="${parameters.selectedNotifyTopics?html}" - <#if parameters.treeCollapsedTopic?exists> - <#assign eventNames = eventNames + "collapse:" + parameters.treeCollapsedTopic?html> + <#if parameters.expandedNotifyTopics?exists> + expandedNotifyTopics="${parameters.expandedNotifyTopics?html}" - + <#if parameters.collapsedNotifyTopics?exists> + collapsedNotifyTopics="${parameters.collapsedNotifyTopics?html}" + + >
id="${parameters.id?html}" - <#if parameters.treeSelectedTopic?exists> + <#if parameters.selectedNotifyTopics?exists || parameters.expandedNotifyTopics?exists + || parameters.collapsedNotifyTopics?exists> selector="treeSelector_${parameters.id?default("")}" <#if parameters.treeCollapsedTopic?exists>