KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > management > browser > frame > ServerInternalFrame


1 /*
2  * EJTools, the Enterprise Java Tools
3  *
4  * Distributable under LGPL license.
5  * See terms of license at www.gnu.org.
6  */

7 package org.ejtools.management.browser.frame;
8
9 import java.awt.BorderLayout JavaDoc;
10 import java.beans.PropertyChangeEvent JavaDoc;
11 import java.util.ResourceBundle JavaDoc;
12
13 import javax.swing.JMenuBar JavaDoc;
14
15 import org.apache.log4j.Logger;
16 import org.ejtools.adwt.BeanContextTreePanel;
17 import org.ejtools.adwt.action.Command;
18 import org.ejtools.adwt.action.action.RefreshAction;
19 import org.ejtools.adwt.service.BeanContextInternalFrame;
20 import org.ejtools.adwt.service.MenuBarServiceProvider;
21 import org.ejtools.adwt.service.ToolBarServiceProvider;
22 import org.ejtools.management.browser.action.ShowNotificationsAction;
23 import org.ejtools.management.browser.model.ManagedObject;
24 import org.ejtools.management.browser.model.Server;
25 import org.ejtools.management.browser.model.service.CacheService;
26 import org.ejtools.management.browser.model.service.CacheServiceProvider;
27 import org.ejtools.management.browser.model.service.ConnectionServiceProvider;
28 import org.ejtools.management.browser.model.service.NotificationServiceProvider;
29 import org.ejtools.util.service.Profile;
30 import org.ejtools.util.service.ProfileHolder;
31
32 /**
33  * Description of the Class
34  *
35  * @author Laurent Etiemble
36  * @version $Revision: 1.6 $
37  */

38 public class ServerInternalFrame extends BeanContextInternalFrame implements ProfileHolder
39 {
40    /** Description of the Field */
41    protected CacheServiceProvider cacheProvider;
42    /** Description of the Field */
43    protected ConnectionServiceProvider connectionProvider;
44    /** Description of the Field */
45    protected MenuBarServiceProvider menubarProvider;
46    /** Description of the Field */
47    protected NotificationsInternalFrame notificationFrame;
48    /** Description of the Field */
49    protected NotificationServiceProvider notificationProvider;
50    /** Description of the Field */
51    protected Profile profile = null;
52    /** Description of the Field */
53    protected Server server = null;
54    /** Description of the Field */
55    protected ToolBarServiceProvider toolbarProvider;
56    /** Description of the Field */
57    private static Logger logger = Logger.getLogger(ServerInternalFrame.class);
58    /** Description of the Field */
59    private static ResourceBundle JavaDoc resources = ResourceBundle.getBundle("org.ejtools.management.browser.Resources");
60
61
62    /**
63     * Constructor for ServerInternalFrame.
64     *
65     * @param profile Description of the Parameter
66     */

67    public ServerInternalFrame()
68    {
69       super();
70    }
71
72
73
74    /**
75     * Description of the Method
76     *
77     * @param objectName Description of the Parameter
78     * @return Description of the Return Value
79     */

80    public ManagedObject queryMBean(String JavaDoc objectName)
81    {
82     ManagedObject resource = (ManagedObject) this.cacheProvider.get(CacheService.RESOURCE_TYPE, objectName);
83       try
84       {
85          if ((resource != null) && (resource.isRegistered()))
86          {
87             return resource;
88          }
89       }
90       catch (Exception JavaDoc e)
91       {
92          logger.warn("Cannot find ObjectName " + objectName, e);
93       }
94       return null;
95    }
96
97
98    public void setProfile(Profile profile)
99    {
100       this.profile = profile;
101    }
102
103
104    /**
105     * Sets the server attribute of the ServerInternalFrame object
106     *
107     * @param server The new server value
108     */

109    public void setServer(Server server)
110    {
111       this.connectionProvider = new ConnectionServiceProvider();
112       this.cacheProvider = new CacheServiceProvider();
113       this.notificationProvider = new NotificationServiceProvider();
114       this.menubarProvider = new MenuBarServiceProvider();
115       this.toolbarProvider = new ToolBarServiceProvider();
116
117       this.server = new Server();
118       this.server.setProfile(profile);
119
120       this.add(this.connectionProvider);
121       this.add(this.cacheProvider);
122       this.add(this.notificationProvider);
123       this.add(this.menubarProvider);
124       this.add(this.toolbarProvider);
125
126       this.add(this.server);
127       this.notificationFrame = new NotificationsInternalFrame(this.notificationProvider);
128
129       this.server.addPropertyChangeListener("name", this);
130       this.server.addPropertyChangeListener("name", this.notificationFrame);
131
132       this.add(new RefreshAction(
133          new Command()
134          {
135             public void execute()
136             {
137                ServerInternalFrame.this.server.refresh();
138             }
139          }));
140
141       this.add(new ShowNotificationsAction(
142          new Command()
143          {
144             public void execute()
145             {
146                ServerInternalFrame.this.showNotificationFrame();
147             }
148          }));
149
150       BeanContextTreePanel panel = new BeanContextTreePanel(this.server);
151       panel.setIndexer(new ResourceIndexer());
152       panel.setRenderer(new ResourceRenderer());
153       panel.selectRoot();
154
155       this.frame.setJMenuBar((JMenuBar JavaDoc) this.menubarProvider.getContainer());
156       this.frame.getContentPane().add(BorderLayout.NORTH, this.toolbarProvider.getContainer());
157       this.frame.getContentPane().add(BorderLayout.CENTER, panel);
158    }
159
160
161    /**
162     * Gets the profile attribute of the ServerInternalFrame object
163     *
164     * @return The profile value
165     */

166    public Profile getProfile()
167    {
168       return this.profile;
169    }
170
171
172    /**
173     * @param event Description of the Parameter
174     */

175    public void propertyChange(PropertyChangeEvent JavaDoc event)
176    {
177       if (event.getPropertyName().equals("name"))
178       {
179          String JavaDoc newName = (String JavaDoc) event.getNewValue();
180          this.setTitle(resources.getString("connection.text.prefix") + " : " + newName);
181       }
182    }
183
184
185    /** Description of the Method */
186    protected void initializeBeanContextResources()
187    {
188       super.initializeBeanContextResources();
189
190       // Hack to update the window title
191
this.server.setName("");
192       this.server.setName(resources.getString("connection.text.untitled"));
193    }
194
195
196    /** Description of the Method */
197    protected void releaseBeanContextResources()
198    {
199       this.notificationFrame.close();
200       this.server.clear();
201       super.releaseBeanContextResources();
202    }
203
204
205    /** Description of the Method */
206    protected void showNotificationFrame()
207    {
208       NotificationsInternalFrame frame = ServerInternalFrame.this.notificationFrame;
209       if (!this.getBeanContext().contains(frame))
210       {
211          this.getBeanContext().add(frame);
212       }
213       frame.activate();
214    }
215 }
216
Popular Tags