KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > tools > administrator > nodes > UserNode


1 /*
2  * Copyright (c) 2001-2005 by Genimen BV (www.genimen.com) All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, is permitted
5  * provided that the following conditions are met:
6  * - Redistributions of source code must retain the above copyright notice, this list of conditions
7  * and the following disclaimer.
8  * - Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * - All advertising materials mentioning features or use of this software must display the
12  * following acknowledgment: "This product includes Djeneric."
13  * - Products derived from this software may not be called "Djeneric" nor may
14  * "Djeneric" appear in their names without prior written permission of Genimen BV.
15  * - Redistributions of any form whatsoever must retain the following acknowledgment: "This
16  * product includes Djeneric."
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL GENIMEN BV, DJENERIC.ORG,
22  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */

30 package com.genimen.djeneric.tools.administrator.nodes;
31
32 import javax.swing.ImageIcon JavaDoc;
33 import javax.swing.tree.TreePath JavaDoc;
34
35 import com.genimen.djeneric.repository.DjModelView;
36 import com.genimen.djeneric.repository.DjSession;
37 import com.genimen.djeneric.repository.DjUser;
38 import com.genimen.djeneric.repository.DjUserContextAssociation;
39 import com.genimen.djeneric.tools.administrator.Administrator;
40 import com.genimen.djeneric.tools.administrator.editors.AdminEditor;
41 import com.genimen.djeneric.tools.administrator.editors.UserEditor;
42 import com.genimen.djeneric.tools.administrator.helpers.AdminPanel;
43 import com.genimen.djeneric.util.DjLogger;
44
45 public class UserNode extends AdministratorTreeNode
46 {
47   private static final long serialVersionUID = 1L;
48   DjUser _user;
49
50   public UserNode(DjUser user)
51   {
52     _user = user;
53   }
54
55   public ImageIcon JavaDoc getImageIcon()
56   {
57     if (_user.isAdministrator()) return Administrator.getImageIcon("administrator.gif");
58     return Administrator.getImageIcon("user.gif");
59   }
60
61   public DjUser getUser()
62   {
63     return _user;
64   }
65
66   public String JavaDoc toString()
67   {
68     return _user.getCode() + " (" + _user.getName() + ")";
69   }
70
71   public void reload() throws Exception JavaDoc
72   {
73     _alreadyLoaded = false;
74     DjSession session = createSession();
75     try
76     {
77       _user.reload(session);
78     }
79     finally
80     {
81       session.close();
82     }
83     expandNode();
84   }
85
86   public void expandNode() throws Exception JavaDoc
87   {
88     if (_alreadyLoaded) return;
89
90     boolean isCollapsed = _tree.isCollapsed(new TreePath JavaDoc(this.getPath()));
91     removeAllChildren();
92
93     try
94     {
95       DjModelView[] views = _user.getViews();
96       for (int i = 0; i < views.length; i++)
97       {
98         UserViewNode an = new UserViewNode(_user, views[i], false);
99         insertAsChild(an);
100       }
101
102       DjUserContextAssociation[] dca = _user.getContextAssociations();
103       for (int i = 0; i < dca.length; i++)
104       {
105         AssociationNode an = new AssociationNode(dca[i], true);
106         insertAsChild(an);
107       }
108
109       _alreadyLoaded = true;
110     }
111     catch (Exception JavaDoc x)
112     {
113       DjLogger.log(x);
114     }
115     finally
116     {
117       getModel().nodeStructureChanged(this);
118     }
119
120     if (!isCollapsed) _tree.expandPath(new TreePath JavaDoc(this.getPath()));
121   }
122
123   public void delete() throws Exception JavaDoc
124   {
125     DjSession session = createSession();
126     try
127     {
128       _user.delete(session);
129       session.commit();
130     }
131     finally
132     {
133       session.close();
134     }
135     AdministratorTreeNode parent = getParentTreeNode();
136     removeFromParent();
137     getModel().nodeStructureChanged(parent);
138   }
139
140   public AdminEditor getEditor(AdminPanel admin)
141   {
142     return new UserEditor(admin, this, _user);
143   }
144
145   public AdminEditor getCreateEditor(AdminPanel admin) throws Exception JavaDoc
146   {
147     return new UserEditor(admin, getParentTreeNode(), admin.getManager().getContextManager().createNewUser());
148   }
149
150   public boolean canEdit()
151   {
152     return true;
153   }
154
155   public boolean canCreate()
156   {
157     return true;
158   }
159
160   public boolean canDelete()
161   {
162     return true;
163   }
164
165   public String JavaDoc getNodeType()
166   {
167     return "User";
168   }
169
170 }
Popular Tags