1 22 package org.objectweb.joram.client.tools.admin; 23 24 import java.io.*; 25 import java.util.*; 26 import javax.swing.*; 27 import javax.swing.tree.*; 28 import java.awt.event.*; 29 30 import org.objectweb.joram.client.jms.admin.*; 31 32 import org.objectweb.util.monolog.api.*; 33 34 class DomainTreeNode extends DefaultMutableTreeNode 35 implements AdminTreeNode { 36 private AdminController c; 37 38 private String domainName; 39 40 public DomainTreeNode(AdminController c, 41 String domainName) { 42 super(domainName); 43 this.domainName = domainName; 44 this.c = c; 45 } 46 47 public final String getDomainName() { 48 return domainName; 49 } 50 51 54 public String getDescription() { 55 return ""; 56 } 57 58 62 public JPopupMenu getContextMenu() { 63 JPopupMenu popup = new JPopupMenu("Domain " + domainName); 64 65 CreateServerAction create = new CreateServerAction(); 66 if (! c.isAdminConnected()) 67 create.setEnabled(false); 68 popup.add(new JMenuItem(create)); 69 70 popup.addSeparator(); 71 72 DeleteDomainAction dda = new DeleteDomainAction(); 73 if (getChildCount() != 0 || 74 ! c.isAdminConnected()) 75 dda.setEnabled(false); 76 popup.add(new JMenuItem(dda)); 77 78 return popup; 79 } 80 81 85 public ImageIcon getImageIcon() { 86 return null; 87 } 88 89 93 public void refresh(DefaultTreeModel treeModel) { 94 95 } 96 97 private class CreateServerAction extends AbstractAction { 98 public CreateServerAction() { 99 super("Create server..."); 100 } 101 102 public void actionPerformed(ActionEvent e) { 103 CreateServerDialog csd = CreateServerDialog.showDialog(); 104 105 if (! csd.getActionCancelled()) { 106 try { 107 AdminModule.addServer( 108 csd.getServerId(), 109 csd.getHostName(), 110 domainName, 111 csd.getPort(), 112 csd.getName()); 113 } catch (Exception exc) { 114 if (Log.logger.isLoggable(BasicLevel.DEBUG)) 115 Log.logger.log(BasicLevel.DEBUG, "", exc); 116 JOptionPane.showMessageDialog(AdminTool.getInstance(), 117 exc.getMessage()); 118 return; 119 } 120 ServerTreeNode serverNode = 121 new ServerTreeNode( 122 c, 123 new Server( 124 (int)csd.getServerId(), 125 csd.getName(), 126 csd.getHostName())); 127 c.getAdminTreeModel().insertNodeInto( 128 serverNode, DomainTreeNode.this, 129 DomainTreeNode.this.getChildCount()); 130 } 131 } 132 } 133 134 private class DeleteDomainAction extends AbstractAction { 135 public DeleteDomainAction() { 136 super("Delete domain", AdminToolConstants.trashIcon); 137 } 138 139 public void actionPerformed(java.awt.event.ActionEvent e) { 140 if (getChildCount() != 0) { 141 JOptionPane.showMessageDialog(AdminTool.getInstance(), 142 "Can't remove a domain that owns servers.", 143 "Remove domain", 144 JOptionPane.ERROR_MESSAGE); 145 } else { 146 Object [] options = { "OK", "CANCEL" }; 147 int conf = JOptionPane.showOptionDialog( 148 AdminTool.getInstance(), 149 "You are about to delete this domain. Please click OK to proceed.", 150 "Warning", JOptionPane.DEFAULT_OPTION, 151 JOptionPane.WARNING_MESSAGE, null, options, options[0]); 152 153 if (conf == 0) { 154 AdminTool.invokeLater(new CommandWorker() { 155 public void run() throws Exception { 156 c.deleteDomain(DomainTreeNode.this); 157 } 158 }); 159 } 160 } 161 } 162 } 163 } 164 | Popular Tags |