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