+++ /dev/null
-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.jcr.ria/zoom-in.png",\r
- shortcut : null,\r
- enabled : true,\r
- menu : "Zoom",\r
- toolbar : null,\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/jcr/ria/zoom-out.png",\r
- shortcut : null,\r
- enabled : true,\r
- menu : "Zoom",\r
- toolbar : null,\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
- var initLength = parts.length; \r
- for(var i=0;i<initLength;i++){\r
- var newPath = parts.join("/");\r
- pathes.push({label:newPath,icon:'org.argeo.jcr.ria/folder_16.png', commandId:newPath});\r
- parts.pop();\r
- }\r
- }\r
- this.setMenuDef(pathes);\r
- }\r
- },\r
- "refresh" : {\r
- label : "Refresh",\r
- icon : "org/argeo/jcr/ria/view-refresh.png",\r
- shortcut : null,\r
- enabled : true,\r
- menu : "Selection",\r
- toolbar : "selection",\r
- callback : function(e) {\r
- var selection = this.tree.getSelection();\r
- if(!selection.length) return;\r
- var jcrNode = selection[0].getJcrNode();\r
- var children = jcrNode.getChildren();\r
- for(var i=0;i<children.length;i++){\r
- jcrNode.removeChild(children[i]);\r
- }\r
- jcrNode.setLoadState("empty");\r
- jcrNode.load();\r
- },\r
- selectionChange : function(viewId, selection){\r
- this.setEnabled(false);\r
- if(selection && selection.length && selection[0].getJcrNode){\r
- this.setEnabled(true);\r
- }\r
- }\r
- },\r
- "open" : {\r
- label : "Open",\r
- icon : "org.argeo.jcr.ria/document-open.png",\r
- shortcut : null,\r
- enabled : true,\r
- menu : "Selection",\r
- toolbar : "selection",\r
- callback : function(e) {\r
- var selection = this.tree.getSelection();\r
- if(!selection.length) return;\r
- var jcrNode = selection[0].getJcrNode();\r
- var viewsManager = org.argeo.ria.components.ViewsManager.getInstance(); \r
- var testView = viewsManager.initIViewClass(org.argeo.jcr.ria.views.PlainXmlViewer, "editor", jcrNode, "close");\r
- testView.load(jcrNode);\r
- \r
- },\r
- selectionChange : function(viewId, selection){\r
- this.setEnabled(false);\r
- if(selection && selection.length && selection[0].getJcrNode){\r
- this.setEnabled(true);\r
- }\r
- }\r
- },\r
- "dl" : {\r
- label : "Download",\r
- icon : "org.argeo.jcr.ria/go-down.png",\r
- shortcut : null,\r
- enabled : true,\r
- menu : "Selection",\r
- toolbar : "selection",\r
- callback : function(e) {\r
- var selection = this.tree.getSelection();\r
- if(!selection.length) return;\r
- var jcrNode = selection[0].getJcrNode();\r
- var url = '/org.argeo.slc.webapp/getJcrItem.jcr?path=' + jcrNode.getPath() + '&download=true';\r
- org.argeo.ria.Application.INSTANCE.javascriptDownloadLocation(url);\r
- },\r
- selectionChange : function(viewId, selection){\r
- this.setEnabled(false);\r
- if(selection && selection.length && selection[0].getJcrNode){\r
- this.setEnabled(true);\r
- }\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:"JCR Tree",\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 newRoot = new org.argeo.jcr.ria.views.JcrTreeFolder(contextNode);\r
- this.tree.setRoot(newRoot);\r
- this.tree.setSelection([newRoot]);\r
- newRoot.setOpen(true);\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
- if(sel[i].getJcrNode){\r
- selection.push(sel[i].getJcrNode());\r
- }\r
- viewSelection.addNode(sel[i]);\r
- }\r
- this.getDataModel().setSelectionWithSource(selection, this);\r
- }, this);\r
- dataModel.addListener("changeSelection", function(e){\r
- if(this.getDataModel().getSelectionSource() == this) return;\r
- var selection = this.getDataModel().getSelection();\r
- // Arbitrary : for the moment, external select can only apply\r
- // to children of the current selection\r
- var crtSel = this.tree.getSelection();\r
- if(!crtSel.length || !selection.length) return;\r
- var crtTreeSel = crtSel[0];\r
- if(selection[0].getParent() && crtTreeSel.getJcrNode().getPath() == selection[0].getParent().getPath()){\r
- crtTreeSel.setOpen(true);\r
- var crtChildren =crtTreeSel.getChildren(); \r
- for(var i=0;i<crtChildren.length;i++){\r
- if(crtChildren[i].getJcrNode().getPath() == selection[0].getPath()){\r
- this.tree.setSelection([crtChildren[i]]);\r
- return;\r
- }\r
- }\r
- }else if(crtTreeSel.getParent() && crtTreeSel.getJcrNode().getParent().getPath() == selection[0].getPath()){\r
- this.tree.setSelection([crtTreeSel.getParent()]);\r
- }\r
- \r
- }, this);\r
- this.tree.setContextMenu(org.argeo.ria.event.CommandsManager\r
- .getInstance().createMenuFromIds(["open", "dl", "refresh", "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