+qx.Class.define("org.argeo.jcr.ria.views.TreeView", {\r
+ extend : qx.ui.container.Composite,\r
+ implement : [org.argeo.ria.components.IView], \r
+\r
+ properties : {\r
+ /**\r
+ * The commands definition Map that will be automatically added and wired to the menubar and toolbar.\r
+ * See {@link org.argeo.ria.event.CommandsManager#definitions} for the keys to use for defining commands.\r
+ */\r
+ commands : {\r
+ init : {\r
+ "zoom_in" : {\r
+ label : "Zoom To Node",\r
+ icon : "org.argeo.slc.ria/media-playback-start.png",\r
+ shortcut : null,\r
+ enabled : true,\r
+ menu : "Context",\r
+ toolbar : "context",\r
+ callback : function(e) {\r
+ var selection = this.tree.getSelection();\r
+ if(!selection.length) return;\r
+ var path = selection[0].getJcrNode().getPath();\r
+ this.getDataModel().requireContextChange(path);\r
+ },\r
+ selectionChange : function(viewId, selection){\r
+ if(viewId != "treeview") return;\r
+ if(!selection || !selection.length) return;\r
+ var treeNode = selection[0];\r
+ if(treeNode.getParent()!=null){\r
+ this.setEnabled(true);\r
+ }else{\r
+ this.setEnabled(false);\r
+ }\r
+ }\r
+ },\r
+ "zoom_out" : {\r
+ label : "Zoom Out",\r
+ icon : "org.argeo.slc.ria/media-playback-start.png",\r
+ shortcut : null,\r
+ enabled : true,\r
+ menu : "Context",\r
+ toolbar : "context",\r
+ submenu : [],\r
+ callback : function(e) {\r
+ },\r
+ submenuCallback : function(commandId){\r
+ this.getDataModel().requireContextChange(commandId);\r
+ },\r
+ selectionChange : function(viewId, selection){\r
+ if(viewId != "treeview") return;\r
+ if(!selection || !selection.length) return;\r
+ var treeNode = selection[0];\r
+ if(treeNode.getParent()!=null || treeNode.getJcrNode().itemIsRoot()){\r
+ this.setEnabled(false);\r
+ return;\r
+ }\r
+ this.setEnabled(true);\r
+ var nodePath = treeNode.getJcrNode().getPath();\r
+ var parts = nodePath.split("\/");\r
+ var pathes = [];\r
+ parts.pop();\r
+ if(parts.length > 1){\r
+ for(var i=0;i<parts.length;i++){\r
+ var newPath = parts.join("/");\r
+ pathes.push({label:newPath,icon:'', commandId:newPath});\r
+ parts.pop();\r
+ }\r
+ }\r
+ this.setMenu(pathes);\r
+ }\r
+ } \r
+ }\r
+ },\r
+ viewSelection : {\r
+ nullable:false, \r
+ check:"org.argeo.ria.components.ViewSelection"\r
+ },\r
+ instanceId : {\r
+ init:"treeView",\r
+ event : "changeInstanceId"\r
+ },\r
+ instanceLabel : {\r
+ init:"Tree View",\r
+ event : "changeInstanceLabel"\r
+ },\r
+ dataModel : {\r
+ \r
+ }\r
+ },\r
+ \r
+ construct : function(){\r
+ this.base(arguments);\r
+ },\r
+ \r
+ members : {\r
+ /**\r
+ * The implementation should contain the GUI initialisation.\r
+ * This is the role of the manager to actually add the graphical component to the pane, \r
+ * so it's not necessary to do it here. \r
+ * @param viewPane {org.argeo.ria.components.ViewPane} The pane manager\r
+ * @param data {Mixed} Any object or data passed by the initiator of the view\r
+ * @return {Boolean}\r
+ */\r
+ init : function(viewPane, dataModel){\r
+ this.setViewSelection(new org.argeo.ria.components.ViewSelection(viewPane.getViewId())); \r
+ this.setLayout(new qx.ui.layout.VBox());\r
+ this.setDataModel(dataModel);\r
+ \r
+ this.tree = new qx.ui.tree.Tree(); \r
+ this.add(this.tree, {flex:1});\r
+ },\r
+ /**\r
+ * The implementation should contain the real data loading (i.o. query...)\r
+ * @return {Boolean}\r
+ */\r
+ load : function(){\r
+ var dataModel = this.getDataModel();\r
+ dataModel.addListener("changeContextNode", function(event){\r
+ var contextNode = event.getData();\r
+ var loader = function(){};\r
+ var newRoot = new org.argeo.jcr.ria.views.JcrTreeFolder(contextNode);\r
+ this.tree.setRoot(newRoot);\r
+ this.tree.setSelection([newRoot]);\r
+ }, this);\r
+ this.tree.addListener("changeSelection", function(e){\r
+ var sel = this.tree.getSelection();\r
+ var selection = [];\r
+ var viewSelection = this.getViewSelection();\r
+ viewSelection.clear(); \r
+ for(var i=0;i<sel.length;i++){\r
+ selection.push(sel[i].getJcrNode());\r
+ viewSelection.addNode(sel[i]);\r
+ }\r
+ this.getDataModel().setSelection(selection);\r
+ }, this);\r
+ this.tree.setContextMenu(org.argeo.ria.event.CommandsManager\r
+ .getInstance().createMenuFromIds(["zoom_in", "zoom_out"])); \r
+ },\r
+ \r
+ /**\r
+ * Whether this component is already contained in a scroller (return false) or not (return true).\r
+ * @return {Boolean}\r
+ */\r
+ addScroll : function(){\r
+ return false;\r
+ },\r
+ /**\r
+ * Called at destruction time\r
+ * Perform all the clean operations (stopping polling queries, etc.) \r
+ */\r
+ close : function(){\r
+ \r
+ } \r
+ \r
+ }\r
+});
\ No newline at end of file