1 22 package org.objectweb.joram.client.tools.admin; 23 24 import javax.swing.*; 25 import javax.swing.tree.*; 26 import javax.naming.*; 27 28 29 class JndiTreeNode extends DefaultMutableTreeNode 30 implements AdminTreeNode 31 { 32 private AdminController c; 33 34 private Context ctx = null; 35 36 private String name = null; 37 private Object obj = null; 38 39 public JndiTreeNode(AdminController c, Context ctx, String name) throws NamingException 40 { 41 super(name); 42 43 this.c = c; 44 this.ctx = ctx; 45 this.name = name; 46 this.obj = ctx.lookup(name); 47 } 48 49 public JndiTreeNode(AdminController c, Context ctx, Binding binding) 50 { 51 super(binding.getName()); 52 53 this.c = c; 54 this.ctx = ctx; 55 name = binding.getName(); 56 obj = binding.getObject(); 57 } 58 59 public void refresh(DefaultTreeModel treeModel) 60 { 61 } 62 63 public String getDescription() 64 { 65 if (obj == null) { 66 try 67 { 68 obj = ctx.lookup(name); 69 } 70 catch (NamingException exc) { 71 obj = null; 72 } 73 } 74 75 StringBuffer sb = new StringBuffer (); 76 if (obj != null) { 77 sb.append("<font face=Arial><b>"); 78 sb.append(getType()); 79 sb.append("</b><br></font><hr><font face=Arial><br><b>Name:</b> "); 80 sb.append(name); 81 sb.append("<br><b>Class:</b> "); 82 sb.append(obj.getClass().getName()); 83 sb.append("<br><br><b>Info:</b> "); 84 sb.append(getInfo()); 85 sb.append("<br></font>"); 86 } 87 else { 88 sb.append("<font face=Arial><b>Object lookup failed</b></font>"); 89 } 90 return sb.toString(); 91 } 92 93 public JPopupMenu getContextMenu() 94 { 95 JPopupMenu popup = new JPopupMenu("Binding"); 96 97 DeleteObjectAction doa = new DeleteObjectAction(); 98 if (!c.isJndiConnected() || !c.isAdminConnected()) 99 doa.setEnabled(false); 100 popup.add(new JMenuItem(doa)); 101 return popup; 102 } 103 104 public ImageIcon getImageIcon() 105 { 106 return AdminToolConstants.jndiIcon; 107 } 108 109 public boolean getAllowsChildren() { return false; } 110 111 public String getType() { 112 if (obj == null) 113 return null; 114 115 String str = obj.toString(); 116 int col = str.indexOf(':'); 117 if (col == -1) 118 return "Unknown"; 119 120 String t = str.substring(0, col); 121 122 if (t.equals("CF")) 123 return "ConnectionFactory"; 124 else if (t.equals("QCF")) 125 return "QueueConnectionFactory"; 126 else if (t.equals("TCF")) 127 return "TopicConnectionFactory"; 128 129 return t; 130 } 131 132 public String getInfo() { 133 if (obj == null) 134 return null; 135 136 String str = obj.toString(); 137 int col = str.indexOf(':'); 138 if (col == -1 || col == (str.length() - 1)) 139 return str; 140 141 return str.substring(col + 1); 142 } 143 144 public String getName() { return name; } 145 146 public Object getObject() { return obj; } 147 148 private class DeleteObjectAction extends AbstractAction 149 { 150 public DeleteObjectAction() 151 { 152 super("Delete", AdminToolConstants.trashIcon); 153 } 154 155 public void actionPerformed(java.awt.event.ActionEvent e) 156 { 157 try 158 { 159 Object [] options = { "OK", "CANCEL" }; 160 int conf = JOptionPane.showOptionDialog(AdminTool.getInstance(), "You are about to permanently delete this object. Please click OK to proceed.", 161 "Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]); 162 163 if (conf == 0) 164 c.deleteObject(JndiTreeNode.this); 165 } 166 catch (Exception x) { 167 x.printStackTrace(); 168 JOptionPane.showMessageDialog(null, x.getMessage()); 169 } 170 } 171 } 172 } 173 | Popular Tags |