]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.webapp/src/main/webapp/source/class/org/argeo/ria/components/ViewPane.js
b56b5b1f63771e2aa140f1f55b6c0cf3055f404e
[gpl/argeo-slc.git] / org.argeo.slc.webapp / src / main / webapp / source / class / org / argeo / ria / components / ViewPane.js
1 /**
2 * A standard view container, referenced in the application by its unique id.
3 * It is managed by the ViewsManager singleton that works as the "View" part of an MVC model.
4 * @see org.argeo.ria.components.ViewsManager
5 * @author Charles
6 */
7 qx.Class.define("org.argeo.ria.components.ViewPane",
8 {
9 extend : qx.ui.container.Composite,
10 implement : [org.argeo.ria.components.ILoadStatusable],
11
12 /**
13 * @param viewId {String} Unique id of this viewPane
14 * @param viewTitle {String} Readable Title of this viewPane
15 * @param splitPaneData {Map} Additionnal data to be used by splitpanes implementations.
16 */
17 construct : function(viewId, viewTitle, splitPaneData){
18 this.base(arguments);
19 this.setViewId(viewId);
20 this._defaultViewTitle = viewTitle;
21 this.setViewTitle(viewTitle);
22 var viewSelection = new org.argeo.ria.components.ViewSelection(viewId);
23 this.setViewSelection(viewSelection);
24 if(splitPaneData){
25 this.setSplitPaneData(splitPaneData);
26 }
27 this.createGui();
28 },
29
30 properties :
31 {
32 /**
33 * Unique id of the pane
34 */
35 viewId : {init:""},
36 /**
37 * Human-readable title for this view
38 */
39 viewTitle : {init:"", event:"changeViewTitle"},
40 /**
41 * Selection model for this view
42 */
43 viewSelection : { nullable:false, check:"org.argeo.ria.components.ViewSelection" },
44 /**
45 * Has its own scrollable content
46 */
47 ownScrollable : {init: false, check:"Boolean"},
48 /**
49 * Data concerning the split pane
50 */
51 splitPaneData : {init : null, check:"Map"},
52 /**
53 * Map of commands definition
54 * @see org.argeo.ria.event.Command
55 */
56 commands : {init : null, nullable:true, check:"Map"}
57 },
58
59 /*
60 *****************************************************************************
61 MEMBERS
62 *****************************************************************************
63 */
64
65 members :
66 {
67 /**
68 * Creates a standard GUI for the viewPane, including a container for an IView.
69 */
70 createGui : function(){
71 this.setLayout(new qx.ui.layout.VBox());
72 this.header = new qx.ui.container.Composite();
73 this.header.setLayout(new qx.ui.layout.Dock());
74 this.loadImage = new qx.ui.basic.Image('resource/slc/ajax-loader.gif');
75 this.header.set({appearance:"app-header", height:34});
76 this.headerLabel = new qx.ui.basic.Label(this.getViewTitle());
77 this.header.add(this.headerLabel, {edge:"west"});
78 this.addListener("changeViewTitle", function(e){
79 var newTitle = e.getData();
80 if(newTitle != ""){
81 this.headerLabel.setContent(newTitle);
82 if(e.getOldData() == ""){
83 this.header.add(this.headerLabel, {edge:"west"});
84 }
85 }else{
86 this.header.remove(this.headerLabel);
87 }
88 }, this);
89 this.add(this.header);
90 this.setDecorator(new qx.ui.decoration.Single(1,"solid","#000"));
91 /*
92 // Open close button of splitPane, not very useful at the moment.
93 if(this.getSplitPaneData()){
94 var data = this.getSplitPaneData();
95 var imgName = (data.orientation=="horizontal"?"go-left":"go-bottom");
96 var image = new qx.ui.basic.Image("resource/slc/"+imgName+".png");
97 image.addListener("click", function(e){
98 var image = e.getTarget();
99 var data = this.getSplitPaneData();
100 var functionDim = (data.orientation=="horizontal"?"Width":"Height");
101 var objectToResize = data.object || this;
102 var crtDim = objectToResize["get"+functionDim]();
103 var minimize = (data.orientation=="horizontal"?"go-right":"go-top");
104 var maximize = (data.orientation=="horizontal"?"go-left":"go-bottom");
105 if(crtDim > data.min){
106 objectToResize["set"+functionDim](data.min);
107 image.setSource("resource/slc/"+minimize+".png");
108 this.origDimension = crtDim;
109 }else{
110 if(this.origDimension){
111 objectToResize["set"+functionDim](this.origDimension);
112 image.setSource("resource/slc/"+maximize+".png");
113 }
114 }
115 }, this);
116 this.header.add(image,{edge:"east"});
117 }
118 */
119 },
120
121 /**
122 * Sets the content of this pane.
123 * @param content {org.argeo.ria.components.IView} An IView implementation
124 */
125 setContent : function(content){
126 var addScrollable = (content.addScroll?content.addScroll():false);
127 if(addScrollable){
128 this.setOwnScrollable(true);
129 this.scrollable = new qx.ui.container.Scroll(content);
130 this.add(this.scrollable, {flex: 1});
131 }else{
132 this.content = content;
133 this.add(this.content, {flex:1});
134 }
135 },
136
137 addHeaderComponent : function(component){
138 this.header.setPadding(4);
139 this.header.add(component, {edge:"center"});
140 this.loadImage.setMargin(4);
141 },
142
143 /**
144 * Implementation of the ILoadStatusable interface.
145 * @see org.argeo.ria.components.ILoadStatusable
146 * @param load {Boolean} The loading status
147 */
148 setOnLoad : function(load){
149 if(load){
150 this.header.add(this.loadImage, {edge:"east"});
151 }else{
152 this.header.remove(this.loadImage);
153 }
154 },
155
156 /**
157 * Removes and destroy the IView content of this viewPane.
158 */
159 empty: function(){
160 if(this.getOwnScrollable() && this.scrollable){
161 this.remove(this.scrollable);
162 }else if(this.content){
163 this.remove(this.content);
164 }
165 if(this.getCommands()){
166 org.argeo.ria.event.CommandsManager.getInstance().removeCommands(this.getCommands());
167 this.setCommands(null);
168 }
169 this.setViewTitle(this._defaultViewTitle);
170 }
171
172 }
173 });