KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > joram > client > tools > admin > DomainTreeNode


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17  * USA.
18  *
19  * Initial developer(s): ScalAgent DT
20  * Contributor(s):
21  */

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 JavaDoc domainName;
39
40   public DomainTreeNode(AdminController c,
41                         String JavaDoc domainName) {
42     super(domainName);
43     this.domainName = domainName;
44     this.c = c;
45   }
46   
47   public final String JavaDoc getDomainName() {
48     return domainName;
49   }
50
51   /**
52    * Returns descriptive text about the node.
53    */

54   public String JavaDoc getDescription() {
55     return "";
56   }
57   
58   /**
59    * Returns a context menu for the node, or null if
60    * no context menu should be created.
61    */

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   /**
82    * Gets the image icon for this node, or null to use
83    * the default.
84    */

85   public ImageIcon getImageIcon() {
86     return null;
87   }
88   
89   /**
90    * Refreshes the node.
91    * @param treeModel the model that the node is contained in.
92    */

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 JavaDoc 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 JavaDoc 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 JavaDoc[] 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 JavaDoc {
156                 c.deleteDomain(DomainTreeNode.this);
157               }
158             });
159         }
160       }
161     }
162   }
163 }
164
Popular Tags