]> 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/ListView.js
Move icons
[gpl/argeo-slc.git] / server / org.argeo.slc.ria / src / argeo-ria-lib / jcr / class / org / argeo / jcr / ria / views / ListView.js
1 qx.Class.define("org.argeo.jcr.ria.views.ListView", {
2 extend : qx.ui.container.Composite,
3 implement : [org.argeo.ria.components.IView],
4 properties : {
5 /**
6 * The commands definition Map that will be automatically added and wired to the menubar and toolbar.
7 * See {@link org.argeo.ria.event.CommandsManager#definitions} for the keys to use for defining commands.
8 */
9 commands : {
10 init : {}
11 },
12 viewSelection : {
13 nullable:false,
14 check:"org.argeo.ria.components.ViewSelection"
15 },
16 instanceId : {
17 init:"listView",
18 event : "changeInstanceId"
19 },
20 instanceLabel : {
21 init:"Nodes List",
22 event : "changeInstanceLabel"
23 },
24 dataModel : {
25
26 }
27 },
28
29 construct : function(){
30 this.base(arguments);
31 },
32
33 members : {
34 /**
35 * The implementation should contain the GUI initialisation.
36 * This is the role of the manager to actually add the graphical component to the pane,
37 * so it's not necessary to do it here.
38 * @param viewPane {org.argeo.ria.components.ViewPane} The pane manager
39 * @param data {Mixed} Any object or data passed by the initiator of the view
40 * @return {Boolean}
41 */
42 init : function(viewPane, dataModel){
43 this.setViewSelection(new org.argeo.ria.components.ViewSelection(viewPane.getViewId()));
44 this.setLayout(new qx.ui.layout.VBox());
45 this.setDataModel(dataModel);
46
47 var split = new qx.ui.splitpane.Pane("vertical");
48 split.setDecorator(null);
49 this.add(split, {flex:1});
50
51 this.list = new qx.ui.form.List();
52 split.add(this.list,1);
53
54 this.propInput = new qx.ui.form.TextArea();
55 split.add(this.propInput,1);
56 var call = new qx.util.DeferredCall(function(){
57 qx.bom.element.Style.set(this.propInput.getContentElement().getDomElement(), "lineHeight", "1.8");
58 }, this);
59 call.schedule();
60 },
61 /**
62 * The implementation should contain the real data loading (i.o. query...)
63 * @return {Boolean}
64 */
65 load : function(){
66 var dataModel = this.getDataModel();
67 dataModel.addListener("changeSelection", function(event){
68 if(dataModel.getSelectionSource() == this) return;
69 var selection = event.getData();
70 this.list.removeAll();
71 if(!selection.length) {
72 return;
73 }
74 var contextNode = selection[0];
75 this._parseNode(contextNode);
76 }, this);
77 },
78
79 _parseNode : function (jcrNode){
80 if(jcrNode.getLoadState() == "loaded"){
81 this.list.removeAll();
82 if(jcrNode.getParent()){
83 this.list.add(this._initListItem(jcrNode.getParent(), ".."));
84 }
85 var children = jcrNode.getChildren();
86 for(var i=0;i<children.length;i++){
87 this.list.add(this._initListItem(children[i]));
88 }
89 if(this.list.hasChildren()){
90 this.list.setSelection([this.list.getChildren()[0]]);
91 }
92 var properties = jcrNode.getProperties();
93 var propString = "";
94 for(var i=0;i<properties.length;i++){
95 propString += properties[i].getName()+"="+properties[i].getValue()+"\n";
96 }
97 this.propInput.setValue(propString);
98 }else{
99 var listener = function(event){
100 if(event.getData() == "loaded"){
101 this._parseNode(jcrNode);
102 jcrNode.removeListener("changeLoadState", listener, this);
103 }
104 };
105 jcrNode.addListener("changeLoadState", listener, this);
106 if(jcrNode.getLoadState() != "loading"){
107 jcrNode.load();
108 }
109 }
110 },
111
112 _initListItem : function(jcrNode, label){
113 var li = new qx.ui.form.ListItem((label?label:jcrNode.getName()), "org.argeo.jcr.ria/folder.png");
114 li.setModel(jcrNode);
115 li.addListener("dblclick", function(){
116 this.getDataModel().setSelectionWithSource([jcrNode], this);
117 }, this);
118 return li;
119 },
120
121 /**
122 * Whether this component is already contained in a scroller (return false) or not (return true).
123 * @return {Boolean}
124 */
125 addScroll : function(){
126 return false;
127 },
128 /**
129 * Called at destruction time
130 * Perform all the clean operations (stopping polling queries, etc.)
131 */
132 close : function(){
133
134 }
135
136 }
137 });