]> err.no Git - sope/blob - sope-appserver/samples/WOxExtTest/TreeView.m
include config.make in makefiles
[sope] / sope-appserver / samples / WOxExtTest / TreeView.m
1 /*
2   Copyright (C) 2000-2004 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21
22 #include <NGObjWeb/WOComponent.h>
23
24 @class NSArray, NSMutableDictionary;
25
26 @interface TreeView : WOComponent < NSCoding >
27 {
28   NSArray             *root;
29   NSMutableDictionary *state;
30   id                  item;
31
32   int clicks;
33   id  currentPath;
34 }
35 @end
36
37 #include "common.h"
38
39 @implementation TreeView
40
41 - (id)init {
42   if ((self = [super init])) {
43     WOResourceManager *rm;
44     NSString          *path;
45
46     rm   = [[self application] resourceManager];
47     
48     path = [rm pathForResourceNamed:@"TreeView.plist"
49                inFramework:nil
50                languages:nil];
51     
52     self->root      = [[NSArray alloc] initWithContentsOfFile:path];
53     self->state     = [[NSMutableDictionary alloc] init];
54   }
55   return self;
56 }
57
58 - (void)dealloc {
59   [self->currentPath release];
60   [self->root  release];
61   [self->item  release];
62   [self->state release];
63   [super dealloc];
64 }
65
66 /* accessors */
67
68 - (NSArray *)root {
69   return self->root;
70 }
71
72 - (NSArray *)oneTags {
73   return [NSArray arrayWithObject:@"one"];
74 }
75
76 - (void)setItem:(id)_item {
77   ASSIGN(self->item, _item);
78 }
79 - (id)item {
80   return self->item;
81 }
82
83 - (void)setClicks:(int)_clicks {
84   self->clicks = _clicks;
85 }
86 - (int)clicks {
87   return self->clicks;
88 }
89
90 - (void)setCurrentPath:(NSString *)_value {
91   ASSIGN(self->currentPath, _value);
92 }
93 - (id)currentPath {
94   return self->currentPath;
95 }
96
97 - (NSString *)keyPath {
98   return [[[self valueForKey:@"currentPath"]
99                  valueForKey:@"key"] componentsJoinedByString:@"."];
100 }
101
102 - (void)setIsZoom:(BOOL)_flag {
103   NSString *key;
104
105   key = [self keyPath];
106
107   NSLog(@"setIsZoom is %@", key);
108   if (key)
109     [self->state setObject:[NSNumber numberWithBool:_flag] forKey:key];
110 }
111 - (BOOL)isZoom {
112   NSString *key;
113
114   key = [self keyPath];
115
116   NSLog(@"isZoom is %@", key);
117   
118   if (key == nil)
119     return NO;
120     
121   return [[self->state objectForKey:key] boolValue];
122 }
123
124 - (BOOL)showItem {
125   return ([[self keyPath] hasSuffix:@"two"] ||
126           [[self keyPath] hasSuffix:@"four"])
127     ? NO
128     : YES;
129 }
130
131 /* actions */
132
133 - (id)countClicks {
134   self->clicks++;
135   return nil /* stay on page */;
136 }
137
138 - (id)dropAction {
139   NSLog(@"... droppedObject is %@", [self valueForKey:@"droppedObject"]);
140   return nil;
141 }
142
143 /* NSCoding */
144
145 - (void)encodeWithCoder:(NSCoder *)_coder {
146   [super encodeWithCoder:_coder];
147   [_coder encodeObject:self->root];
148   [_coder encodeObject:self->state];
149   [_coder encodeObject:self->item];
150 }
151 - (id)initWithCoder:(NSCoder *)_coder {
152   if ((self = [super initWithCoder:_coder])) {
153     self->root  = [[_coder decodeObject] retain];
154     self->state = [[_coder decodeObject] retain];
155     self->item  = [[_coder decodeObject] retain];
156   }
157   return self;
158 }
159
160 @end /* TableView */