KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > WebAppNode


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc;
5
6 import org.dijon.PopupMenu;
7
8 import com.tc.admin.common.XAbstractAction;
9 import com.tc.admin.common.XTreeNode;
10
11 import java.awt.event.ActionEvent JavaDoc;
12 import java.net.URL JavaDoc;
13
14 import javax.swing.ImageIcon JavaDoc;
15 import javax.swing.JPopupMenu JavaDoc;
16
17 public class WebAppNode extends XTreeNode {
18   private WebApp m_webApp;
19   private WebAppLinkNode m_tomcat1Link;
20   private WebAppLinkNode m_tomcat2Link;
21   private PopupMenu m_popupMenu;
22   private RefreshAction m_refreshAction;
23   private RemoveAction m_removeAction;
24   
25   private static ImageIcon JavaDoc ICON;
26   static {
27     String JavaDoc uri = "/com/tc/admin/icons/package_obj.gif";
28     URL JavaDoc url = WebAppNode.class.getResource(uri);
29     
30     if(url != null) {
31       ICON = new ImageIcon JavaDoc(url);
32     }
33   }
34   
35   public WebAppNode(WebApp webApp) {
36     super(webApp.getName());
37
38     setWebApp(webApp);
39     setIcon(ICON);
40     
41     add(m_tomcat1Link = new WebAppLinkNode("http://localhost:9081/"+m_webApp));
42     add(m_tomcat2Link = new WebAppLinkNode("http://localhost:9082/"+m_webApp));
43
44     initPopup();
45   }
46   
47   private void initPopup() {
48     String JavaDoc path = m_webApp.getPath();
49     
50     if(path != null && path.length() > 0) {
51       m_popupMenu = new PopupMenu();
52       m_popupMenu.add(m_refreshAction = new RefreshAction());
53       m_popupMenu.add(m_removeAction = new RemoveAction());
54     }
55   }
56   
57   public JPopupMenu JavaDoc getPopupMenu() {
58     return m_popupMenu;
59   }
60
61   void setRefreshEnabled(boolean enabled) {
62     if(m_refreshAction != null) {
63       m_refreshAction.setEnabled(enabled);
64     }
65   }
66   
67   class RefreshAction extends XAbstractAction {
68     RefreshAction() {
69       super("Refresh");
70       String JavaDoc uri = "/com/tc/admin/icons/refresh.gif";
71       setSmallIcon(new ImageIcon JavaDoc(getClass().getResource(uri)));
72     }
73     
74     public void actionPerformed(ActionEvent JavaDoc ae) {
75       ((WebAppTreeModel)getModel()).refresh(getWebApp());
76     }
77   }
78   
79   void setRemoveEnabled(boolean enabled) {
80     if(m_removeAction != null) {
81       m_removeAction.setEnabled(enabled);
82     }
83   }
84   
85   class RemoveAction extends XAbstractAction {
86     RemoveAction() {
87       super("Remove");
88       String JavaDoc uri = "/com/tc/admin/icons/terminate_co.gif";
89       setSmallIcon(new ImageIcon JavaDoc(getClass().getResource(uri)));
90     }
91     
92     public void actionPerformed(ActionEvent JavaDoc ae) {
93       ((WebAppTreeModel)getModel()).remove(getWebApp());
94     }
95   }
96   
97   public void setWebApp(WebApp webApp) {
98     m_webApp = webApp;
99   }
100
101   public WebApp getWebApp() {
102     return m_webApp;
103   }
104   
105   public void updateLinks(boolean tomcat1Ready, boolean tomcat2Ready) {
106     m_tomcat1Link.setReady(tomcat1Ready);
107     m_tomcat2Link.setReady(tomcat2Ready);
108   }
109   
110   public String JavaDoc getName() {
111     return m_webApp.getName();
112   }
113 }
114
Popular Tags