001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tc;
005:
006: import org.dijon.PopupMenu;
007:
008: import com.tc.admin.common.XAbstractAction;
009: import com.tc.admin.common.XTreeNode;
010:
011: import java.awt.event.ActionEvent;
012: import java.net.URL;
013:
014: import javax.swing.ImageIcon;
015: import javax.swing.JPopupMenu;
016:
017: public class WebAppNode extends XTreeNode {
018: private WebApp m_webApp;
019: private WebAppLinkNode m_tomcat1Link;
020: private WebAppLinkNode m_tomcat2Link;
021: private PopupMenu m_popupMenu;
022: private RefreshAction m_refreshAction;
023: private RemoveAction m_removeAction;
024:
025: private static ImageIcon ICON;
026: static {
027: String uri = "/com/tc/admin/icons/package_obj.gif";
028: URL url = WebAppNode.class.getResource(uri);
029:
030: if (url != null) {
031: ICON = new ImageIcon(url);
032: }
033: }
034:
035: public WebAppNode(WebApp webApp) {
036: super (webApp.getName());
037:
038: setWebApp(webApp);
039: setIcon(ICON);
040:
041: add(m_tomcat1Link = new WebAppLinkNode("http://localhost:9081/"
042: + m_webApp));
043: add(m_tomcat2Link = new WebAppLinkNode("http://localhost:9082/"
044: + m_webApp));
045:
046: initPopup();
047: }
048:
049: private void initPopup() {
050: String path = m_webApp.getPath();
051:
052: if (path != null && path.length() > 0) {
053: m_popupMenu = new PopupMenu();
054: m_popupMenu.add(m_refreshAction = new RefreshAction());
055: m_popupMenu.add(m_removeAction = new RemoveAction());
056: }
057: }
058:
059: public JPopupMenu getPopupMenu() {
060: return m_popupMenu;
061: }
062:
063: void setRefreshEnabled(boolean enabled) {
064: if (m_refreshAction != null) {
065: m_refreshAction.setEnabled(enabled);
066: }
067: }
068:
069: class RefreshAction extends XAbstractAction {
070: RefreshAction() {
071: super ("Refresh");
072: String uri = "/com/tc/admin/icons/refresh.gif";
073: setSmallIcon(new ImageIcon(getClass().getResource(uri)));
074: }
075:
076: public void actionPerformed(ActionEvent ae) {
077: ((WebAppTreeModel) getModel()).refresh(getWebApp());
078: }
079: }
080:
081: void setRemoveEnabled(boolean enabled) {
082: if (m_removeAction != null) {
083: m_removeAction.setEnabled(enabled);
084: }
085: }
086:
087: class RemoveAction extends XAbstractAction {
088: RemoveAction() {
089: super ("Remove");
090: String uri = "/com/tc/admin/icons/terminate_co.gif";
091: setSmallIcon(new ImageIcon(getClass().getResource(uri)));
092: }
093:
094: public void actionPerformed(ActionEvent ae) {
095: ((WebAppTreeModel) getModel()).remove(getWebApp());
096: }
097: }
098:
099: public void setWebApp(WebApp webApp) {
100: m_webApp = webApp;
101: }
102:
103: public WebApp getWebApp() {
104: return m_webApp;
105: }
106:
107: public void updateLinks(boolean tomcat1Ready, boolean tomcat2Ready) {
108: m_tomcat1Link.setReady(tomcat1Ready);
109: m_tomcat2Link.setReady(tomcat2Ready);
110: }
111:
112: public String getName() {
113: return m_webApp.getName();
114: }
115: }
|