1 22 package org.objectweb.joram.client.tools.admin; 23 24 import javax.swing.*; 25 import javax.swing.tree.*; 26 27 import org.objectweb.joram.client.jms.admin.User; 28 29 30 class UserTreeNode extends DefaultMutableTreeNode 31 implements AdminTreeNode 32 { 33 private AdminController c; 34 private User user; 35 36 private SubscriptionRootTreeNode subscriptionRoot; 37 38 public UserTreeNode(AdminController c, User user) { 39 super(user.getName() + ':' + 40 user.getProxyId()); 41 this.c = c; 42 this.user = user; 43 44 subscriptionRoot = new SubscriptionRootTreeNode(); 45 add(subscriptionRoot); 46 } 47 48 public void refresh(DefaultTreeModel treeModel) 49 { 50 } 51 52 public String getDescription() 53 { 54 StringBuffer sb = new StringBuffer (); 55 sb.append("<font face=Arial><b>User: </b>"); 56 sb.append(user); 57 sb.append("<br><br>"); 58 59 sb.append("</font>"); 60 return sb.toString(); 61 } 62 63 public JPopupMenu getContextMenu() 64 { 65 JPopupMenu popup = new JPopupMenu("User"); 66 67 ChangePasswordAction cpa = new ChangePasswordAction(); 68 if (!c.isAdminConnected()) 69 cpa.setEnabled(false); 70 popup.add(new JMenuItem(cpa)); 71 72 DeleteUserAction dua = new DeleteUserAction(); 73 if (!c.isAdminConnected()) 74 dua.setEnabled(false); 75 popup.add(new JMenuItem(dua)); 76 77 return popup; 78 } 79 80 public ImageIcon getImageIcon() 81 { 82 return AdminToolConstants.userIcon; 83 } 84 85 public User getUser() { return user; } 86 87 public String getUserName() { 89 String name = null; 90 91 try { 92 name = (String ) user.code().get("name"); 93 } 94 catch (Exception exc) {} 95 96 return name; 97 } 98 99 public ServerTreeNode getParentServerTreeNode() { 100 return (ServerTreeNode) getParent().getParent(); 101 } 102 103 public boolean getAllowsChildren() { 104 return true; 105 } 106 107 private class DeleteUserAction extends AbstractAction 108 { 109 public DeleteUserAction() 110 { 111 super("Delete", AdminToolConstants.trashIcon); 112 } 113 114 public void actionPerformed(java.awt.event.ActionEvent e) 115 { 116 try 117 { 118 Object [] options = { "OK", "CANCEL" }; 119 int conf = JOptionPane.showOptionDialog(AdminTool.getInstance(), "You are about to permanently delete this user. Please click OK to proceed.", 120 "Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]); 121 122 if (conf == 0) 123 c.deleteUser(UserTreeNode.this); 124 } 125 catch (Exception x) { 126 x.printStackTrace(); 127 JOptionPane.showMessageDialog(null, x.getMessage()); 128 } 129 } 130 } 131 132 private class ChangePasswordAction extends AbstractAction 133 { 134 public ChangePasswordAction() 135 { 136 super("Change Password..."); 137 } 138 139 public void actionPerformed(java.awt.event.ActionEvent e) 140 { 141 try 142 { 143 while (true) { 144 CreateUserDialog cud = CreateUserDialog.showDialog(UserTreeNode.this.getUserName(), true); 145 146 if (cud.getActionCancelled()) { 147 break; 148 } 149 else { 150 String msg = ""; 151 152 if (cud.getPassword().length() == 0) 153 msg = "You have to enter a new password for the user. Please click OK to make corrections."; 154 else if (!cud.getPassword().equals(cud.getConfirmationPassword())) 155 msg = "The two passwords that you have entered do not match. Please click OK to make corrections."; 156 else { 157 c.updateUser(UserTreeNode.this, cud.getUserName(), cud.getPassword()); 158 break; 159 } 160 161 Object [] options = { "OK" }; 162 JOptionPane.showOptionDialog(AdminTool.getInstance(), msg, 163 "Error", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[0]); 164 } 165 } 166 } 167 catch (Exception x) { 168 x.printStackTrace(); 169 JOptionPane.showMessageDialog(null, x.getMessage()); 170 } 171 } 172 } 173 } 174 | Popular Tags |