]> git.argeo.org Git - gpl/argeo-slc.git/blob - TreeView.js
ee17460f99abda63059af94eb9b26253725967fb
[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 : "Zoom",
18 toolbar : "zoom",
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 : "Zoom",
42 toolbar : "zoom",
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 var initLength = parts.length;
64 for(var i=0;i<initLength;i++){
65 var newPath = parts.join("/");
66 pathes.push({label:newPath,icon:'', commandId:newPath});
67 parts.pop();
68 }
69 }
70 this.setMenu(pathes);
71 }
72 },
73 "open" : {
74 label : "Open",
75 icon : "org.argeo.slc.ria/media-playback-start.png",
76 shortcut : null,
77 enabled : true,
78 menu : "Selection",
79 toolbar : "selection",
80 callback : function(e) {
81 var selection = this.tree.getSelection();
82 if(!selection.length) return;
83 var jcrNode = selection[0].getJcrNode();
84 var viewsManager = org.argeo.ria.components.ViewsManager.getInstance();
85 var testView = viewsManager.initIViewClass(org.argeo.jcr.ria.views.PlainXmlViewer, "editor", jcrNode);
86 testView.load(jcrNode);
87
88 },
89 selectionChange : function(viewId, selection){
90 this.setEnabled(false);
91 if(selection && selection.length && selection[0].getJcrNode){
92 this.setEnabled(true);
93 }
94 }
95 },
96 "dl" : {
97 label : "Download",
98 icon : "org.argeo.slc.ria/media-playback-start.png",
99 shortcut : null,
100 enabled : true,
101 menu : "Selection",
102 toolbar : "selection",
103 callback : function(e) {
104 var selection = this.tree.getSelection();
105 if(!selection.length) return;
106 var jcrNode = selection[0].getJcrNode();
107 var url = '/org.argeo.slc.webapp/getJcrItem.jcr?path=' + jcrNode.getPath() + '&download=true';
108 org.argeo.ria.Application.INSTANCE.javascriptDownloadLocation(url);
109 },
110 selectionChange : function(viewId, selection){
111 this.setEnabled(false);
112 if(selection && selection.length && selection[0].getJcrNode){
113 this.setEnabled(true);
114 }
115 }
116 }
117 }
118 },
119 viewSelection : {
120 nullable:false,
121 check:"org.argeo.ria.components.ViewSelection"
122 },
123 instanceId : {
124 init:"treeView",
125 event : "changeInstanceId"
126 },
127 instanceLabel : {
128 init:"Full Tree",
129 event : "changeInstanceLabel"
130 },
131 dataModel : {
132
133 }
134 },
135
136 construct : function(){
137 this.base(arguments);
138 },
139
140 members : {
141 /**
142 * The implementation should contain the GUI initialisation.
143 * This is the role of the manager to actually add the graphical component to the pane,
144 * so it's not necessary to do it here.
145 * @param viewPane {org.argeo.ria.components.ViewPane} The pane manager
146 * @param data {Mixed} Any object or data passed by the initiator of the view
147 * @return {Boolean}
148 */
149 init : function(viewPane, dataModel){
150 this.setViewSelection(new org.argeo.ria.components.ViewSelection(viewPane.getViewId()));
151 this.setLayout(new qx.ui.layout.VBox());
152 this.setDataModel(dataModel);
153
154 this.tree = new qx.ui.tree.Tree();
155 this.add(this.tree, {flex:1});
156 },
157 /**
158 * The implementation should contain the real data loading (i.o. query...)
159 * @return {Boolean}
160 */
161 load : function(){
162 var dataModel = this.getDataModel();
163 dataModel.addListener("changeContextNode", function(event){
164 var contextNode = event.getData();
165 var newRoot = new org.argeo.jcr.ria.views.JcrTreeFolder(contextNode);
166 this.tree.setRoot(newRoot);
167 this.tree.setSelection([newRoot]);
168 }, this);
169 this.tree.addListener("changeSelection", function(e){
170 var sel = this.tree.getSelection();
171 var selection = [];
172 var viewSelection = this.getViewSelection();
173 viewSelection.clear();
174 for(var i=0;i<sel.length;i++){
175 selection.push(sel[i].getJcrNode());
176 viewSelection.addNode(sel[i]);
177 }
178 this.getDataModel().setSelectionWithSource(selection, this);
179 }, this);
180 dataModel.addListener("changeSelection", function(e){
181 if(this.getDataModel().getSelectionSource() == this) return;
182 var selection = this.getDataModel().getSelection();
183 // Arbitrary : for the moment, external select can only apply
184 // to children of the current selection
185 var crtSel = this.tree.getSelection();
186 if(!crtSel.length || !selection.length) return;
187 var crtTreeSel = crtSel[0];
188 if(selection[0].getParent() && crtTreeSel.getJcrNode().getPath() == selection[0].getParent().getPath()){
189 crtTreeSel.setOpen(true);
190 var crtChildren =crtTreeSel.getChildren();
191 for(var i=0;i<crtChildren.length;i++){
192 if(crtChildren[i].getJcrNode().getPath() == selection[0].getPath()){
193 this.tree.setSelection([crtChildren[i]]);
194 return;
195 }
196 }
197 }else if(crtTreeSel.getParent() && crtTreeSel.getJcrNode().getParent().getPath() == selection[0].getPath()){
198 this.tree.setSelection([crtTreeSel.getParent()]);
199 }
200
201 }, this);
202 this.tree.setContextMenu(org.argeo.ria.event.CommandsManager
203 .getInstance().createMenuFromIds(["open", "zoom_in", "zoom_out"]));
204 },
205
206 /**
207 * Whether this component is already contained in a scroller (return false) or not (return true).
208 * @return {Boolean}
209 */
210 addScroll : function(){
211 return false;
212 },
213 /**
214 * Called at destruction time
215 * Perform all the clean operations (stopping polling queries, etc.)
216 */
217 close : function(){
218
219 }
220
221 }
222 });