1 30 package com.genimen.djeneric.tools.administrator.nodes; 31 32 import javax.swing.ImageIcon ; 33 import javax.swing.tree.TreePath ; 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 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 toString() 67 { 68 return _user.getCode() + " (" + _user.getName() + ")"; 69 } 70 71 public void reload() throws Exception 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 87 { 88 if (_alreadyLoaded) return; 89 90 boolean isCollapsed = _tree.isCollapsed(new TreePath (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 x) 112 { 113 DjLogger.log(x); 114 } 115 finally 116 { 117 getModel().nodeStructureChanged(this); 118 } 119 120 if (!isCollapsed) _tree.expandPath(new TreePath (this.getPath())); 121 } 122 123 public void delete() throws Exception 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 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 getNodeType() 166 { 167 return "User"; 168 } 169 170 } | Popular Tags |