2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE 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 SOPE 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 SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 Take a look at WETreeView for more information.
27 WETreeData associations:
33 treeLink (do not generate a -componentActionURL but use the specified link)
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;
59 WOAssociation *treeLink;
67 #include "WETreeContextKeys.h"
68 #include "WETreeMatrixElement.h"
71 @implementation WETreeData
73 static Class StrClass = Nil;
76 StrClass = [NSString class];
79 - (id)initWithName:(NSString *)_name
80 associations:(NSDictionary *)_config
81 template:(WOElement *)_root
83 if ((self = [super initWithName:_name associations:_config template:_root])){
84 self->isTreeElement = WOExtGetProperty(_config, @"isTreeElement");
85 self->icon = WOExtGetProperty(_config, @"icon");
86 self->cornerIcon = WOExtGetProperty(_config, @"cornerIcon");
87 self->title = WOExtGetProperty(_config, @"title");
88 self->string = WOExtGetProperty(_config, @"string");
89 self->treeLink = WOExtGetProperty(_config, @"treeLink");
91 self->template = [_root retain];
97 [self->isTreeElement release];
98 [self->treeLink release];
100 [self->cornerIcon release];
101 [self->title release];
102 [self->string release];
103 [self->template release];
107 /* HTML generation */
109 - (void)_appendIcon:(NSString *)_icon alt:(NSString *)_alt
110 toResponse:(WOResponse *)_response inContext:(WOContext *)_ctx
114 iconWidth = [_ctx objectForKey:WETreeView_IconWidth];
116 [_response appendContentString:@"<img border=\"0\" src=\""];
117 [_response appendContentHTMLAttributeValue:_icon];
118 [_response appendContentString:@"\""];
120 if ([iconWidth length] > 0) {
121 [_response appendContentString:@" width=\""];
122 [_response appendContentString:iconWidth];
123 [_response appendContentString:@"\""];
125 if ([_alt length] > 0) {
126 [_response appendContentString:@" alt=\""];
127 [_response appendContentHTMLAttributeValue:_alt];
128 [_response appendContentString:@"\""];
131 if (_ctx->wcFlags.xmlStyleEmptyElements)
132 [_response appendContentString:@" />"];
134 [_response appendContentString:@">"];
137 - (void)_appendLink:(NSString *)_icon resp:(WOResponse *)_response
138 ctx:(WOContext *)_ctx
142 // doForm = [_ctx isInForm];
146 // TODO: we might want to support an assoc to provide the name
147 [_response appendContentString:@"<input type=\"image\" border=\"0\""];
148 [_response appendContentString:@" align=\"top\" name=\""];
149 [_response appendContentString:[_ctx elementID]];
150 [_response appendContentString:@"\" src=\""];
151 [_response appendContentString:_icon];
152 if (_ctx->wcFlags.xmlStyleEmptyElements)
153 [_response appendContentString:@"\" />"];
155 [_response appendContentString:@"\">"];
160 [_ctx appendElementIDComponent:WETreeView_ZOOM_ACTION_ID];
162 link = (self->treeLink != nil)
163 ? [self->treeLink stringValueInComponent:[_ctx component]]
164 : [_ctx componentActionURL];
166 if ([link length] > 0) {
167 [_response appendContentString:@"<a href=\""];
168 [_response appendContentString:link];
169 [_response appendContentString:@"\">"];
171 [self _appendIcon:_icon alt:@"z" toResponse:_response inContext:_ctx];
172 if ([link length] > 0)
173 [_response appendContentString:@"</a>"];
175 [_ctx deleteLastElementIDComponent];
179 - (void)_appendTreeElement:(NSString *)_key
180 toResponse:(WOResponse *)_response
181 inContext:(WOContext *)_ctx
187 // TODO: we need to patch this for stateless operation
190 doLink = (_key == WETreeView_Plus || _key == WETreeView_CornerPlus ||
191 _key == WETreeView_Minus || _key == WETreeView_CornerMinus);
193 if (self->treeLink) {
194 link = [self->treeLink stringValueInComponent:[_ctx component]];
195 if ([link length] == 0)
200 img = [_ctx objectForKey:_key];
201 img = WEUriOfResource(img, _ctx);
203 if (_key == WETreeView_Leaf) {
204 NSString *tmp = [self->icon stringValueInComponent:[_ctx component]];
206 tmp = WEUriOfResource(tmp, _ctx);
207 img = (tmp) ? tmp : img;
209 else if (_key == WETreeView_CornerLeaf) {
210 NSString *tmp = [self->cornerIcon stringValueInComponent:[_ctx component]];
211 tmp = WEUriOfResource(tmp, _ctx);
212 img = (tmp) ? tmp : img;
217 [_ctx appendElementIDComponent:WETreeView_ZOOM_ACTION_ID];
218 [_response appendContentString:@"<a href=\""];
219 [_response appendContentString:(link ? link :[_ctx componentActionURL])];
220 [_response appendContentString:@"\">"];
222 if (_key == WETreeView_Plus || _key == WETreeView_CornerPlus)
223 [_response appendContentString:@"<tt>[+]</tt>"];
224 else if (_key == WETreeView_Minus || _key == WETreeView_CornerMinus)
225 [_response appendContentString:@"<tt>[-]</tt>"];
227 [_response appendContentString:@"</a>"];
228 [_ctx deleteLastElementIDComponent]; /* WETreeView_ZOOM_ACTION_ID */
230 else if (_key == WETreeView_Leaf)
231 [_response appendContentString:@"<tt>-- </tt>"];
232 else if (_key == WETreeView_CornerLeaf)
233 [_response appendContentString:@"<tt>-| </tt>"];
234 else if (_key == WETreeView_Line)
235 [_response appendContentString:@"<tt> | </tt>"];
236 else if (_key == WETreeView_CornerLeaf)
237 [_response appendContentString:@"<tt> --</tt>"];
238 else if (_key == WETreeView_Junction || _key == WETreeView_Corner)
239 [_response appendContentString:@"<tt> |-</tt>"];
240 else if (_key == WETreeView_Space)
241 [_response appendContentString:@"<tt> </tt>"];
245 [self _appendLink:img resp:_response ctx:_ctx];
247 [self _appendIcon:img alt:@"z" toResponse:_response inContext:_ctx];
251 - (void)appendHeader:(WOResponse *)_response inContext:(WOContext *)_ctx {
256 cmp = [_ctx component];
257 tmp = [self->title stringValueInComponent:cmp];
258 isTree = [self->isTreeElement boolValueInComponent:cmp];;
264 [_response appendContentString:@"<td"];
265 [self appendExtraAttributesToResponse:_response inContext:_ctx];
266 if (self->otherTagString) {
267 [_response appendContentCharacter:' '];
268 [_response appendContentString:
269 [self->otherTagString stringValueInComponent:
273 [_response appendContentString:@" colspan=\""];
274 [_response appendContentString:
275 [[_ctx objectForKey:WETreeView_HEADER_MODE] stringValue]];
276 [_response appendContentString:@"\"><nobr>"];
279 [_response appendContentString:@"><nobr>"];
282 [_response appendContentString:@"<b>"];
283 [_response appendContentHTMLString:tmp];
284 [_response appendContentString:@"</b>"];
287 [_response appendContentString:@"</nobr></td>"];
290 - (void)appendData:(WOResponse *)_response inContext:(WOContext *)_ctx {
291 /* TODO: split up this method */
292 _WETreeMatrixElement *treeElement;
293 WOComponent *cmp = nil;
295 NSString *content = nil;
298 cmp = [_ctx component];
299 isTree = [self->isTreeElement boolValueInComponent:cmp];
300 content = [self->string stringValueInComponent:cmp];
301 treeElement = [_ctx objectForKey:WETreeView_TreeElement];
304 for (i = 0; i < [treeElement depth]+1; i++) {
308 iconWidth = [_ctx objectForKey:WETreeView_IconWidth];
310 treeElm = (i < [treeElement depth])
311 ? [treeElement elementAtIndex:i]
312 : [treeElement leaf];
315 [_response appendContentString:@"<td"];
316 [self appendExtraAttributesToResponse:_response inContext:_ctx];
317 [_response appendContentString:@" valign=\"middle\" align=\"center\""];
321 s = [[StrClass alloc] initWithFormat:@" width=\"%@\"", iconWidth];
322 [_response appendContentString:s];
326 if (treeElm == WETreeView_Plus || treeElm == WETreeView_Minus ||
327 treeElm == WETreeView_Junction || treeElm == WETreeView_Line) {
330 img = [_ctx objectForKey:WETreeView_Line];
331 img = WEUriOfResource(img, _ctx);
333 [_response appendContentString:@" background=\""];
334 [_response appendContentString:img];
335 [_response appendContentCharacter:'"'];
338 [_response appendContentString:@"><nobr>"];
341 [self _appendTreeElement:treeElm toResponse:_response inContext:_ctx];
343 [_response appendContentString:@"</nobr></td>"];
347 [_response appendContentString:@"<td"];
348 [self appendExtraAttributesToResponse:_response inContext:_ctx];
349 [_response appendContentString:@" width='97%'"];
350 [_response appendContentString:@" valign='middle' align='left'"];
351 [_response appendContentString:@" colspan=\""];
352 [_response appendContentString:[treeElement colspanAsString]];
353 [_response appendContentString:@"\">"];
356 /* add cell content */
357 [self->template appendToResponse:_response inContext:_ctx];
359 [_response appendContentHTMLString:content];
362 [_response appendContentString:@"</td>"];
366 [_response appendContentString:@"<td"];
367 [self appendExtraAttributesToResponse:_response inContext:_ctx];
368 if (self->otherTagString) {
369 [_response appendContentCharacter:' '];
370 [_response appendContentString:
371 [self->otherTagString stringValueInComponent:
374 [_response appendContentCharacter:'>'];
377 /* add cell content */
378 [self->template appendToResponse:_response inContext:_ctx];
379 if (content) [_response appendContentHTMLString:content];
382 [_response appendContentString:@"</td>"];
386 - (void)takeValuesFromRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
387 [self->template takeValuesFromRequest:_rq inContext:_ctx];
390 - (id)invokeActionForRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
391 return [self->template invokeActionForRequest:_rq inContext:_ctx];
394 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
395 self->doTable = ([_ctx objectForKey:WETreeView_RenderNoTable] == nil);
397 if ([_ctx objectForKey:WETreeView_HEADER_MODE])
398 [self appendHeader:_response inContext:_ctx];
400 [self appendData:_response inContext:_ctx];
403 @end /* WETreeData */