]>
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
1 qx
.Class
.define("org.argeo.jcr.ria.views.TreeView", {
2 extend
: qx
.ui
.container
.Composite
,
3 implement
: [org
.argeo
.ria
.components
.IView
],
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.
13 label
: "Zoom To Node",
14 icon
: "org.argeo.jcr.ria/zoom-in.png",
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
);
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);
32 this.setEnabled(false);
38 icon
: "org/argeo/jcr/ria/zoom-out.png",
44 callback : function(e
) {
46 submenuCallback : function(commandId
){
47 this.getDataModel().requireContextChange(commandId
);
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);
57 this.setEnabled(true);
58 var nodePath
= treeNode
.getJcrNode().getPath();
59 var parts
= nodePath
.split("\/");
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
});
70 this.setMenuDef(pathes
);
75 icon
: "org/argeo/jcr/ria/view-refresh.png",
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
]);
88 jcrNode
.setLoadState("empty");
91 selectionChange : function(viewId
, selection
){
92 this.setEnabled(false);
93 if(selection
&& selection
.length
&& selection
[0].getJcrNode
){
94 this.setEnabled(true);
100 icon
: "org.argeo.jcr.ria/document-open.png",
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
);
114 selectionChange : function(viewId
, selection
){
115 this.setEnabled(false);
116 if(selection
&& selection
.length
&& selection
[0].getJcrNode
){
117 this.setEnabled(true);
123 icon
: "org.argeo.jcr.ria/go-down.png",
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
);
135 selectionChange : function(viewId
, selection
){
136 this.setEnabled(false);
137 if(selection
&& selection
.length
&& selection
[0].getJcrNode
){
138 this.setEnabled(true);
146 check
:"org.argeo.ria.components.ViewSelection"
150 event
: "changeInstanceId"
154 event
: "changeInstanceLabel"
161 construct : function(){
162 this.base(arguments
);
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
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
);
179 this.tree
= new qx
.ui
.tree
.Tree();
180 this.add(this.tree
, {flex
:1});
183 * The implementation should contain the real data loading (i.o. query...)
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);
195 this.tree
.addListener("changeSelection", function(e
){
196 var sel
= this.tree
.getSelection();
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());
204 viewSelection
.addNode(sel
[i
]);
206 this.getDataModel().setSelectionWithSource(selection
, 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
]]);
225 }else if(crtTreeSel
.getParent() && crtTreeSel
.getJcrNode().getParent().getPath() == selection
[0].getPath()){
226 this.tree
.setSelection([crtTreeSel
.getParent()]);
230 this.tree
.setContextMenu(org
.argeo
.ria
.event
.CommandsManager
231 .getInstance().createMenuFromIds(["open", "dl", "refresh", "zoom_in", "zoom_out"]));
235 * Whether this component is already contained in a scroller (return false) or not (return true).
238 addScroll : function(){
242 * Called at destruction time
243 * Perform all the clean operations (stopping polling queries, etc.)