2 Copyright (C) 2000-2004 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
26 Take a look at WETreeView for more information.
28 WETreeData associations:
36 TreeDataCell: WETreeData {
37 isTreeElement = YES; // this is a tree cell (that means, it has plus
38 // and minus icons and all that stuff)
40 DataCell: WETreeData {
41 isTreeElement = NO; // this is NOT a tree cell, i.e. it does NOT
42 // have any plus or minus icons. (This is just a
43 // ordinary <td></td>!!!)
47 #include <NGObjWeb/WODynamicElement.h>
49 @interface WETreeData : WODynamicElement
51 // WODynamicElement: extraAttributes
52 // WODynamicElement: otherTagString
54 WOAssociation *isTreeElement;
56 WOAssociation *string;
58 WOAssociation *cornerIcon;
66 #include "WETreeContextKeys.h"
67 #include "WETreeMatrixElement.h"
70 @implementation WETreeData
72 static Class StrClass = Nil;
75 StrClass = [NSString class];
78 - (id)initWithName:(NSString *)_name
79 associations:(NSDictionary *)_config
80 template:(WOElement *)_root
82 if ((self = [super initWithName:_name associations:_config template:_root])){
83 self->isTreeElement = WOExtGetProperty(_config, @"isTreeElement");
84 self->icon = WOExtGetProperty(_config, @"icon");
85 self->cornerIcon = WOExtGetProperty(_config, @"cornerIcon");
86 self->title = WOExtGetProperty(_config, @"title");
87 self->string = WOExtGetProperty(_config, @"string");
89 self->template = [_root retain];
95 [self->isTreeElement release];
97 [self->cornerIcon release];
98 [self->title release];
99 [self->string release];
100 [self->template release];
104 /* HTML generation */
106 - (void)_appendIcon:(NSString *)_icon alt:(NSString *)_alt
107 toResponse:(WOResponse *)_response inContext:(WOContext *)_ctx
111 iconWidth = [_ctx objectForKey:WETreeView_IconWidth];
113 [_response appendContentString:@"<img border=\"0\" src=\""];
114 [_response appendContentHTMLAttributeValue:_icon];
115 [_response appendContentString:@"\""];
117 if ([iconWidth length] > 0) {
118 [_response appendContentString:@" width=\""];
119 [_response appendContentString:iconWidth];
120 [_response appendContentString:@"\""];
122 if ([_alt length] > 0) {
123 [_response appendContentString:@" alt=\""];
124 [_response appendContentHTMLAttributeValue:_alt];
125 [_response appendContentString:@"\""];
128 [_response appendContentString:@" />"];
131 - (void)_appendLink:(NSString *)_icon resp:(WOResponse *)_response
132 ctx:(WOContext *)_ctx
134 BOOL doForm = [_ctx isInForm];
139 [_response appendContentString:@"<input type=\"image\" border=\"0\""];
140 [_response appendContentString:@" align=\"top\" name=\""];
141 [_response appendContentString:[_ctx elementID]];
142 [_response appendContentString:@"\" src=\""];
143 [_response appendContentString:_icon];
144 [_response appendContentString:@"\" />"];
147 [_ctx appendElementIDComponent:WETreeView_ZOOM_ACTION_ID];
148 [_response appendContentString:@"<a href=\""];
149 [_response appendContentString:[_ctx componentActionURL]];
150 [_response appendContentString:@"\">"];
151 [self _appendIcon:_icon alt:@"z" toResponse:_response inContext:_ctx];
152 [_response appendContentString:@"</a>"];
153 [_ctx deleteLastElementIDComponent];
157 - (void)_appendTreeElement:(NSString *)_key
158 toResponse:(WOResponse *)_response
159 inContext:(WOContext *)_ctx
164 doLink = (_key == WETreeView_Plus || _key == WETreeView_CornerPlus ||
165 _key == WETreeView_Minus || _key == WETreeView_CornerMinus);
167 img = [_ctx objectForKey:_key];
168 img = WEUriOfResource(img, _ctx);
170 if (_key == WETreeView_Leaf) {
171 NSString *tmp = [self->icon stringValueInComponent:[_ctx component]];
173 tmp = WEUriOfResource(tmp, _ctx);
174 img = (tmp) ? tmp : img;
176 else if (_key == WETreeView_CornerLeaf) {
177 NSString *tmp = [self->cornerIcon stringValueInComponent:[_ctx component]];
178 tmp = WEUriOfResource(tmp, _ctx);
179 img = (tmp) ? tmp : img;
184 [_ctx appendElementIDComponent:WETreeView_ZOOM_ACTION_ID];
185 [_response appendContentString:@"<a href=\""];
186 [_response appendContentString:[_ctx componentActionURL]];
187 [_response appendContentString:@"\">"];
189 if (_key == WETreeView_Plus || _key == WETreeView_CornerPlus)
190 [_response appendContentString:@"<tt>[+]</tt>"];
191 else if (_key == WETreeView_Minus || _key == WETreeView_CornerMinus)
192 [_response appendContentString:@"<tt>[-]</tt>"];
194 [_response appendContentString:@"</a>"];
195 [_ctx deleteLastElementIDComponent];
197 else if (_key == WETreeView_Leaf)
198 [_response appendContentString:@"<tt>-- </tt>"];
199 else if (_key == WETreeView_CornerLeaf)
200 [_response appendContentString:@"<tt>-| </tt>"];
201 else if (_key == WETreeView_Line)
202 [_response appendContentString:@"<tt> | </tt>"];
203 else if (_key == WETreeView_CornerLeaf)
204 [_response appendContentString:@"<tt> --</tt>"];
205 else if (_key == WETreeView_Junction || _key == WETreeView_Corner)
206 [_response appendContentString:@"<tt> |-</tt>"];
207 else if (_key == WETreeView_Space)
208 [_response appendContentString:@"<tt> </tt>"];
212 [self _appendLink:img resp:_response ctx:_ctx];
214 [self _appendIcon:img alt:@"z" toResponse:_response inContext:_ctx];
218 - (void)appendHeader:(WOResponse *)_response inContext:(WOContext *)_ctx {
219 WOComponent *cmp = [_ctx component];
220 NSString *tmp = [self->title stringValueInComponent:cmp];
221 BOOL isTree = [self->isTreeElement boolValueInComponent:cmp];;
227 [_response appendContentString:@"<td"];
228 [self appendExtraAttributesToResponse:_response inContext:_ctx];
229 if (self->otherTagString) {
230 [_response appendContentString:
231 [self->otherTagString stringValueInComponent:
235 [_response appendContentString:@" colspan=\""];
236 [_response appendContentString:
237 [[_ctx objectForKey:WETreeView_HEADER_MODE] stringValue]];
238 [_response appendContentString:@"\"><nobr>"];
241 [_response appendContentString:@"><nobr>"];
244 [_response appendContentString:@"<b>"];
245 [_response appendContentHTMLString:tmp];
246 [_response appendContentString:@"</b>"];
249 [_response appendContentString:@"</nobr></td>"];
252 - (void)appendData:(WOResponse *)_response inContext:(WOContext *)_ctx {
253 /* TODO: split up this method */
254 _WETreeMatrixElement *treeElement;
255 WOComponent *cmp = nil;
257 NSString *content = nil;
260 cmp = [_ctx component];
261 isTree = [self->isTreeElement boolValueInComponent:cmp];
262 content = [self->string stringValueInComponent:cmp];
263 treeElement = [_ctx objectForKey:WETreeView_TreeElement];
266 for (i = 0; i < [treeElement depth]+1; i++) {
270 iconWidth = [_ctx objectForKey:WETreeView_IconWidth];
272 treeElm = (i < [treeElement depth])
273 ? [treeElement elementAtIndex:i]
274 : [treeElement leaf];
277 [_response appendContentString:@"<td"];
278 [self appendExtraAttributesToResponse:_response inContext:_ctx];
279 [_response appendContentString:@" valign=\"middle\" align=\"center\""];
283 s = [[StrClass alloc] initWithFormat:@" width=\"%@\"", iconWidth];
284 [_response appendContentString:s];
288 if (treeElm == WETreeView_Plus || treeElm == WETreeView_Minus ||
289 treeElm == WETreeView_Junction || treeElm == WETreeView_Line) {
292 img = [_ctx objectForKey:WETreeView_Line];
293 img = WEUriOfResource(img, _ctx);
295 [_response appendContentString:@" background=\""];
296 [_response appendContentString:img];
297 [_response appendContentCharacter:'"'];
300 [_response appendContentString:@"><nobr>"];
303 [self _appendTreeElement:treeElm toResponse:_response inContext:_ctx];
305 [_response appendContentString:@"</nobr></td>"];
309 [_response appendContentString:@"<td"];
310 [self appendExtraAttributesToResponse:_response inContext:_ctx];
311 [_response appendContentString:@" width='97%'"];
312 [_response appendContentString:@" valign='middle' align='left'"];
313 [_response appendContentString:@" colspan=\""];
314 [_response appendContentString:[treeElement colspanAsString]];
315 [_response appendContentString:@"\">"];
318 /* add cell content */
319 [self->template appendToResponse:_response inContext:_ctx];
321 [_response appendContentHTMLString:content];
324 [_response appendContentString:@"</td>"];
328 [_response appendContentString:@"<td"];
329 [self appendExtraAttributesToResponse:_response inContext:_ctx];
330 if (self->otherTagString) {
331 [_response appendContentString:
332 [self->otherTagString stringValueInComponent:
335 [_response appendContentCharacter:'>'];
338 /* add cell content */
339 [self->template appendToResponse:_response inContext:_ctx];
340 if (content) [_response appendContentHTMLString:content];
343 [_response appendContentString:@"</td>"];
347 - (void)takeValuesFromRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
348 [self->template takeValuesFromRequest:_rq inContext:_ctx];
351 - (id)invokeActionForRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
352 return [self->template invokeActionForRequest:_rq inContext:_ctx];
355 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
356 self->doTable = ([_ctx objectForKey:WETreeView_RenderNoTable] == nil);
358 if ([_ctx objectForKey:WETreeView_HEADER_MODE])
359 [self appendHeader:_response inContext:_ctx];
361 [self appendData:_response inContext:_ctx];
364 @end /* WETreeData */