]> 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
1dff09f3749ac81a85828d2f142f113bf7d17af7
[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.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
91 }
92 }
93 }
94 },
95 viewSelection : {
96 nullable:false,
97 check:"org.argeo.ria.components.ViewSelection"
98 },
99 instanceId : {
100 init:"treeView",
101 event : "changeInstanceId"
102 },
103 instanceLabel : {
104 init:"Full Tree",
105 event : "changeInstanceLabel"
106 },
107 dataModel : {
108
109 }
110 },
111
112 construct : function(){
113 this.base(arguments);
114 },
115
116 members : {
117 /**
118 * The implementation should contain the GUI initialisation.
119 * This is the role of the manager to actually add the graphical component to the pane,
120 * so it's not necessary to do it here.
121 * @param viewPane {org.argeo.ria.components.ViewPane} The pane manager
122 * @param data {Mixed} Any object or data passed by the initiator of the view
123 * @return {Boolean}
124 */
125 init : function(viewPane, dataModel){
126 this.setViewSelection(new org.argeo.ria.components.ViewSelection(viewPane.getViewId()));
127 this.setLayout(new qx.ui.layout.VBox());
128 this.setDataModel(dataModel);
129
130 this.tree = new qx.ui.tree.Tree();
131 this.add(this.tree, {flex:1});
132 },
133 /**
134 * The implementation should contain the real data loading (i.o. query...)
135 * @return {Boolean}
136 */
137 load : function(){
138 var dataModel = this.getDataModel();
139 dataModel.addListener("changeContextNode", function(event){
140 var contextNode = event.getData();
141 var newRoot = new org.argeo.jcr.ria.views.JcrTreeFolder(contextNode);
142 this.tree.setRoot(newRoot);
143 this.tree.setSelection([newRoot]);
144 }, this);
145 this.tree.addListener("changeSelection", function(e){
146 var sel = this.tree.getSelection();
147 var selection = [];
148 var viewSelection = this.getViewSelection();
149 viewSelection.clear();
150 for(var i=0;i<sel.length;i++){
151 selection.push(sel[i].getJcrNode());
152 viewSelection.addNode(sel[i]);
153 }
154 this.getDataModel().setSelectionWithSource(selection, this);
155 }, this);
156 dataModel.addListener("changeSelection", function(e){
157 if(this.getDataModel().getSelectionSource() == this) return;
158 var selection = this.getDataModel().getSelection();
159 // Arbitrary : for the moment, external select can only apply
160 // to children of the current selection
161 var crtSel = this.tree.getSelection();
162 if(!crtSel.length || !selection.length) return;
163 var crtTreeSel = crtSel[0];
164 if(selection[0].getParent() && crtTreeSel.getJcrNode().getPath() == selection[0].getParent().getPath()){
165 crtTreeSel.setOpen(true);
166 var crtChildren =crtTreeSel.getChildren();
167 for(var i=0;i<crtChildren.length;i++){
168 if(crtChildren[i].getJcrNode().getPath() == selection[0].getPath()){
169 this.tree.setSelection([crtChildren[i]]);
170 return;
171 }
172 }
173 }else if(crtTreeSel.getParent() && crtTreeSel.getJcrNode().getParent().getPath() == selection[0].getPath()){
174 this.tree.setSelection([crtTreeSel.getParent()]);
175 }
176
177 }, this);
178 this.tree.setContextMenu(org.argeo.ria.event.CommandsManager
179 .getInstance().createMenuFromIds(["open", "zoom_in", "zoom_out"]));
180 },
181
182 /**
183 * Whether this component is already contained in a scroller (return false) or not (return true).
184 * @return {Boolean}
185 */
186 addScroll : function(){
187 return false;
188 },
189 /**
190 * Called at destruction time
191 * Perform all the clean operations (stopping polling queries, etc.)
192 */
193 close : function(){
194
195 }
196
197 }
198 });