]> git.argeo.org Git - gpl/argeo-slc.git/blob - TreeView.js
233c316d941b04937b9cfb228ca57e1ee3860191
[gpl/argeo-slc.git] / TreeView.js
1 qx.Class.define("org.argeo.jcr.ria.views.TreeView", {
2 extend : qx.ui.container.Composite,
3 implement : [org.argeo.ria.components.IView],
4
5 properties : {
6 /**
7 * The commands definition Map that will be automatically added and wired to the menubar and toolbar.
8 * See {@link org.argeo.ria.event.CommandsManager#definitions} for the keys to use for defining commands.
9 */
10 commands : {
11 init : {
12 "zoom_in" : {
13 label : "Zoom To Node",
14 icon : "org.argeo.slc.ria/media-playback-start.png",
15 shortcut : null,
16 enabled : true,
17 menu : "Context",
18 toolbar : "context",
19 callback : function(e) {
20 var selection = this.tree.getSelection();
21 if(!selection.length) return;
22 var path = selection[0].getJcrNode().getPath();
23 this.getDataModel().requireContextChange(path);
24 },
25 selectionChange : function(viewId, selection){
26 if(viewId != "treeview") return;
27 if(!selection || !selection.length) return;
28 var treeNode = selection[0];
29 if(treeNode.getParent()!=null){
30 this.setEnabled(true);
31 }else{
32 this.setEnabled(false);
33 }
34 }
35 },
36 "zoom_out" : {
37 label : "Zoom Out",
38 icon : "org.argeo.slc.ria/media-playback-start.png",
39 shortcut : null,
40 enabled : true,
41 menu : "Context",
42 toolbar : "context",
43 submenu : [],
44 callback : function(e) {
45 },
46 submenuCallback : function(commandId){
47 this.getDataModel().requireContextChange(commandId);
48 },
49 selectionChange : function(viewId, selection){
50 if(viewId != "treeview") return;
51 if(!selection || !selection.length) return;
52 var treeNode = selection[0];
53 if(treeNode.getParent()!=null || treeNode.getJcrNode().itemIsRoot()){
54 this.setEnabled(false);
55 return;
56 }
57 this.setEnabled(true);
58 var nodePath = treeNode.getJcrNode().getPath();
59 var parts = nodePath.split("\/");
60 var pathes = [];
61 parts.pop();
62 if(parts.length > 1){
63 for(var i=0;i<parts.length;i++){
64 var newPath = parts.join("/");
65 pathes.push({label:newPath,icon:'', commandId:newPath});
66 parts.pop();
67 }
68 }
69 this.setMenu(pathes);
70 }
71 }
72 }
73 },
74 viewSelection : {
75 nullable:false,
76 check:"org.argeo.ria.components.ViewSelection"
77 },
78 instanceId : {
79 init:"treeView",
80 event : "changeInstanceId"
81 },
82 instanceLabel : {
83 init:"Tree View",
84 event : "changeInstanceLabel"
85 },
86 dataModel : {
87
88 }
89 },
90
91 construct : function(){
92 this.base(arguments);
93 },
94
95 members : {
96 /**
97 * The implementation should contain the GUI initialisation.
98 * This is the role of the manager to actually add the graphical component to the pane,
99 * so it's not necessary to do it here.
100 * @param viewPane {org.argeo.ria.components.ViewPane} The pane manager
101 * @param data {Mixed} Any object or data passed by the initiator of the view
102 * @return {Boolean}
103 */
104 init : function(viewPane, dataModel){
105 this.setViewSelection(new org.argeo.ria.components.ViewSelection(viewPane.getViewId()));
106 this.setLayout(new qx.ui.layout.VBox());
107 this.setDataModel(dataModel);
108
109 this.tree = new qx.ui.tree.Tree();
110 this.add(this.tree, {flex:1});
111 },
112 /**
113 * The implementation should contain the real data loading (i.o. query...)
114 * @return {Boolean}
115 */
116 load : function(){
117 var dataModel = this.getDataModel();
118 dataModel.addListener("changeContextNode", function(event){
119 var contextNode = event.getData();
120 var loader = function(){};
121 var newRoot = new org.argeo.jcr.ria.views.JcrTreeFolder(contextNode);
122 this.tree.setRoot(newRoot);
123 this.tree.setSelection([newRoot]);
124 }, this);
125 this.tree.addListener("changeSelection", function(e){
126 var sel = this.tree.getSelection();
127 var selection = [];
128 var viewSelection = this.getViewSelection();
129 viewSelection.clear();
130 for(var i=0;i<sel.length;i++){
131 selection.push(sel[i].getJcrNode());
132 viewSelection.addNode(sel[i]);
133 }
134 this.getDataModel().setSelection(selection);
135 }, this);
136 this.tree.setContextMenu(org.argeo.ria.event.CommandsManager
137 .getInstance().createMenuFromIds(["zoom_in", "zoom_out"]));
138 },
139
140 /**
141 * Whether this component is already contained in a scroller (return false) or not (return true).
142 * @return {Boolean}
143 */
144 addScroll : function(){
145 return false;
146 },
147 /**
148 * Called at destruction time
149 * Perform all the clean operations (stopping polling queries, etc.)
150 */
151 close : function(){
152
153 }
154
155 }
156 });