1 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 title) { 40 super(title); 41 this.c = c; 42 } 43 44 public void refresh(DefaultTreeModel treeModel) { 45 } 46 47 public String getDescription() { 48 StringBuffer sb = new StringBuffer (); 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 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 platformConfig; 81 try { 82 platformConfig = AdminModule.getConfiguration(); 83 } catch (Exception 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 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 |