1 22 package org.objectweb.joram.client.tools.admin; 23 24 import java.util.*; 25 import javax.swing.*; 26 import javax.swing.tree.*; 27 28 import org.objectweb.joram.client.jms.admin.*; 29 30 31 class ServerTreeNode extends DefaultMutableTreeNode 32 implements AdminTreeNode 33 { 34 private AdminController c; 35 private Server serverDesc; 36 private DestinationRootTreeNode destRoot; 37 private UserRootTreeNode userRoot; 38 private DomainRootTreeNode domainRoot; 39 40 public ServerTreeNode(AdminController c, 41 Server serverDesc) { 42 super(toString(serverDesc)); 43 this.c = c; 44 this.serverDesc = serverDesc; 45 46 destRoot = new DestinationRootTreeNode(this); 47 add(destRoot); 48 userRoot = new UserRootTreeNode(this); 49 add(userRoot); 50 domainRoot = new DomainRootTreeNode(this); 51 add(domainRoot); 52 } 53 54 public void refresh(DefaultTreeModel treeModel) { 55 } 56 57 public String getDescription() { 58 StringBuffer sb = new StringBuffer (); 59 sb.append("<font face=Arial><b>Server #"); 60 sb.append(toString(serverDesc)); 61 sb.append("</b><br></font>"); 62 return sb.toString(); 63 } 64 65 public JPopupMenu getContextMenu() { 66 JPopupMenu popup = new JPopupMenu("Server"); 67 68 CreateDestinationAction cda = new CreateDestinationAction(); 69 if (! c.isJndiConnected() || !c.isAdminConnected()) 70 cda.setEnabled(false); 71 popup.add(new JMenuItem(cda)); 72 73 CreateUserAction cua = new CreateUserAction(); 74 if (! c.isAdminConnected()) 75 cua.setEnabled(false); 76 popup.add(new JMenuItem(cua)); 77 78 popup.addSeparator(); 79 80 CreateDomainAction cdoma = new CreateDomainAction(); 81 if (! c.isAdminConnected()) 82 cdoma.setEnabled(false); 83 popup.add(new JMenuItem(cdoma)); 84 85 popup.addSeparator(); 86 87 StopServerAction ssa = new StopServerAction(); 88 if (!c.isAdminConnected()) 89 ssa.setEnabled(false); 90 popup.add(new JMenuItem(ssa)); 91 92 DeleteServerAction dsa = new DeleteServerAction(); 93 if (getDomainRoot().getChildCount() != 0 || 94 ! c.isAdminConnected()) 95 dsa.setEnabled(false); 96 popup.add(new JMenuItem(dsa)); 97 98 return popup; 99 } 100 101 public ImageIcon getImageIcon() { 102 return AdminToolConstants.serverIcon; 103 } 104 105 public int getServerId() { 106 return serverDesc.getId(); 107 } 108 109 public final DestinationRootTreeNode getDestinationRoot() { 110 return destRoot; 111 } 112 113 public final UserRootTreeNode getUserRoot() { 114 return userRoot; 115 } 116 117 public final DomainRootTreeNode getDomainRoot() { 118 return domainRoot; 119 } 120 121 public String toString() { 122 return toString(serverDesc); 123 } 124 125 public static String toString(Server serverDesc) { 126 return "Server #" + 127 serverDesc.getId() + ": " + 128 serverDesc.getName() + " (" + 129 serverDesc.getHostName() + ')'; 130 } 131 132 public List getDeadMessageQueues() { 133 List rs = new Vector(); 134 135 for (int i = 0; i < destRoot.getChildCount(); i++){ 136 DestinationTreeNode dtn = (DestinationTreeNode) destRoot.getChildAt(i); 137 try { 138 DeadMQueue dmq = (DeadMQueue) dtn.getDestination(); 139 rs.add(dmq); 140 } 141 catch (ClassCastException cce) {} 142 } 143 return rs; 144 } 145 146 public List getUsers() { 147 List rs = new Vector(); 148 149 for (int i = 0; i < userRoot.getChildCount(); i++){ 150 UserTreeNode utn = (UserTreeNode) userRoot.getChildAt(i); 151 try { 152 User user = (User) utn.getUser(); 153 rs.add(user); 154 } 155 catch (ClassCastException cce) {} 156 } 157 158 return rs; 159 } 160 161 private class CreateDestinationAction extends AbstractAction { 162 public CreateDestinationAction() { 163 super("Create Destination..."); 164 } 165 166 public void actionPerformed(java.awt.event.ActionEvent e) { 167 try { 168 final CreateDestinationDialog cdd = CreateDestinationDialog.showDialog(); 169 170 if (! cdd.getActionCancelled()) { 171 AdminTool.invokeLater(new CommandWorker() { 172 public void run() throws Exception { 173 c.createDestination(ServerTreeNode.this, 174 cdd.getDestinationName(), 175 cdd.getDestinationType()); 176 } 177 }); 178 } 179 } 180 catch (Exception x) { 181 x.printStackTrace(); 182 JOptionPane.showMessageDialog(null, x.getMessage()); 183 } 184 } 185 } 186 187 private class StopServerAction extends AbstractAction 188 { 189 public StopServerAction() 190 { 191 super("Stop Server", AdminToolConstants.stopIcon); 192 } 193 194 public void actionPerformed(java.awt.event.ActionEvent e) { 195 Object [] options = { "OK", "CANCEL" }; 196 int conf = JOptionPane.showOptionDialog( 197 AdminTool.getInstance(), 198 "You are about to stop this server. Please click OK to proceed.", 199 "Warning", JOptionPane.DEFAULT_OPTION, 200 JOptionPane.WARNING_MESSAGE, null, options, options[0]); 201 202 if (conf == 0) { 203 AdminTool.invokeLater(new CommandWorker() { 204 public void run() throws Exception { 205 c.stopServer(ServerTreeNode.this); 206 } 207 }); 208 } 209 } 210 } 211 212 private class CreateUserAction extends AbstractAction { 213 public CreateUserAction() { 214 super("Create User..."); 215 } 216 217 public void actionPerformed(java.awt.event.ActionEvent e) { 218 while (true) { 219 final CreateUserDialog cud = CreateUserDialog.showDialog(); 220 221 if (cud.getActionCancelled()) { 222 break; 223 } 224 else { 225 String msg = ""; 226 227 if (cud.getUserName().length() == 0) 228 msg = "The user name is mandatory to create a new user. Please click OK to make corrections."; 229 else if (cud.getPassword().length() == 0) 230 msg = "A password is mandatory to create a new user. Please click OK to make corrections."; 231 else if (!cud.getPassword().equals(cud.getConfirmationPassword())) 232 msg = "The two passwords that you have entered do not match. Please click OK to make corrections."; 233 else { 234 AdminTool.invokeLater(new CommandWorker() { 235 public void run() throws Exception { 236 c.createUser(ServerTreeNode.this, cud.getUserName(), cud.getPassword()); 237 } 238 }); 239 break; 240 } 241 242 Object [] options = { "OK" }; 243 JOptionPane.showOptionDialog(AdminTool.getInstance(), msg, 244 "Error", JOptionPane.DEFAULT_OPTION, 245 JOptionPane.ERROR_MESSAGE, null, options, options[0]); 246 } 247 } 248 } 249 } 250 251 private class CreateDomainAction extends AbstractAction { 252 public CreateDomainAction() { 253 super("Create Domain..."); 254 } 255 256 public void actionPerformed(java.awt.event.ActionEvent e) { 257 while (true) { 258 final CreateDomainDialog cdd = CreateDomainDialog.showDialog(); 259 260 if (cdd.getActionCancelled()) { 261 break; 262 } else { 263 AdminTool.invokeLater(new CommandWorker() { 264 public void run() throws Exception { 265 c.createDomain(ServerTreeNode.this, 266 cdd.getName(), 267 cdd.getPort()); 268 } 269 }); 270 break; 271 } 272 } 273 } 274 } 275 276 private class DeleteServerAction extends AbstractAction { 277 public DeleteServerAction() { 278 super("Delete Server"); 279 } 280 281 public void actionPerformed(java.awt.event.ActionEvent e) { 282 if (domainRoot.getChildCount() != 0) { 283 JOptionPane.showMessageDialog(AdminTool.getInstance(), 284 "Can't remove a server that owns domains.", 285 "Remove server", 286 JOptionPane.ERROR_MESSAGE); 287 } else { 288 Object [] options = { "OK", "CANCEL" }; 289 int conf = JOptionPane.showOptionDialog( 290 AdminTool.getInstance(), 291 "You are about to delete this server. Please click OK to proceed.", 292 "Warning", JOptionPane.DEFAULT_OPTION, 293 JOptionPane.WARNING_MESSAGE, null, options, options[0]); 294 295 if (conf == 0) { 296 AdminTool.invokeLater(new CommandWorker() { 297 public void run() throws Exception { 298 c.deleteServer(ServerTreeNode.this); 299 } 300 }); 301 } 302 } 303 } 304 } 305 } 306 | Popular Tags |