]>
git.argeo.org Git - gpl/argeo-slc.git/blob - TreeView.js
ee17460f99abda63059af94eb9b26253725967fb
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.slc.ria/media-playback-start.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.slc.ria/media-playback-start.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
:'', commandId
:newPath
});
75 icon
: "org.argeo.slc.ria/media-playback-start.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 viewsManager
= org
.argeo
.ria
.components
.ViewsManager
.getInstance();
85 var testView
= viewsManager
.initIViewClass(org
.argeo
.jcr
.ria
.views
.PlainXmlViewer
, "editor", jcrNode
);
86 testView
.load(jcrNode
);
89 selectionChange : function(viewId
, selection
){
90 this.setEnabled(false);
91 if(selection
&& selection
.length
&& selection
[0].getJcrNode
){
92 this.setEnabled(true);
98 icon
: "org.argeo.slc.ria/media-playback-start.png",
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
);
110 selectionChange : function(viewId
, selection
){
111 this.setEnabled(false);
112 if(selection
&& selection
.length
&& selection
[0].getJcrNode
){
113 this.setEnabled(true);
121 check
:"org.argeo.ria.components.ViewSelection"
125 event
: "changeInstanceId"
129 event
: "changeInstanceLabel"
136 construct : function(){
137 this.base(arguments
);
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
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
);
154 this.tree
= new qx
.ui
.tree
.Tree();
155 this.add(this.tree
, {flex
:1});
158 * The implementation should contain the real data loading (i.o. query...)
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
]);
169 this.tree
.addListener("changeSelection", function(e
){
170 var sel
= this.tree
.getSelection();
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
]);
178 this.getDataModel().setSelectionWithSource(selection
, 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
]]);
197 }else if(crtTreeSel
.getParent() && crtTreeSel
.getJcrNode().getParent().getPath() == selection
[0].getPath()){
198 this.tree
.setSelection([crtTreeSel
.getParent()]);
202 this.tree
.setContextMenu(org
.argeo
.ria
.event
.CommandsManager
203 .getInstance().createMenuFromIds(["open", "zoom_in", "zoom_out"]));
207 * Whether this component is already contained in a scroller (return false) or not (return true).
210 addScroll : function(){
214 * Called at destruction time
215 * Perform all the clean operations (stopping polling queries, etc.)