KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.*;
25 import java.io.*;
26 import java.awt.event.*;
27 import javax.swing.*;
28 import javax.swing.tree.*;
29
30 import org.objectweb.joram.client.jms.admin.*;
31
32 import org.objectweb.util.monolog.api.*;
33
34 class PlatformTreeNode extends DefaultMutableTreeNode
35     implements AdminTreeNode {
36   private AdminController c;
37   
38   public PlatformTreeNode(AdminController c,
39                           String JavaDoc title) {
40     super(title);
41     this.c = c;
42   }
43
44   public void refresh(DefaultTreeModel treeModel) {
45   }
46
47   public String JavaDoc getDescription() {
48     StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
49     sb.append("<font face=Arial><b>Platform");
50     sb.append("</b><br></font>");
51     return sb.toString();
52   }
53
54   public JPopupMenu getContextMenu() {
55     JPopupMenu popup = new JPopupMenu("Platform");
56
57     
58
59     SaveConfigAction save = new SaveConfigAction();
60     if (! c.isAdminConnected())
61       save.setEnabled(false);
62     popup.add(new JMenuItem(save));
63
64     return popup;
65   }
66
67   public ImageIcon getImageIcon()
68   {
69     return AdminToolConstants.homeIcon;
70   }
71
72   public String JavaDoc toString() { return "Platform"; }
73
74   private class SaveConfigAction extends AbstractAction {
75     public SaveConfigAction() {
76       super("Save config...");
77     }
78     
79     public void actionPerformed(ActionEvent e) {
80       String JavaDoc platformConfig;
81       try {
82         platformConfig = AdminModule.getConfiguration();
83       } catch (Exception JavaDoc exc) {
84         System.err.println("Failed to load config: " + exc);
85         return;
86       }
87
88       File currentDirectory = new File(System.getProperty("user.dir"));
89       JFileChooser fileChooser = new JFileChooser(currentDirectory);
90       int res = fileChooser.showSaveDialog(AdminTool.getInstance());
91       switch (res) {
92       case JFileChooser.APPROVE_OPTION :
93         try {
94           File platformConfigFile = fileChooser.getSelectedFile();
95           FileOutputStream fos = new FileOutputStream(platformConfigFile);
96           PrintWriter pw = new PrintWriter(fos);
97           pw.println(platformConfig);
98           pw.flush();
99           pw.close();
100           fos.close();
101         } catch (Exception JavaDoc exc) {
102           System.err.println("Failed to save config: " + exc);
103         }
104       case JFileChooser.CANCEL_OPTION :
105       case JFileChooser.ERROR_OPTION :
106       default :
107       }
108     }
109   }
110 }
111
Popular Tags