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.tools.administrator.Administrator; 39 import com.genimen.djeneric.util.DjLogger; 40 41 public class UserViewNode extends AdministratorTreeNode 42 { 43 private static final long serialVersionUID = 1L; 44 DjUser _user; 45 DjModelView _view; 46 boolean _parentIsView; 47 48 public UserViewNode(DjUser user, DjModelView view, boolean parentIsView) 49 { 50 _user = user; 51 _view = view; 52 _parentIsView = parentIsView; 53 } 54 55 public ImageIcon getImageIcon() 56 { 57 if (_user.isAdministrator()) return Administrator.getImageIcon("usrmvwadmin.gif"); 58 return Administrator.getImageIcon("usrmvw.gif"); 59 } 60 61 public String toString() 62 { 63 if (_parentIsView) return _user.getCode() + " (" + _user.getName() + ")"; 64 return _view.getCode(); 65 } 66 67 public void reload() throws Exception 68 { 69 _alreadyLoaded = false; 70 DjSession session = createSession(); 71 try 72 { 73 _user.reload(session); 74 _view.reload(session); 75 } 76 finally 77 { 78 session.close(); 79 } 80 expandNode(); 81 } 82 83 public void expandNode() throws Exception 84 { 85 if (_alreadyLoaded) return; 86 87 boolean isCollapsed = _tree.isCollapsed(new TreePath (this.getPath())); 88 removeAllChildren(); 89 90 try 91 { 92 _alreadyLoaded = true; 93 } 94 catch (Exception x) 95 { 96 DjLogger.log(x); 97 } 98 finally 99 { 100 getModel().nodeStructureChanged(this); 101 } 102 103 if (!isCollapsed) _tree.expandPath(new TreePath (this.getPath())); 104 } 105 106 public void delete() throws Exception 107 { 108 DjSession session = createSession(); 109 try 110 { 111 if (_parentIsView) _view.removeUser(session, _user); 112 else _user.removeView(session, _view); 113 session.commit(); 114 } 115 finally 116 { 117 session.close(); 118 } 119 AdministratorTreeNode parent = getParentTreeNode(); 120 removeFromParent(); 121 getModel().nodeStructureChanged(parent); 122 } 123 124 public boolean canEdit() 125 { 126 return false; 127 } 128 129 public boolean canCreate() 130 { 131 return false; 132 } 133 134 public boolean canDelete() 135 { 136 return true; 137 } 138 139 public String getNodeType() 140 { 141 return "User View"; 142 } 143 144 } | Popular Tags |