KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > console > gui > CjdbcGui


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2005 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Nicolas Modrzyk
22  * Contributor(s): Emmanuel Cecchet.
23  */

24
25 package org.objectweb.cjdbc.console.gui;
26
27 import java.awt.BorderLayout JavaDoc;
28 import java.awt.Color JavaDoc;
29 import java.awt.Container JavaDoc;
30 import java.awt.Cursor JavaDoc;
31 import java.awt.Dimension JavaDoc;
32 import java.awt.FlowLayout JavaDoc;
33 import java.awt.GridLayout JavaDoc;
34 import java.awt.dnd.DnDConstants JavaDoc;
35 import java.awt.dnd.DropTarget JavaDoc;
36 import java.io.BufferedReader JavaDoc;
37 import java.io.BufferedWriter JavaDoc;
38 import java.io.File JavaDoc;
39 import java.io.FileInputStream JavaDoc;
40 import java.io.FileNotFoundException JavaDoc;
41 import java.io.FileReader JavaDoc;
42 import java.io.FileWriter JavaDoc;
43 import java.io.IOException JavaDoc;
44 import java.io.PrintWriter JavaDoc;
45 import java.io.StringReader JavaDoc;
46 import java.text.SimpleDateFormat JavaDoc;
47 import java.util.ArrayList JavaDoc;
48 import java.util.Date JavaDoc;
49 import java.util.Enumeration JavaDoc;
50 import java.util.HashMap JavaDoc;
51 import java.util.Hashtable JavaDoc;
52 import java.util.Iterator JavaDoc;
53 import java.util.Set JavaDoc;
54
55 import javax.management.MBeanAttributeInfo JavaDoc;
56 import javax.management.MBeanException JavaDoc;
57 import javax.management.MBeanInfo JavaDoc;
58 import javax.management.MBeanOperationInfo JavaDoc;
59 import javax.management.ObjectInstance JavaDoc;
60 import javax.management.ObjectName JavaDoc;
61 import javax.swing.BorderFactory JavaDoc;
62 import javax.swing.Icon JavaDoc;
63 import javax.swing.JButton JavaDoc;
64 import javax.swing.JDesktopPane JavaDoc;
65 import javax.swing.JFileChooser JavaDoc;
66 import javax.swing.JFrame JavaDoc;
67 import javax.swing.JInternalFrame JavaDoc;
68 import javax.swing.JOptionPane JavaDoc;
69 import javax.swing.JPanel JavaDoc;
70 import javax.swing.JScrollPane JavaDoc;
71 import javax.swing.JTabbedPane JavaDoc;
72 import javax.swing.JTable JavaDoc;
73 import javax.swing.JTextArea JavaDoc;
74 import javax.swing.JTextField JavaDoc;
75 import javax.swing.JTextPane JavaDoc;
76 import javax.swing.JToolTip JavaDoc;
77 import javax.swing.filechooser.FileFilter JavaDoc;
78
79 import org.objectweb.cjdbc.common.exceptions.CJDBCException;
80 import org.objectweb.cjdbc.common.i18n.ConsoleTranslate;
81 import org.objectweb.cjdbc.common.i18n.GuiTranslate;
82 import org.objectweb.cjdbc.common.jmx.JmxException;
83 import org.objectweb.cjdbc.common.jmx.mbeans.ControllerMBean;
84 import org.objectweb.cjdbc.common.jmx.mbeans.DataCollectorMBean;
85 import org.objectweb.cjdbc.common.jmx.mbeans.DatabaseBackendMBean;
86 import org.objectweb.cjdbc.common.jmx.mbeans.VirtualDatabaseMBean;
87 import org.objectweb.cjdbc.common.jmx.notifications.CjdbcNotificationList;
88 import org.objectweb.cjdbc.common.shared.BackendInfo;
89 import org.objectweb.cjdbc.common.util.Constants;
90 import org.objectweb.cjdbc.common.util.Strings;
91 import org.objectweb.cjdbc.common.xml.XmlTools;
92 import org.objectweb.cjdbc.console.gui.constants.GuiCommands;
93 import org.objectweb.cjdbc.console.gui.constants.GuiConstants;
94 import org.objectweb.cjdbc.console.gui.constants.GuiIcons;
95 import org.objectweb.cjdbc.console.gui.dnd.listeners.BackendTransferListener;
96 import org.objectweb.cjdbc.console.gui.dnd.listeners.ControllerTransferListener;
97 import org.objectweb.cjdbc.console.gui.frames.GuiExceptionFrame;
98 import org.objectweb.cjdbc.console.gui.frames.GuiInputBackupFrame;
99 import org.objectweb.cjdbc.console.gui.frames.GuiNewControllerFrame;
100 import org.objectweb.cjdbc.console.gui.frames.GuiSelectCheckpointFrame;
101 import org.objectweb.cjdbc.console.gui.frames.GuiSelectShutdownFrame;
102 import org.objectweb.cjdbc.console.gui.frames.GuiVirtualDatabaseLoginFrame;
103 import org.objectweb.cjdbc.console.gui.frames.NewBackendFrame;
104 import org.objectweb.cjdbc.console.gui.frames.jmxdesktop.AttributeChangeDialog;
105 import org.objectweb.cjdbc.console.gui.frames.jmxdesktop.OperationCallDialog;
106 import org.objectweb.cjdbc.console.gui.jtools.JMultiLineToolTip;
107 import org.objectweb.cjdbc.console.gui.jtools.JTextAreaWriter;
108 import org.objectweb.cjdbc.console.gui.model.AttributeModel;
109 import org.objectweb.cjdbc.console.gui.model.JNewList;
110 import org.objectweb.cjdbc.console.gui.model.OperationModel;
111 import org.objectweb.cjdbc.console.gui.objects.BackendObject;
112 import org.objectweb.cjdbc.console.gui.objects.ConfigurationFileObject;
113 import org.objectweb.cjdbc.console.gui.objects.ControllerObject;
114 import org.objectweb.cjdbc.console.gui.objects.DatabaseObject;
115 import org.objectweb.cjdbc.console.gui.objects.DumpFileObject;
116 import org.objectweb.cjdbc.console.gui.objects.tooltips.BackendToolTip;
117 import org.objectweb.cjdbc.console.gui.popups.ConfigurationFilePopUpMenu;
118 import org.objectweb.cjdbc.console.gui.popups.ControllerListPopUpMenu;
119 import org.objectweb.cjdbc.console.gui.popups.ControllerPopUpMenu;
120 import org.objectweb.cjdbc.console.gui.popups.DatabasePopUpMenu;
121 import org.objectweb.cjdbc.console.gui.popups.DumpPopUpMenu;
122 import org.objectweb.cjdbc.console.gui.popups.LogEditPopUpMenu;
123 import org.objectweb.cjdbc.console.gui.session.GuiSession;
124 import org.objectweb.cjdbc.console.gui.threads.GuiLoggingThread;
125 import org.objectweb.cjdbc.console.gui.threads.GuiParsingThread;
126 import org.objectweb.cjdbc.console.gui.threads.task.BackupBackendTask;
127 import org.objectweb.cjdbc.console.gui.threads.task.RestoreBackendTask;
128 import org.objectweb.cjdbc.console.jmx.RmiJmxClient;
129 import org.objectweb.cjdbc.console.monitoring.MonitoringConsole;
130 import org.objectweb.cjdbc.console.text.ConsoleException;
131 import org.objectweb.cjdbc.console.views.CacheStatsViewer;
132 import org.objectweb.cjdbc.console.views.CacheViewer;
133 import org.objectweb.cjdbc.console.views.RecoveryLogViewer;
134 import org.objectweb.cjdbc.console.views.SQLStatViewer;
135
136 /**
137  * This class is the main class for the graphical version of the C-JDBC
138  * administration console.
139  *
140  * @author <a HREF="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modrzyk </a>
141  * @author <a HREF="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
142  * @version 1.0
143  */

144 public class CjdbcGui extends JFrame JavaDoc
145 {
146   // /////////////////////////////////////////////////////////////
147
// DATA CONTAINERS
148
// /////////////////////////////////////////////////////////////
149
/** Stored values for session */
150   GuiSession guiSession;
151   /** Virtual database MBeans [DatabaseName] / [VirtualDatabaseJmxClient] */
152   Hashtable JavaDoc databaseMBeans;
153   /** Controller MBeans [URL] / [ControllerJmxClient] */
154   Hashtable JavaDoc controllerMBeans;
155   /** Hastable of backends states: [StateName] / [Panel] */
156   Hashtable JavaDoc backendsState;
157   /** List of backends [backendName] : [BackendObject] */
158   Hashtable JavaDoc backendList;
159   /** List of databases [databaseName] : [DatabaseObject] */
160   Hashtable JavaDoc databaseList;
161   /** List of controllers [controllerName] : [ControllerObject] */
162   Hashtable JavaDoc controllerList;
163
164   /** List of jmx clients [url] : [RmiJmxClient] */
165   Hashtable JavaDoc jmxClients;
166   RmiJmxClient currentJmxClient;
167   String JavaDoc selectedController;
168   String JavaDoc selectedDatabase;
169
170   Object JavaDoc credentials = null;
171
172   JNewList mbeanList;
173
174   // /////////////////////////////////////////////////////////////
175
// THREADS
176
// /////////////////////////////////////////////////////////////
177
/** The thread that connects to the log4j server on a host */
178   GuiLoggingThread logginThread;
179
180   // /////////////////////////////////////////////////////////////
181
// MIXED CONTAINERS
182
// /////////////////////////////////////////////////////////////
183
/** The panel for the list of databases */
184   JPanel JavaDoc vdbListPanel;
185   /** The list containing the xml file NAMES, no paths */
186   JPanel JavaDoc fileListPanel;
187   /** Panel for controller list */
188   JPanel JavaDoc controllerListPanel;
189
190   // /////////////////////////////////////////////////////////////
191
// FLOATING FRAMES
192
// /////////////////////////////////////////////////////////////
193
/** Login frame */
194   GuiVirtualDatabaseLoginFrame loginFrame;
195   /** New controller frame objects */
196   GuiNewControllerFrame newControllerFrame;
197   /** Exception frame for reporting errors from the server */
198   GuiExceptionFrame exceptionFrame;
199   /** New Backend frame object */
200   NewBackendFrame newBackendFrame;
201   /** Select checkpoint frame */
202   GuiSelectCheckpointFrame selectCheckpointFrame;
203   /** Select shutdown frame */
204   GuiSelectShutdownFrame selectShutdownFrame;
205   /** Select backup frame */
206   GuiInputBackupFrame inputBackupFrame;
207
208   // /////////////////////////////////////////////////////////////
209
// LISTENERS
210
// /////////////////////////////////////////////////////////////
211
/** Backend transfer listener used for drag and drop */
212   BackendTransferListener backendTransferListener;
213   /** Configuration File transfer listener used for drag and drop */
214   ControllerTransferListener configurationFileTransferListener;
215
216   /** GuiAction listener */
217   CjdbcGuiListener guiActionListener;
218
219   // /////////////////////////////////////////////////////////////
220
// GRAPHIC CONTAINERS
221
// /////////////////////////////////////////////////////////////
222

223   /** The texts of the debug,logging panel */
224   String JavaDoc debugText, loggingText;
225   /** The debug panel itself */
226   JTextArea JavaDoc debugTextPane, loggingTextPane;
227   /** The log panel itself */
228   JTextPane JavaDoc infoTextPane;
229   /** The thread that parse the xml panel */
230   GuiParsingThread parsingThread;
231   /** The xml editor panel */
232   JTextPane JavaDoc xmlTextPane;
233   /** the file chooser for configuration files */
234   JFileChooser JavaDoc configurationFileChooser;
235   /** the file chooser for jar files */
236   JFileChooser JavaDoc jarFileChooser;
237   /** the save file chooser for files */
238   JFileChooser JavaDoc saveFileChooser;
239   /** Backend pane */
240   JPanel JavaDoc backendPanel;
241   /** The controller list mouse listener */
242   ControllerListPopUpMenu controllerListPopUpMenu;
243   /** The center Pane */
244   JTabbedPane JavaDoc centerPane;
245   /** Scroll panel for selection in center pane */
246   JScrollPane JavaDoc helpScroll, debugScroll, xmlScroll,
247       loggingScroll, infoScroll, logConfigScroll;
248   /** Scroll panels from the left pane */
249   JScrollPane JavaDoc fileScroll;
250   /** The panel for exceptions tracing */
251   JTextArea JavaDoc debugTraceTextPane;
252   /** Writer to the trace exception area in the backend panel */
253   JTextAreaWriter traceWriter;
254   /** The panel for the log4j configuration */
255   JTextPane JavaDoc logConfigTextPane;
256   /** Panels for the backend panel */
257   JPanel JavaDoc backendButtons, backendIcons;
258
259   JDesktopPane JavaDoc jmxPanel;
260   JScrollPane JavaDoc jmxScroll;
261   JScrollPane JavaDoc attributePane;
262   JTable JavaDoc attributeTable;
263   JTable JavaDoc operationTable;
264   JScrollPane JavaDoc operationPane;
265
266   JInternalFrame JavaDoc mbeanFrame;
267   JInternalFrame JavaDoc attributeFrame;
268   JInternalFrame JavaDoc operationFrame;
269
270   /**
271    * Creates a new <code>CjdbcGui.java</code> object
272    */

273   public CjdbcGui()
274   {
275     super(GuiTranslate.get("gui.name"));
276     new Thread JavaDoc(new CjdbcGuiLoader(this)).start();
277   }
278
279   private ControllerMBean actionGetControllerBean(String JavaDoc controllerName)
280   {
281     if (controllerMBeans.containsKey(controllerName))
282     {
283       currentJmxClient = (RmiJmxClient) jmxClients.get(controllerName);
284       if (currentJmxClient.isValidConnection())
285       {
286         ControllerMBean controllerMBean = (ControllerMBean) controllerMBeans
287             .get(controllerName);
288         ((ControllerObject) controllerList.get(controllerName))
289             .setIcon(GuiIcons.CONTROLLER_READY);
290         return controllerMBean;
291       }
292       else
293       {
294         appendDebugText("Controller :" + controllerName
295             + " cannot be accessed anymore. Trying to reconnect...");
296         controllerMBeans.remove(controllerName);
297         return actionGetControllerBean(controllerName);
298       }
299     }
300     else
301     {
302       try
303       {
304         RmiJmxClient jmxClient = new RmiJmxClient(controllerName, credentials);
305         appendDebugText("Setting listener for controller:" + controllerName);
306         jmxClient.setNotificationListener(guiActionListener);
307         jmxClients.put(controllerName, jmxClient);
308         controllerMBeans.put(controllerName, jmxClient.getControllerProxy());
309         if (selectedController == null
310             || controllerName.equalsIgnoreCase(selectedController))
311           currentJmxClient = jmxClient;
312
313         appendDebugText("Connected to: " + controllerName);
314         actionStartControllerLoggingThread(controllerName);
315
316         ControllerObject co = ((ControllerObject) controllerList
317             .get(controllerName));
318         if (co != null)
319           co.setIcon(GuiIcons.CONTROLLER_READY);
320         return jmxClient.getControllerProxy();
321       }
322       catch (Exception JavaDoc e)
323       {
324         appendDebugText("Failed to connect to: " + controllerName);
325         ControllerObject co = ((ControllerObject) controllerList
326             .get(controllerName));
327         if (co != null)
328           co.setIcon(GuiIcons.CONTROLLER_DOWN);
329         return null;
330       }
331     }
332   }
333
334   private void actionStartControllerLoggingThread(String JavaDoc controllerName)
335   {
336     try
337     {
338       RmiJmxClient client = (RmiJmxClient) jmxClients.get(controllerName);
339       String JavaDoc ip = client.getRemoteHostAddress();
340
341       if (logginThread != null)
342         logginThread.quit();
343       logginThread = new GuiLoggingThread(loggingTextPane, ip);
344       logginThread.start();
345       appendDebugText("Log4j logging thread started for: <" + controllerName
346           + ">");
347     }
348     catch (Exception JavaDoc e1)
349     {
350       e1.printStackTrace();
351       appendDebugText("Could not start log4j logging thread to: <"
352           + controllerName + ">");
353     }
354   }
355
356   private VirtualDatabaseMBean actionGetDatabaseBean(String JavaDoc databaseName)
357   {
358     if (databaseMBeans.containsKey(databaseName))
359     {
360       return (VirtualDatabaseMBean) databaseMBeans.get(databaseName);
361     }
362     else
363     {
364       appendDebugText("Login to database:" + databaseName);
365       DatabaseObject dob = (DatabaseObject) databaseList.get(databaseName);
366       if (dob == null)
367       {
368         appendDebugText("Failed to retrieve " + databaseName
369             + " from internal list");
370         return null;
371       }
372       loginFrame = new GuiVirtualDatabaseLoginFrame(this, guiActionListener,
373           databaseName, dob.getIpAdress(), dob.getPort(), guiSession);
374       loginFrame.setVisible(true);
375       return null;
376     }
377   }
378
379   private void actionLoadDatabaseList(String JavaDoc controllerName)
380   {
381     // /////////////////////////////////////////////////////////////////////////
382
// Load list of database
383
// /////////////////////////////////////////////////////////////////////////
384
ControllerMBean controllerMBean = actionGetControllerBean(controllerName);
385     ArrayList JavaDoc databases;
386     try
387     {
388       vdbListPanel.removeAll();
389       databases = controllerMBean.getVirtualDatabaseNames();
390       int size = databases.size();
391       appendDebugText("Loading virtual databases list...");
392       for (int i = 0; i < size; i++)
393         actionLoadDatabase((String JavaDoc) databases.get(i), controllerName);
394     }
395     catch (Exception JavaDoc e1)
396     {
397       e1.printStackTrace();
398       appendDebugText("Cannot load virtual database list (" + e1.getMessage()
399           + ")");
400       vdbListPanel.removeAll();
401     }
402     paintDatabasePanel();
403     repaint();
404   }
405
406   void actionUnloadBackends(String JavaDoc controller)
407   {
408     appendDebugText("Unloading backends from controller:" + controller);
409     Enumeration JavaDoc enume;
410     BackendObject bo;
411     String JavaDoc name;
412     while ((enume = backendList.keys()).hasMoreElements())
413     {
414       name = (String JavaDoc) enume.nextElement();
415       bo = (BackendObject) backendList.get(name);
416       bo.setVisible(false);
417       backendList.remove(name);
418       bo = null;
419     }
420   }
421
422   void paintDatabasePanel()
423   {
424     vdbListPanel.validate();
425     vdbListPanel.repaint();
426     validate();
427     repaint();
428   }
429
430   private void actionLoadDatabase(String JavaDoc databaseName, String JavaDoc controllerName)
431   {
432     // /////////////////////////////////////////////////////////////////////////
433
// Load graphic object for a virtual database
434
// /////////////////////////////////////////////////////////////////////////
435
DatabaseObject dob = new DatabaseObject(databaseName, controllerName, false);
436     dob.setActionCommand(GuiCommands.COMMAND_SELECT_DATABASE);
437     dob.addActionListener(guiActionListener);
438     dob.addMouseListener(new DatabasePopUpMenu(this, dob));
439     databaseList.put(databaseName, dob);
440     // We need the object to be in the list before calling getDatabaseBean
441
VirtualDatabaseMBean virtualDatabaseMBean = actionGetDatabaseBean(databaseName);
442     if (virtualDatabaseMBean != null)
443       dob.setDistributed(virtualDatabaseMBean.isDistributed());
444     actionAddObjectToGridLayout(vdbListPanel, dob);
445     appendDebugText("Loaded:" + databaseName + " for controller:"
446         + controllerName);
447   }
448
449   private void actionAddObjectToGridLayout(JPanel JavaDoc panel, JButton JavaDoc button)
450   {
451     GridLayout JavaDoc layout = (GridLayout JavaDoc) panel.getLayout();
452     int pcount = panel.getComponentCount();
453     layout.setRows(pcount + 1);
454     panel.add(button);
455     panel.validate();
456     panel.repaint();
457   }
458
459   /**
460    * Load the list of backends for the given database
461    *
462    * @param databaseName the database to load the backends from
463    */

464   public void publicActionLoadBackendsList(String JavaDoc databaseName)
465   {
466     try
467     {
468       VirtualDatabaseMBean databaseMBean = actionGetDatabaseBean(databaseName);
469       // ArrayList list = actionLoadCheckpointNames(databaseName);
470
ArrayList JavaDoc backends = databaseMBean.getAllBackendNames();
471       appendDebugText("Local Backend list for controller("
472           + currentJmxClient.getRemoteName() + ") is:" + backends);
473       for (int i = 0; i < backends.size(); i++)
474         actionLoadBackend(databaseName, (String JavaDoc) backends.get(i),
475             currentJmxClient.getRemoteName(), true);
476
477       if (databaseMBean.isDistributed())
478       {
479         databaseMBean = actionGetDatabaseBean(databaseName);
480         Hashtable JavaDoc map;
481         try
482         {
483           map = databaseMBean.viewGroupBackends();
484           Enumeration JavaDoc enumeration = map.keys();
485           while (enumeration.hasMoreElements())
486           {
487             String JavaDoc controllerName = (String JavaDoc) enumeration.nextElement();
488             ArrayList JavaDoc list = (ArrayList JavaDoc) map.get(controllerName);
489             for (int i = 0; i < list.size(); i++)
490             {
491               BackendInfo info = (BackendInfo) list.get(i);
492               String JavaDoc backendName = info.getName();
493               actionLoadBackend(databaseName, backendName, controllerName,
494                   false);
495             }
496           }
497         }
498         catch (RuntimeException JavaDoc e1)
499         {
500           appendDebugText(
501               "Runtime exception while loading distributed database:"
502                   + databaseName, e1);
503         }
504
505       }
506       paintBackendPane();
507     }
508     catch (Exception JavaDoc e)
509     {
510       appendDebugText("Could not retrieve backend list for database"
511           + databaseName, e);
512     }
513   }
514
515   /**
516    * Create a new database backend object and load its state
517    *
518    * @param database the virtual database name
519    * @param backendName the backend name
520    * @param controllerName the controller that owns this backend
521    * @param enable if the backend object should be enabled. (not used?)
522    */

523   public void actionLoadBackend(String JavaDoc database, String JavaDoc backendName,
524       String JavaDoc controllerName, boolean enable)
525   {
526     BackendObject backend = null;
527     if (!backendList.containsKey(backendName))
528     {
529       appendDebugText("Loading backend:" + backendName + " from controller:"
530           + controllerName);
531       try
532       {
533         backend = new BackendObject(this, backendTransferListener, database,
534             backendName, controllerName)
535         {
536           public JToolTip JavaDoc createToolTip()
537           {
538             return new JMultiLineToolTip();
539           }
540         };
541       }
542       catch (Exception JavaDoc e)
543       {
544         e.printStackTrace();
545       }
546       backend.setBorder(BorderFactory.createTitledBorder(
547           GuiConstants.LOWERED_BORDER, controllerName));
548       backend.setControllerName(controllerName);
549       backendList.put(backendName, backend);
550     }
551     else
552     {
553       backend = (BackendObject) backendList.get(backendName);
554       backend.setBorder(BorderFactory.createTitledBorder(
555           GuiConstants.LOWERED_BORDER, controllerName));
556       backend.setControllerName(controllerName);
557       backend.setEnabled(controllerName.equals(selectedController));
558       appendDebugText("ReLoading backend:" + backendName);
559     }
560
561     try
562     {
563       actionSetBackendState(backendName);
564     }
565     catch (RuntimeException JavaDoc e)
566     {
567       appendDebugText("cannot access mbean anymore");
568       publicActionRemoveBackendFromGui(backendName);
569     }
570   }
571
572   /**
573    * Converts a JMX state to a Gui constants values
574    *
575    * @param jmxState the JMX state to convert
576    * @return the GUI constant value or null if not found
577    * @see GuiConstants
578    */

579   private String JavaDoc actionConvertState(String JavaDoc jmxState)
580   {
581     if (jmxState == null)
582       return null;
583
584     appendDebugText("Converting new jmx state:" + jmxState);
585
586     if (jmxState
587         .equalsIgnoreCase(CjdbcNotificationList.VIRTUALDATABASE_BACKEND_ENABLED))
588       return GuiConstants.BACKEND_STATE_ENABLED;
589     else if (jmxState
590         .equalsIgnoreCase(CjdbcNotificationList.VIRTUALDATABASE_BACKEND_ENABLED_WRITE))
591       return GuiConstants.BACKEND_STATE_ENABLED;
592     else if (jmxState
593         .equalsIgnoreCase(CjdbcNotificationList.VIRTUALDATABASE_BACKEND_DISABLED))
594       return GuiConstants.BACKEND_STATE_DISABLED;
595     else if (jmxState
596         .equalsIgnoreCase(CjdbcNotificationList.VIRTUALDATABASE_BACKEND_DISABLING))
597       return GuiConstants.BACKEND_STATE_DISABLED;
598     else if (jmxState
599         .equalsIgnoreCase(CjdbcNotificationList.VIRTUALDATABASE_BACKEND_BACKINGUP))
600       return GuiConstants.BACKEND_STATE_BACKUP;
601     else if (jmxState
602         .equalsIgnoreCase(CjdbcNotificationList.VIRTUALDATABASE_BACKEND_RECOVERING))
603       return GuiConstants.BACKEND_STATE_RESTORE;
604     else if (jmxState
605         .equalsIgnoreCase(CjdbcNotificationList.VIRTUALDATABASE_BACKEND_REPLAYING))
606       return GuiConstants.BACKEND_STATE_RECOVERY;
607     else if (jmxState
608         .equalsIgnoreCase(CjdbcNotificationList.VIRTUALDATABASE_BACKEND_UNKNOWN))
609       return GuiConstants.BACKEND_STATE_DISABLED;
610     else
611       return null;
612   }
613
614   /**
615    * Change the state of a backend object Checks the new state is valid, and
616    * then display the backend object into the new panel. Removes it from the old
617    * panel as well. Calls repaint of each panel. This is not connected to the
618    * actual database the backend object is referenced from because many states
619    * do not exist on the controller
620    *
621    * @param bo the backend object
622    * @param newState new state to assign to the backend
623    */

624   public void actionChangeBackendState(BackendObject bo, String JavaDoc newState)
625   {
626     // test if the new state is valid
627
if (!GuiConstants.isValidBackendState(newState))
628       return;
629
630     // State is valid, process
631

632     // Removed from old panel
633
String JavaDoc oldState = bo.getState();
634     JPanel JavaDoc oldpanel = (JPanel JavaDoc) backendsState.get(oldState);
635     oldpanel.remove(bo);
636     oldpanel.validate();
637     oldpanel.repaint();
638
639     // Change the state of the backend object
640
bo.setState(newState);
641
642     // Add it to thew new state panel
643
JPanel JavaDoc panel = (JPanel JavaDoc) backendsState.get(newState);
644     panel.add(bo);
645     panel.validate();
646     panel.repaint();
647   }
648
649   /**
650    * Set the state of the given backend. The state is retrieved via a jmx call
651    * on the backend corresponding MBean.
652    *
653    * @param backendName the backend to set the state
654    */

655   public void actionSetBackendState(String JavaDoc backendName)
656   {
657     try
658     {
659       BackendObject bo = (BackendObject) backendList.get(backendName);
660       if (bo == null)
661       {
662         appendDebugText("Backend (" + backendName + ") cannot be found");
663         return;
664       }
665       String JavaDoc controllerName = bo.getControllerName();
666       if (controllerName == null)
667       {
668         appendDebugText("Backend (" + backendName
669             + ") has lost its controller reference.");
670         appendDebugText("Removing backend (" + backendName
671             + ") from display list.");
672         backendList.remove(backendName);
673         return;
674       }
675       if (selectedController.equals(controllerName))
676         bo.setEnabled(true);
677       else
678         bo.setEnabled(false);
679       String JavaDoc state = bo.getState();
680       appendDebugText("STATE:" + state);
681       String JavaDoc login = guiSession.getAuthenticatedDatabaseLogin(bo.getDatabase());
682       String JavaDoc password = guiSession.getAuthenticatedDatabasePassword(bo
683           .getDatabase());
684       RmiJmxClient client = (RmiJmxClient) jmxClients.get(controllerName);
685       DatabaseBackendMBean backend = null;
686       VirtualDatabaseMBean databaseMBean = null;
687
688       try
689       {
690         backend = client.getDatabaseBackendProxy(bo.getDatabase(), backendName,
691             login, password);
692         databaseMBean = client.getVirtualDatabaseProxy(bo.getDatabase(), login,
693             password);
694       }
695       catch (Exception JavaDoc e)
696       {
697         appendDebugText("Could not change state of backend:" + backendName,
698             new JmxException("MBean connection was lost"));
699       }
700       String JavaDoc newState = actionConvertState(backend.getState());
701
702       actionSetBackendState(backendName, newState);
703
704       // set Tool tip after state
705
try
706       {
707         String JavaDoc[] data = databaseMBean.viewBackendInformation(backendName);
708         bo.setToolTipText(new BackendToolTip(data).getFormattedToolTip());
709       }
710       catch (Exception JavaDoc e)
711       {
712         appendDebugText("Tool tip could not be collected for backend:"
713             + backendName);
714       }
715     }
716     catch (Exception JavaDoc e)
717     {
718       appendDebugText("Could not change state of backend:" + backendName, e);
719     }
720   }
721
722   /**
723    * Change panel of backend
724    *
725    * @param backendName name of backend
726    * @param newState new state
727    */

728   public void actionSetBackendState(String JavaDoc backendName, String JavaDoc newState)
729   {
730     BackendObject bo = (BackendObject) backendList.get(backendName);
731     appendDebugText("Setting backend(" + backendName + "):" + bo.getName()
732         + " to state:" + newState);
733
734     String JavaDoc state = bo.getState();
735     if (state == null)
736     {
737       // state has not been inited
738
}
739     else
740     {
741       // remove previous state
742
JPanel JavaDoc panel = (JPanel JavaDoc) backendsState.get(state);
743       panel.remove(bo);
744       panel.validate();
745       panel.repaint();
746     }
747
748     // Set new state
749
JPanel JavaDoc panel = (JPanel JavaDoc) backendsState.get(newState);
750     bo.setState(newState);
751
752     panel.add(bo);
753     panel.validate();
754     panel.repaint();
755
756   }
757
758   /**
759    * Validate and Repaint the backend split
760    */

761   public void paintBackendPane()
762   {
763     // ////////////////////////////////////////////////////////////////////////
764
// Paint backends panel
765
// /////////////////////////////////////////////////////////////////////////
766
backendPanel.validate();
767     backendPanel.repaint();
768   }
769
770   void paintConfigurationPane()
771   {
772     // ////////////////////////////////////////////////////////////////////////
773
// Paint configuration file panel
774
// /////////////////////////////////////////////////////////////////////////
775
fileScroll.setVisible(true);
776     fileListPanel.setVisible(true);
777     fileScroll.validate();
778     fileListPanel.validate();
779     fileScroll.repaint();
780   }
781
782   String JavaDoc actionLoadXmlText(File JavaDoc filePath)
783   {
784     // /////////////////////////////////////////////////////////////////////////
785
// Load xml file content
786
// /////////////////////////////////////////////////////////////////////////
787
try
788     {
789       if (filePath == null || !filePath.exists())
790       {
791         return "";
792       }
793       StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
794       BufferedReader JavaDoc reader = new BufferedReader JavaDoc(new FileReader JavaDoc(filePath));
795       String JavaDoc line = "";
796       while ((line = reader.readLine()) != null)
797       {
798         buffer.append(line + System.getProperty("line.separator"));
799       }
800       reader.close();
801       return buffer.toString();
802     }
803     catch (Exception JavaDoc e)
804     {
805       appendDebugText("Error while reading from file:" + e.getMessage());
806       return "";
807     }
808   }
809
810   /**
811    * Append debug text to the debug panel
812    *
813    * @param text to append
814    */

815   public void appendDebugText(String JavaDoc text)
816   {
817     debugText += text + System.getProperty("line.separator");
818     debugTextPane.setText(debugText);
819   }
820
821   /**
822    * Same as above and displays the stack trace ...
823    *
824    * @param text text to display
825    * @param e the exception to get the trace from
826    */

827   public void appendDebugText(String JavaDoc text, Exception JavaDoc e)
828   {
829     try
830     {
831       if (GuiConstants.DEBUG_LEVEL <= GuiConstants.DEBUG_NO_EXCEPTION_WINDOW)
832       {
833         if (e instanceof MBeanException JavaDoc)
834           exceptionFrame.showException(((MBeanException JavaDoc) e)
835               .getTargetException());
836         else
837           exceptionFrame.showException(e);
838       }
839       appendDebugText(text + "[Message:" + e.getMessage() + "]");
840       traceWriter.write("---- Exception ----\n");
841       e.printStackTrace(new PrintWriter JavaDoc(traceWriter));
842       traceWriter.flush();
843     }
844     catch (IOException JavaDoc e1)
845     {
846       // ignore . . .
847
}
848   }
849
850   /**
851    * Show the file chooser to add an xml file to the configuration list
852    */

853   public void publicActionAddXmlFile()
854   {
855     if (configurationFileChooser == null)
856     {
857       configurationFileChooser = new JFileChooser JavaDoc(".");
858       configurationFileChooser.setFileFilter(new FileFilter JavaDoc()
859       {
860         /**
861          * @see javax.swing.filechooser.FileFilter#accept(java.io.File)
862          */

863         public boolean accept(File JavaDoc f)
864         {
865           if (f.getAbsolutePath().endsWith(".xml") || f.isDirectory())
866             return true;
867           else
868             return false;
869         }
870
871         /**
872          * @see javax.swing.filechooser.FileFilter#getDescription()
873          */

874         public String JavaDoc getDescription()
875         {
876           return "Xml Files";
877         }
878       });
879     }
880     configurationFileChooser.showOpenDialog(this);
881     File JavaDoc selFile = configurationFileChooser.getSelectedFile();
882     if (selFile != null)
883     {
884       appendDebugText("Selected new file:" + selFile.getAbsolutePath());
885       guiSession.addFileToConfigurationFiles(selFile);
886       ConfigurationFileObject cfo = new ConfigurationFileObject(
887           configurationFileTransferListener, selFile);
888       ConfigurationFilePopUpMenu cfpum = new ConfigurationFilePopUpMenu(this,
889           cfo);
890       cfo.addActionListener(cfpum);
891       cfo.addMouseListener(cfpum);
892       actionAddObjectToGridLayout(fileListPanel, cfo);
893       paintConfigurationPane();
894     }
895   }
896
897   void actionLoadXmlList()
898   {
899     if (fileListPanel != null)
900     {
901       ArrayList JavaDoc vfileItems = guiSession.getConfigurationFiles();
902       int vsize = vfileItems.size();
903       ConfigurationFileObject cfo;
904       for (int i = 0; i < vsize; i++)
905       {
906         cfo = new ConfigurationFileObject(configurationFileTransferListener,
907             (File JavaDoc) vfileItems.get(i));
908         ConfigurationFilePopUpMenu cfpum = new ConfigurationFilePopUpMenu(this,
909             cfo);
910         cfo.addActionListener(cfpum);
911         cfo.addMouseListener(cfpum);
912         fileListPanel.add(cfo);
913         actionAddObjectToGridLayout(fileListPanel, cfo);
914       }
915       // paintConfigurationPane();
916
}
917   }
918
919   private ArrayList JavaDoc actionLoadCheckpointNames(String JavaDoc databaseName)
920   {
921     ArrayList JavaDoc list = actionGetDatabaseBean(databaseName).viewCheckpointNames();
922     for (int i = 0; i < list.size(); i++)
923       appendDebugText("Found checkpoint:" + list.get(i) + " for database:"
924           + databaseName);
925     return list;
926   }
927
928   /**
929    * Load the controller list. Removes all the controller icons from the panel.
930    * and get all the controllers from the session hashtable Then calls
931    * <code>actionLoadController</code>
932    */

933   public void publicActionLoadControllerList()
934   {
935     if (controllerListPanel != null)
936     {
937       controllerListPanel.removeAll();
938       ArrayList JavaDoc controllerItems = guiSession.getControllerItems();
939       int size = controllerItems.size();
940       for (int i = 0; i < size; i++)
941         actionLoadController((String JavaDoc) controllerItems.get(i));
942       paintControllerPane();
943     }
944   }
945
946   /**
947    * Paint the controller panel
948    */

949   void paintControllerPane()
950   {
951     controllerListPanel.validate();
952     controllerListPanel.repaint();
953   }
954
955   /**
956    * View the controller frame to add a new controller reference to the list
957    */

958   public void publicActionAddControllerView()
959   {
960     newControllerFrame.setVisible(true);
961   }
962
963   /**
964    * actionDatabaseEnableAll definition. Call the proper MBean to enable all
965    * backends
966    *
967    * @param databaseName the name of the database to operate
968    */

969   public void publicActionDatabaseEnableAll(String JavaDoc databaseName)
970   {
971     try
972     {
973       actionGetDatabaseBean(databaseName).enableAllBackends();
974       publicActionLoadBackendsList(databaseName);
975       centerPane.setSelectedComponent(backendPanel);
976       appendDebugText("Enabled All backends for :" + databaseName
977           + " was a success");
978     }
979     catch (Exception JavaDoc e)
980     {
981       appendDebugText("Enabled All backends for :" + databaseName + " failed",
982           e);
983     }
984   }
985
986   /**
987    * Load a panel for the backends
988    *
989    * @param name the name of the panel
990    */

991   public void actionLoadBackendActionButton(String JavaDoc name)
992   {// ////////////////////////////////////////////////////////////////////////
993
// Define backend action buttons
994
// /////////////////////////////////////////////////////////////////////////
995
appendDebugText("Loading backend action panel:" + name);
996     Color JavaDoc color = GuiConstants.getBackendBgColor(name);
997
998     JPanel JavaDoc paneContent = new JPanel JavaDoc(new FlowLayout JavaDoc());
999     paneContent.setBackground(color);
1000    paneContent.setName(name);
1001    paneContent.setVisible(true);
1002
1003    JButton JavaDoc paneLabel = new JButton JavaDoc(name);
1004    paneLabel.setActionCommand(name);
1005    paneLabel.setBackground(color);
1006    paneLabel.setSize(100, 50);
1007    paneLabel.setVisible(true);
1008
1009    DropTarget JavaDoc target1 = new DropTarget JavaDoc(paneLabel, DnDConstants.ACTION_MOVE,
1010        backendTransferListener);
1011    target1.setActive(true);
1012
1013    DropTarget JavaDoc target2 = new DropTarget JavaDoc(paneContent, DnDConstants.ACTION_MOVE,
1014        backendTransferListener);
1015    target2.setActive(true);
1016
1017    GridLayout JavaDoc iconLayout = (GridLayout JavaDoc) backendIcons.getLayout();
1018    iconLayout.setColumns(iconLayout.getColumns() + 1);
1019    GridLayout JavaDoc buttonsLayout = (GridLayout JavaDoc) backendButtons.getLayout();
1020    buttonsLayout.setColumns(buttonsLayout.getColumns() + 1);
1021    backendIcons.add(paneContent);
1022    backendButtons.add(paneLabel);
1023    // Adding to the main hashtable of states
1024
backendsState.put(name, paneContent);
1025  }
1026
1027  /**
1028   * Load standard version for the panel
1029   *
1030   * @param recoveryEnabled more options are available when recovery log is
1031   * enabled for the database
1032   */

1033  public void actionLoadBackendPane(boolean recoveryEnabled)
1034  {
1035    // ////////////////////////////////////////////////////////////////////////
1036
// Define backend panel
1037
// /////////////////////////////////////////////////////////////////////////
1038
if (backendPanel == null)
1039    {
1040      backendPanel = new JPanel JavaDoc(new BorderLayout JavaDoc());
1041      backendPanel.setEnabled(true);
1042      backendPanel.setBackground(Color.white);
1043      backendPanel.setVisible(true);
1044    }
1045    else
1046    {
1047      backendPanel.remove(backendButtons);
1048      backendPanel.remove(backendIcons);
1049    }
1050
1051    backendButtons = new JPanel JavaDoc(new GridLayout JavaDoc(1, 0));
1052    backendIcons = new JPanel JavaDoc(new GridLayout JavaDoc(1, 0));
1053    backendIcons.setBackground(Color.white);
1054    backendIcons.setVisible(true);
1055    backendButtons.setVisible(true);
1056
1057    actionLoadBackendActionButton(GuiConstants.BACKEND_STATE_ENABLED);
1058    if (recoveryEnabled)
1059      actionLoadBackendActionButton(GuiConstants.BACKEND_STATE_RECOVERY);
1060    actionLoadBackendActionButton(GuiConstants.BACKEND_STATE_DISABLED);
1061    if (recoveryEnabled)
1062      actionLoadBackendActionButton(GuiConstants.BACKEND_STATE_BACKUP);
1063    if (recoveryEnabled)
1064      actionLoadBackendActionButton(GuiConstants.BACKEND_STATE_RESTORE);
1065    backendPanel.add(backendIcons, BorderLayout.CENTER);
1066    backendPanel.add(backendButtons, BorderLayout.NORTH);
1067
1068    centerPane.validate();
1069    centerPane.repaint();
1070    validate();
1071    repaint();
1072  }
1073
1074  /**
1075   * Load the virtual database after authentication.
1076   */

1077  public void publicActionLoadAuthenticatedDatabase()
1078  {
1079    loginFrame.setVisible(false);
1080    try
1081    {
1082      String JavaDoc databaseName = loginFrame.getDatabaseName();
1083      String JavaDoc login = loginFrame.getLoginBox().getText().trim();
1084      String JavaDoc password = loginFrame.getPasswordBox().getText().trim();
1085
1086      VirtualDatabaseMBean mbean = null;
1087      try
1088      {
1089        mbean = currentJmxClient.getVirtualDatabaseProxy(databaseName, login,
1090            password);
1091        if (mbean == null)
1092          throw new IOException JavaDoc("MBean connection lost");
1093      }
1094      catch (IOException JavaDoc ioe)
1095      {
1096        appendDebugText(ioe.getMessage());
1097        actionUnloadBackends(currentJmxClient.getRemoteName());
1098        return;
1099      }
1100
1101      if (!mbean.checkAdminAuthentication(login, password))
1102      {
1103        throw new Exception JavaDoc("Authentication failed");
1104      }
1105
1106      databaseMBeans.put(databaseName, mbean);
1107      guiSession.addDatabaseToSession(databaseName, login, password);
1108
1109      String JavaDoc[] list = mbean.viewControllerList();
1110      for (int i = 0; i < list.length; i++)
1111      {
1112        appendDebugText("Found controllerL" + list[i]);
1113        if (!guiSession.checkControllerInSession(list[i]))
1114        {
1115          actionLoadController(list[i]);
1116          RmiJmxClient client = (RmiJmxClient) jmxClients.get(list[i]);
1117          // get the listeners on the virtual database
1118
client.getVirtualDatabaseProxy(databaseName, login, password);
1119          paintControllerPane();
1120        }
1121      }
1122
1123      boolean recoveryExist = mbean.hasRecoveryLog();
1124      appendDebugText("RecoveryLog is defined for this database:"
1125          + recoveryExist);
1126      actionLoadBackendPane(recoveryExist);
1127
1128      publicActionLoadBackendsList(databaseName);
1129      actionLoadCheckpointNames(databaseName);
1130      publicActionLoadDumpList(databaseName);
1131    }
1132    catch (Exception JavaDoc e1)
1133    {
1134      appendDebugText("Could not connect to database", e1);
1135    }
1136  }
1137
1138  /**
1139   * Quit the GUI
1140   */

1141  public void publicActionQuit()
1142  {
1143    try
1144    {
1145      guiSession.saveSessionToFile(new File JavaDoc(
1146          GuiConstants.CJDBC_DEFAULT_SESSION_FILE));
1147    }
1148    catch (IOException JavaDoc e)
1149    {
1150      System.out.println("Could not save session");
1151    }
1152    System.exit(0);
1153  }
1154
1155  /**
1156   * Add a new driver to the controller. Start the file chooser and use the
1157   * proper MBean
1158   *
1159   * @param controllerName name of the controller
1160   */

1161  public void publicActionLoadDriver(String JavaDoc controllerName)
1162  {
1163    if (jarFileChooser == null)
1164    {
1165      jarFileChooser = new JFileChooser JavaDoc(".");
1166      jarFileChooser.setFileFilter(new FileFilter JavaDoc()
1167      {
1168        /**
1169         * @see javax.swing.filechooser.FileFilter#accept(java.io.File)
1170         */

1171        public boolean accept(File JavaDoc f)
1172        {
1173          if (f.getAbsolutePath().endsWith(".jar") || f.isDirectory())
1174            return true;
1175          else
1176            return false;
1177        }
1178
1179        /**
1180         * @see javax.swing.filechooser.FileFilter#getDescription()
1181         */

1182        public String JavaDoc getDescription()
1183        {
1184          return "Jar Files";
1185        }
1186      });
1187    }
1188    jarFileChooser.showOpenDialog(this);
1189    File JavaDoc selFile = jarFileChooser.getSelectedFile();
1190    try
1191    {
1192      if (selFile != null)
1193      {
1194        ControllerMBean controllerMBean = actionGetControllerBean(controllerName);
1195        controllerMBean.addDriver(readDriver(selFile.getAbsolutePath()));
1196      }
1197    }
1198    catch (Exception JavaDoc e)
1199    {
1200      appendDebugText("Could not load driver from jar file:"
1201          + selFile.getName());
1202    }
1203  }
1204
1205  private byte[] readDriver(String JavaDoc filename) throws FileNotFoundException JavaDoc,
1206      IOException JavaDoc
1207  {
1208    File JavaDoc file;
1209    FileInputStream JavaDoc fileInput = null;
1210    file = new File JavaDoc(filename);
1211    fileInput = new FileInputStream JavaDoc(file);
1212
1213    // Read the file into an array of bytes
1214
long size = file.length();
1215    if (size > Integer.MAX_VALUE)
1216      throw new IOException JavaDoc(ConsoleTranslate
1217          .get("controller.command.adddriver.file.too.big"));
1218    byte[] bytes = new byte[(int) size];
1219    int nb = fileInput.read(bytes);
1220    fileInput.close();
1221    if (nb != size)
1222      throw new IOException JavaDoc(ConsoleTranslate
1223          .get("controller.command.adddriver.file.not.read"));
1224    return bytes;
1225  }
1226
1227  /**
1228   * Fetch the logs from the controller
1229   *
1230   * @param controllerName the name of the controller
1231   */

1232  public void publicActionRefreshLogs(String JavaDoc controllerName)
1233  {
1234    try
1235    {
1236      ControllerMBean controllerMBean = actionGetControllerBean(controllerName);
1237      loggingTextPane.setText(controllerMBean.generateLogReport());
1238      appendDebugText("Re-Fetched logs for controller:" + controllerName);
1239    }
1240    catch (Exception JavaDoc e)
1241    {
1242      appendDebugText("Fail to fetch logs for controller:" + controllerName, e);
1243    }
1244  }
1245
1246  /**
1247   * Clean the debug buffer
1248   */

1249  public void publicActionCleanDebugBuffer()
1250  {
1251    debugText = "";
1252    debugTextPane.setText("");
1253  }
1254
1255  /**
1256   * saveConfigurationFile definition. Starts the JFile Chooser and write the
1257   * xml content to the selected file
1258   */

1259  public void publicActionSaveConfigurationFile()
1260  {
1261    try
1262    {
1263      if (saveFileChooser == null)
1264      {
1265        saveFileChooser = new JFileChooser JavaDoc();
1266        saveFileChooser.showSaveDialog(this);
1267        File JavaDoc selected = saveFileChooser.getSelectedFile();
1268        if (selected != null)
1269        {
1270          BufferedWriter JavaDoc writer = new BufferedWriter JavaDoc(new FileWriter JavaDoc(selected));
1271          writer.write(xmlTextPane.getText());
1272          writer.close();
1273        }
1274        else
1275        {
1276          appendDebugText("Did not select a file was saving...");
1277        }
1278      }
1279    }
1280    catch (Exception JavaDoc e)
1281    {
1282      appendDebugText("Error while writing to file:" + e.getMessage());
1283    }
1284  }
1285
1286  /**
1287   * add a Controller to the list.
1288   */

1289  public void publicActionAddController()
1290  {
1291    newControllerFrame.setVisible(false);
1292    String JavaDoc ipAddress = newControllerFrame.getIpAddressBox().getText().trim();
1293    String JavaDoc port = newControllerFrame.getPortNumber().getText().trim();
1294    appendDebugText("Add controller with ip:" + ipAddress + " amd port:" + port);
1295    String JavaDoc name = ipAddress + ":" + port;
1296    if (guiSession.checkControllerInSession(name))
1297    {
1298      String JavaDoc message = GuiTranslate.get("error.controller.already.in.session");
1299      CJDBCException e = new CJDBCException(message);
1300      appendDebugText(message, e);
1301    }
1302    else
1303    {
1304      actionLoadController(name);
1305      paintControllerPane();
1306    }
1307  }
1308
1309  /**
1310   * Load a new controller, the graphic object, the connection state and add it
1311   * to the controller pane list.
1312   *
1313   * @param name the name(url) of the controller
1314   */

1315  private void actionLoadController(String JavaDoc name)
1316  {
1317    guiSession.addControllerToList(name);
1318    ControllerObject co = new ControllerObject(name);
1319    co.setActionCommand(GuiCommands.COMMAND_SELECT_CONTROLLER);
1320    co.addActionListener(guiActionListener);
1321    co.addMouseListener(new ControllerPopUpMenu(this, co));
1322    ControllerMBean controllerMBean = actionGetControllerBean(name);
1323    if (controllerMBean == null)
1324    {
1325      appendDebugText("Cannot load controller:" + name);
1326      return;
1327    }
1328    DropTarget JavaDoc target = new DropTarget JavaDoc(co, DnDConstants.ACTION_MOVE,
1329        configurationFileTransferListener);
1330    co.setDropTarget(target);
1331    appendDebugText("Loading controller:" + controllerMBean.getJmxName());
1332    if (currentJmxClient.isValidConnection())
1333    {
1334      co.setState(GuiConstants.CONTROLLER_STATE_UP);
1335    }
1336    else
1337    {
1338      co.setState(GuiConstants.CONTROLLER_STATE_DOWN);
1339    }
1340    actionAddObjectToGridLayout(controllerListPanel, co);
1341    controllerList.put(name, co);
1342  }
1343
1344  /**
1345   * Action when a new controller has been selected
1346   *
1347   * @param connectUrl the url of the controller that was selected
1348   */

1349  public void publicActionSelectNewController(String JavaDoc connectUrl)
1350  {
1351    Enumeration JavaDoc enume = controllerList.keys();
1352    String JavaDoc key = "";
1353    ControllerObject controller;
1354    while (enume.hasMoreElements())
1355    {
1356      key = (String JavaDoc) enume.nextElement();
1357      controller = (ControllerObject) controllerList.get(key);
1358      if (key.equalsIgnoreCase(connectUrl))
1359      {
1360        controller.setBorder(GuiConstants.TITLED_BORDER);
1361        controller.setBorderPainted(true);
1362      }
1363      else
1364        controller.setBorderPainted(false);
1365    }
1366    actionGetControllerBean(connectUrl);
1367    selectedController = connectUrl;
1368    actionLoadDatabaseList(connectUrl);
1369    publicActionLoadXmlController(connectUrl);
1370
1371    if (selectedDatabase != null)
1372      publicActionLoadAuthenticatedDatabase();
1373
1374    actionStartControllerLoggingThread(connectUrl);
1375  }
1376
1377  /**
1378   * Returns the selectedController value.
1379   *
1380   * @return Returns the selectedController.
1381   */

1382  public String JavaDoc getSelectedController()
1383  {
1384    return selectedController;
1385  }
1386
1387  /**
1388   * Loads the graphic dump list for this databaser
1389   *
1390   * @param databaseName the virtual database name
1391   */

1392  public void publicActionLoadDumpList(String JavaDoc databaseName)
1393  {
1394    VirtualDatabaseMBean databaseMBean = actionGetDatabaseBean(databaseName);
1395    try
1396    {
1397      // FIXME Recovery Refactoring: getAvailableDumpFiles() -> getAvailableDumps()
1398
// File[] dumps = databaseMBean.getAvailableDumpFiles();
1399
File JavaDoc[] dumps = new File JavaDoc[0];
1400        appendDebugText("Loaded dumps for virtual database:" + databaseName);
1401      JPanel JavaDoc dumpPane = (JPanel JavaDoc) backendsState
1402          .get(GuiConstants.BACKEND_STATE_RESTORE);
1403      dumpPane.removeAll();
1404      for (int i = 0; i < dumps.length; i++)
1405      {
1406        appendDebugText("Adding dump:" + dumps[i]);
1407        DumpFileObject dfo = new DumpFileObject(dumps[i])
1408        {
1409          public JToolTip JavaDoc createToolTip()
1410          {
1411            return new JMultiLineToolTip();
1412          }
1413        };
1414        dfo.addMouseListener(new DumpPopUpMenu(this, databaseName, dfo));
1415        DropTarget JavaDoc target = new DropTarget JavaDoc(dfo, DnDConstants.ACTION_MOVE,
1416            backendTransferListener);
1417        dfo.setDropTarget(target);
1418        dumpPane.add(dfo);
1419      }
1420      paintBackendPane();
1421    }
1422    catch (Exception JavaDoc e)
1423    {
1424      e.printStackTrace();
1425      appendDebugText("Failed to load dumps for virtual database:"
1426          + databaseName + " because of:" + e.getMessage());
1427    }
1428  }
1429
1430  /**
1431   * Load the xml for the given controller Gives the focus to the xml panel with
1432   * the new content
1433   *
1434   * @param connectUrl controllerName
1435   */

1436  public void publicActionLoadXmlController(String JavaDoc connectUrl)
1437  {
1438    try
1439    {
1440      ControllerMBean controllerMBean = actionGetControllerBean(connectUrl);
1441      xmlTextPane.setText(controllerMBean.getXml());
1442      appendDebugText("Loaded xml configuration for controller:" + connectUrl);
1443    }
1444    catch (Exception JavaDoc e)
1445    {
1446      appendDebugText("Failed to get xml configuration for controller:"
1447          + connectUrl);
1448    }
1449  }
1450
1451  /**
1452   * Select a new database action
1453   *
1454   * @param value the name of the virtual dababase
1455   */

1456  public void publicActionSelectNewDatabase(String JavaDoc value)
1457  {
1458    selectedDatabase = value;
1459    try
1460    {
1461      VirtualDatabaseMBean databaseClient = actionGetDatabaseBean(value);
1462      if (databaseClient != null)
1463      {
1464        databaseClient.viewControllerList();
1465        publicActionLoadAuthenticatedDatabase();
1466      }
1467      Enumeration JavaDoc enume = databaseList.keys();
1468      String JavaDoc key = "";
1469      DatabaseObject database;
1470      while (enume.hasMoreElements())
1471      {
1472        key = (String JavaDoc) enume.nextElement();
1473        database = (DatabaseObject) databaseList.get(key);
1474        if (key.equalsIgnoreCase(value))
1475        {
1476          database.setBorder(GuiConstants.TITLED_BORDER);
1477          database.setBorderPainted(true);
1478        }
1479        else
1480          database.setBorderPainted(false);
1481      }
1482    }
1483    catch (Exception JavaDoc e)
1484    {
1485      appendDebugText("Failed to get access to database:" + value, e);
1486    }
1487  }
1488
1489  /**
1490   * Load the xml configuration of the given database and display the xml buffer
1491   *
1492   * @param databaseName virtual database name to get configuration from
1493   */

1494  public void publicActionLoadXmlDatabase(String JavaDoc databaseName)
1495  {
1496    try
1497    {
1498      VirtualDatabaseMBean databaseMBean = actionGetDatabaseBean(databaseName);
1499      xmlTextPane.setText(XmlTools.prettyXml(databaseMBean.getXml()));
1500      appendDebugText("Loaded xml configuration for database:" + databaseName);
1501      centerPane.setSelectedComponent(xmlScroll);
1502    }
1503    catch (Exception JavaDoc e)
1504    {
1505      appendDebugText("Failed to get xml configuration for database:"
1506          + databaseName, e);
1507    }
1508  }
1509
1510  /**
1511   * Select a new configuration load the content of the xml file into the
1512   * xmlTextPane panel
1513   *
1514   * @param file the path to the xml file
1515   */

1516  public void publicActionSelectNewConfigurationFile(String JavaDoc file)
1517  {
1518    try
1519    {
1520      xmlTextPane.setText(actionLoadXmlText(new File JavaDoc(file)));
1521      appendDebugText("Loaded xml configuration for file:" + file);
1522      centerPane.setSelectedComponent(xmlScroll);
1523    }
1524    catch (Exception JavaDoc e)
1525    {
1526      appendDebugText("Failed to load xml for file:" + file);
1527    }
1528  }
1529
1530  /**
1531   * Send a shutdown command to the corresponding database
1532   *
1533   * @param dob database object representing the database to shutdown
1534   * @param shutdownLevel the level to apply for the shutdown
1535   */

1536  public void publicActionShutdownDatabase(DatabaseObject dob, int shutdownLevel)
1537  {
1538    try
1539    {
1540      String JavaDoc databaseName = dob.getName();
1541      VirtualDatabaseMBean vdbMBean = actionGetDatabaseBean(databaseName);
1542      vdbMBean.shutdown(shutdownLevel);
1543      controllerListPanel.remove(dob);
1544      guiSession.getDatabaseItems().remove(databaseName);
1545      String JavaDoc controllerName = dob.getControllerName();
1546      actionUnloadBackends(controllerName);
1547      actionLoadDatabaseList(controllerName);
1548    }
1549    catch (Exception JavaDoc e)
1550    {
1551      appendDebugText("Failed to shutdown database", e);
1552    }
1553  }
1554
1555  /**
1556   * Execute the backend drop action with this gui
1557   *
1558   * @param backendName name of the backend
1559   * @param target the drop target used for the Dnd
1560   */

1561  public void publicActionExecuteBackendDrop(JButton JavaDoc target, String JavaDoc backendName)
1562  {
1563
1564    String JavaDoc actionName = target.getActionCommand();
1565    if (actionName.equals(GuiConstants.BACKEND_STATE_RESTORE))
1566      publicActionRestoreBackend(backendName, ((DumpFileObject) target)
1567          .getDumpName());
1568    else
1569      publicActionExecuteBackendDrop(actionName, backendName);
1570  }
1571
1572  private String JavaDoc actionDisplaySelectCheckpointFrame(String JavaDoc database)
1573  {
1574    VirtualDatabaseMBean databaseMBean = actionGetDatabaseBean(database);
1575    if (selectCheckpointFrame == null)
1576    {
1577      ArrayList JavaDoc list = databaseMBean.viewCheckpointNames();
1578      list.add(GuiConstants.BACKEND_NO_CHECKPOINT);
1579      String JavaDoc[] entries = (String JavaDoc[]) list.toArray(new String JavaDoc[list.size()]);
1580      selectCheckpointFrame = new GuiSelectCheckpointFrame(this, entries,
1581          guiActionListener);
1582      selectCheckpointFrame.setVisible(true);
1583    }
1584
1585    JTextField JavaDoc field = selectCheckpointFrame.getValueField();
1586    selectCheckpointFrame = null;
1587    if (field == null)
1588      return null;
1589    String JavaDoc checkpoint = field.getText();
1590    return checkpoint;
1591  }
1592
1593  /**
1594   * Check if the target column and the current state are the same
1595   *
1596   * @param actionName the action from the DnD
1597   * @param backendName the name of the backend that is the target of the action
1598   * @return true if nothing has changed
1599   */

1600  private boolean isDropInSameColumn(String JavaDoc actionName, String JavaDoc backendName)
1601  {
1602    BackendObject bob = (BackendObject) backendList.get(backendName);
1603    String JavaDoc state = bob.getState();
1604    if (state.equalsIgnoreCase(actionName))
1605      return true;
1606    else
1607      return false;
1608  }
1609
1610  /**
1611   * Execute the backend drop action with this gui
1612   *
1613   * @param actionName action name on the backend
1614   * @param backendName the drop target used for the Dnd
1615   */

1616  public void publicActionExecuteBackendDrop(String JavaDoc actionName,
1617      String JavaDoc backendName)
1618  {
1619    appendDebugText("Got drop backend action:" + actionName + " from:"
1620        + backendName);
1621
1622    BackendObject bob = (BackendObject) backendList.get(backendName);
1623    String JavaDoc database = bob.getDatabase();
1624    VirtualDatabaseMBean databaseMBean = actionGetDatabaseBean(bob
1625        .getDatabase());
1626
1627    /*
1628     * This code does not do anything if
1629     * (actionName.equals(GuiConstants.BACKEND_STATE_RESTORE)) { ControllerMBean
1630     * controller = actionGetControllerBean(databaseMBean
1631     * .viewOwningController()); controller.listAvailableDumpFiles(); //
1632     * GuiSelectDumpFrame dump = new //
1633     * GuiSelectDumpFrame(this,,guiActionListener); }
1634     */

1635
1636    if (isDropInSameColumn(actionName, backendName))
1637    {
1638      appendDebugText("Drop action is not relevant");
1639      return;
1640    }
1641
1642    if (actionName.equals(GuiConstants.BACKEND_STATE_ENABLED))
1643    {
1644      try
1645      {
1646        DatabaseBackendMBean bean = bob.getMbean();
1647        String JavaDoc lastcheck = bean.getLastKnownCheckpoint();
1648        if (lastcheck != null)
1649        {
1650          actionSetBackendState(backendName,
1651              GuiConstants.BACKEND_STATE_RECOVERY);
1652          databaseMBean.enableBackendFromCheckpoint(backendName);
1653          return;
1654        }
1655        else
1656        {
1657          String JavaDoc checkpoint = actionDisplaySelectCheckpointFrame(database);
1658          if (checkpoint == null)
1659          {
1660            appendDebugText("Cancelling enable backend...");
1661            return;
1662          }
1663          appendDebugText("Using checkpoint:" + checkpoint
1664              + " to enable backend:" + backendName);
1665          if (checkpoint.equals(GuiConstants.BACKEND_NO_CHECKPOINT))
1666            databaseMBean.forceEnableBackend(backendName);
1667          else
1668            databaseMBean.enableBackendFromCheckpoint(backendName);
1669        }
1670        // actionSetBackendState(backendName);
1671
}
1672      catch (Exception JavaDoc e)
1673      {
1674        appendDebugText("Failed to enable backend", e);
1675      }
1676    }
1677    else if (actionName.equals(GuiConstants.BACKEND_STATE_DISABLED))
1678    {
1679      try
1680      {
1681        // No recovery log defined.
1682
if (!databaseMBean.hasRecoveryLog())
1683          databaseMBean.forceDisableBackend(backendName);
1684        else
1685        {
1686          String JavaDoc checkpoint = generateCheckpoint(backendName);
1687          //
1688
// actionDisplaySelectCheckpointFrame(database);
1689
// if (checkpoint == null)
1690
// {
1691
// appendDebugText("Cancelling disable backend...");
1692
// return;
1693
// }
1694
appendDebugText("Using autogenerated checkpoint:" + checkpoint
1695              + " to disable backend:" + backendName);
1696          // if (checkpoint.equals(GuiConstants.BACKEND_NO_CHECKPOINT))
1697
// databaseMBean.disableBackend(backendName);
1698
// else
1699
databaseMBean.disableBackendWithCheckpoint(backendName);
1700        }
1701        actionSetBackendState(backendName);
1702      }
1703      catch (Exception JavaDoc e)
1704      {
1705        appendDebugText("Failed to disable backend", e);
1706      }
1707    }
1708    else if (actionName.equals(GuiConstants.BACKEND_STATE_NEW))
1709    {
1710      appendDebugText("Creating new backend from backend:" + bob.getName());
1711      publicActionNewBackendPrompt(bob);
1712    }
1713    else if (actionName.equals(GuiConstants.BACKEND_STATE_BACKUP))
1714    {
1715      publicActionBackupBackendPrompt(bob);
1716    }
1717
1718    actionRefreshBackendState(bob);
1719  }
1720
1721  private void actionRefreshBackendState(BackendObject bob)
1722  {
1723    String JavaDoc state = bob.getState();
1724    JPanel JavaDoc panel = (JPanel JavaDoc) backendsState.get(state);
1725    if (panel.getParent().equals(panel))
1726    {
1727      appendDebugText("refresh of backend:" + bob.getName() + " not needed");
1728    }
1729    else
1730    {
1731      appendDebugText("refresh of backend:" + bob.getName() + " needed");
1732      actionLoadBackend(bob.getDatabase(), bob.getName(), bob
1733          .getControllerName(), bob.isEnabled());
1734      // actionChangeBackendState(bob, bob.getState());
1735
}
1736  }
1737
1738  /**
1739   * Generate a checkpoint name from the given backend and the current date.
1740   *
1741   * @param backendName the backend to generate a checkpoint for
1742   * @return backend name concat date
1743   */

1744  private String JavaDoc generateCheckpoint(String JavaDoc backendName)
1745  {
1746    String JavaDoc check = backendName + ":"
1747        + new SimpleDateFormat JavaDoc("yyyy.MM.dd.HH.mm.ss").format(new Date JavaDoc());
1748    return Strings.replace(check, ":", "-");
1749  }
1750
1751  /**
1752   * Open the frame to fill in details to create a new backend
1753   *
1754   * @param bob the backend to replicate
1755   */

1756  public void publicActionNewBackendPrompt(BackendObject bob)
1757  {
1758    if (newBackendFrame == null)
1759      newBackendFrame = new NewBackendFrame(bob, guiActionListener);
1760    else
1761      newBackendFrame.setBob(bob);
1762    newBackendFrame.setVisible(true);
1763  }
1764
1765  /**
1766   * Restore a backend from a dump file
1767   *
1768   * @param backendName name of the backend
1769   * @param dumpName name of the dump file
1770   */

1771  public void publicActionRestoreBackend(String JavaDoc backendName, String JavaDoc dumpName)
1772  {
1773    BackendObject bob = (BackendObject) backendList.get(backendName);
1774    try
1775    {
1776      if (bob.getMbean().isReadEnabled())
1777      {
1778        String JavaDoc message = "Cannot restore an enabled backend";
1779        appendDebugText(message, new ConsoleException(message));
1780        return;
1781      }
1782    }
1783    catch (Exception JavaDoc e)
1784    {
1785      appendDebugText(e.getMessage(), e);
1786      return;
1787    }
1788    appendDebugText("Restoring backend:" + backendName + " with dump name:"
1789        + dumpName);
1790
1791    VirtualDatabaseMBean database = actionGetDatabaseBean(bob.getDatabase());
1792    new Thread JavaDoc(new RestoreBackendTask(this, database, bob, dumpName)).start();
1793  }
1794
1795  /**
1796   * Execute a backup of the given backend
1797   *
1798   * @param bob the backend object
1799   */

1800  public void publicActionBackupBackendPrompt(BackendObject bob)
1801  {
1802    String JavaDoc checkpoint = actionDisplayInputBackupFrame(bob.getDatabase(), bob
1803        .getName());
1804    if (checkpoint == null)
1805    {
1806      appendDebugText("No dump name received, cancelling action...");
1807      return;
1808    }
1809    VirtualDatabaseMBean database = actionGetDatabaseBean(bob.getDatabase());
1810    new Thread JavaDoc(new BackupBackendTask(this, database, bob, checkpoint)).start();
1811  }
1812
1813  /**
1814   * Display the dump input frame
1815   *
1816   * @param database virtual database to dump
1817   * @param backend backend to dump
1818   * @return dump name
1819   */

1820  private String JavaDoc actionDisplayInputBackupFrame(String JavaDoc database, String JavaDoc backend)
1821  {
1822    VirtualDatabaseMBean databaseMBean = actionGetDatabaseBean(database);
1823    if (inputBackupFrame == null)
1824    {
1825      // FIXME Recovery Refactoring : getAvailableDumpFiles() -> getAvailableDumps()
1826
//File[] files = databaseMBean.getAvailableDumpFiles();
1827
File JavaDoc[] files = new File JavaDoc[0];
1828      int size = files.length;
1829      String JavaDoc[] entries = new String JavaDoc[size];
1830      for (int i = 0; i < size; i++)
1831      {
1832        entries[i] = files[i].getName();
1833      }
1834      inputBackupFrame = new GuiInputBackupFrame(this, entries,
1835          guiActionListener);
1836      inputBackupFrame.setValue(generateCheckpoint(backend));
1837      inputBackupFrame.setVisible(true);
1838    }
1839
1840    JTextField JavaDoc field = inputBackupFrame.getValueField();
1841    inputBackupFrame = null;
1842    if (field == null)
1843      return null;
1844    String JavaDoc dump = field.getText();
1845    return dump;
1846  }
1847
1848  /**
1849   * Set the cursor to be a hand
1850   */

1851  public void publicActionRefreshCursorShape()
1852  {
1853    appendDebugText("Refresh cursor for main frame");
1854    Cursor JavaDoc cursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
1855    setCursor(cursor);
1856    backendPanel.setCursor(cursor);
1857    validate();
1858    repaint();
1859  }
1860
1861  /**
1862   * Load a configuration file on a controller
1863   *
1864   * @param filePath the configuration file
1865   * @param controllerName the name of the controller
1866   */

1867  public void publicActionExecuteControllerDrop(String JavaDoc filePath,
1868      String JavaDoc controllerName)
1869  {
1870    File JavaDoc file = new File JavaDoc(filePath);
1871    try
1872    {
1873      ControllerMBean controllerMBean = actionGetControllerBean(controllerName);
1874      controllerMBean.addVirtualDatabases(actionLoadXmlText(file));
1875      appendDebugText("Execute public action on controller drop for:"
1876          + filePath + " and:" + controllerName);
1877      actionLoadDatabaseList(controllerName);
1878    }
1879    catch (Exception JavaDoc e)
1880    {
1881      appendDebugText("Failed to load configuration file :" + file.getName(), e);
1882    }
1883  }
1884
1885  /**
1886   * actionDatabaseDisableAll definition. Call the proper MBean to disable all
1887   * backends
1888   *
1889   * @param databaseName virtual database name
1890   */

1891  public void publicActionDatabaseDisableAll(String JavaDoc databaseName)
1892  {
1893    try
1894    {
1895      actionGetDatabaseBean(databaseName).disableAllBackends();
1896      publicActionLoadBackendsList(databaseName);
1897      centerPane.setSelectedComponent(backendPanel);
1898      appendDebugText("Disable All backends for :" + databaseName
1899          + " was a success");
1900    }
1901    catch (Exception JavaDoc e)
1902    {
1903      appendDebugText("Disable All backends for :" + databaseName + " failed.",
1904          e);
1905    }
1906  }
1907
1908  /**
1909   * GetInfo for the given controller
1910   *
1911   * @param controllerName the controllerName
1912   */

1913  public void publicActionGetControllerInfo(String JavaDoc controllerName)
1914  {
1915    try
1916    {
1917      ControllerMBean controllerMBean = actionGetControllerBean(controllerName);
1918      infoTextPane.setText(controllerMBean.getXml());
1919      centerPane.setSelectedComponent(infoScroll);
1920    }
1921    catch (Exception JavaDoc e)
1922    {
1923      appendDebugText("Failed to get info for controller:" + controllerName, e);
1924    }
1925  }
1926
1927  /**
1928   * Shutdown the given controller
1929   *
1930   * @param controllerName name of the controller to shutdown
1931   */

1932  public void publicActionShutdownController(String JavaDoc controllerName)
1933  {
1934    ControllerMBean controllerMBean = null;
1935    int shutdownLevel = 2;
1936    try
1937    {
1938      controllerMBean = actionGetControllerBean(controllerName);
1939    }
1940    catch (Exception JavaDoc e)
1941    {
1942      appendDebugText("Failed to get a proxy to shutdown the controller:"
1943          + controllerName, e);
1944    }
1945    try
1946    {
1947      if (controllerMBean != null)
1948      {
1949        ArrayList JavaDoc databases = controllerMBean.getVirtualDatabaseNames();
1950        for (int i = 0; i < databases.size(); i++)
1951        {
1952          DatabaseObject dob = (DatabaseObject) databaseList.get(databases
1953              .get(i));
1954          appendDebugText("Shutting down database:" + dob.getName()
1955              + " with level:" + shutdownLevel);
1956          publicActionShutdownDatabase(dob, shutdownLevel);
1957        }
1958        controllerMBean.shutdown(shutdownLevel);
1959      }
1960      else
1961        appendDebugText("Failed to get a proxy to shutdown the controller:"
1962            + controllerName);
1963    }
1964    catch (Exception JavaDoc e)
1965    {
1966      // lost connection expected
1967
}
1968    publicActionLoadControllerList();
1969
1970  }
1971
1972  /**
1973   * Get a report for the given controller
1974   *
1975   * @param controllerName the controller to get the report from
1976   */

1977  public void publicActionControllerReport(String JavaDoc controllerName)
1978  {
1979    try
1980    {
1981      ControllerMBean controllerMBean = actionGetControllerBean(controllerName);
1982      infoTextPane.setText(controllerMBean.generateReport());
1983      centerPane.setSelectedComponent(infoScroll);
1984    }
1985    catch (Exception JavaDoc e)
1986    {
1987      appendDebugText("Failed to get info for controller:" + controllerName, e);
1988    }
1989  }
1990
1991  /**
1992   * Delete a dump of a database from the virtual database
1993   *
1994   * @param databaseName the url of the controller
1995   * @param dump the dump object
1996   */

1997  public void publicActionDeleteDump(String JavaDoc databaseName, DumpFileObject dump)
1998  {
1999    boolean confirm = actionDisplayConfirmFrame(GuiTranslate
2000        .get("gui.confirm.delete.dump"));
2001    if (!confirm)
2002    {
2003      appendDebugText("Action is not confirmed, cancelling deletion");
2004      return;
2005    }
2006    VirtualDatabaseMBean database = actionGetDatabaseBean(databaseName);
2007    // FIXME Recovery Refactoring: removeDumpFile(File) -> removeDump(String)
2008
/*
2009    try
2010    {
2011      database.removeDumpFile(dump.getDumpFile());
2012      appendDebugText("Removed dump file:" + dump.getDumpFile().getName()
2013          + " from controller:" + databaseName);
2014      publicActionLoadDumpList(databaseName);
2015    }
2016    catch (Exception e)
2017    {
2018      appendDebugText("Failed to removed dump file:"
2019          + dump.getDumpFile().getName() + " from controller:" + databaseName,
2020          e);
2021    }
2022    */

2023  }
2024
2025  /**
2026   * Display frame to confirm action
2027   *
2028   * @param message message to confirm
2029   * @return true if YES is selected, false otherwise
2030   */

2031  private boolean actionDisplayConfirmFrame(String JavaDoc message)
2032  {
2033    int value = JOptionPane.showConfirmDialog(this, message, message,
2034        JOptionPane.YES_NO_OPTION);
2035    if (value == JOptionPane.YES_OPTION)
2036      return true;
2037    else
2038      return false;
2039  }
2040
2041  /**
2042   * Execute the backend drop action with this gui
2043   *
2044   * @param panel the target of the drop
2045   * @param backendName name of the backend that is the target of the drop
2046   */

2047  public void publicActionExecuteBackendDrop(JPanel JavaDoc panel, String JavaDoc backendName)
2048  {
2049    publicActionExecuteBackendDrop(panel.getName(), backendName);
2050  }
2051
2052  /**
2053   * Load the controller log4j configuration file in the info buffer
2054   *
2055   * @param controllerName the controller's url
2056   */

2057  public void publicActionControllerLogConfiguration(String JavaDoc controllerName)
2058  {
2059    try
2060    {
2061      ControllerMBean controllerMBean = actionGetControllerBean(controllerName);
2062      logConfigTextPane.setText(controllerMBean.viewLogConfigurationFile());
2063      centerPane.setSelectedComponent(logConfigScroll);
2064      logConfigTextPane.addMouseListener(new LogEditPopUpMenu(this,
2065          controllerName, logConfigTextPane));
2066    }
2067    catch (Exception JavaDoc e)
2068    {
2069      appendDebugText("Failed to get log4j configuration for controller:"
2070          + controllerName, e);
2071    }
2072  }
2073
2074  /**
2075   * Update the controller log4j configuration file, and restart the logger
2076   * thread
2077   *
2078   * @param controllerName the controller's url
2079   * @param newContent the new log4j configuration
2080   */

2081  public void publicActionUpdateControllerLogConfiguration(
2082      String JavaDoc controllerName, String JavaDoc newContent)
2083  {
2084    try
2085    {
2086      appendDebugText("Updating log4j configuration for controller:"
2087          + controllerName);
2088      ControllerMBean controllerMBean = actionGetControllerBean(controllerName);
2089      controllerMBean.updateLogConfigurationFile(newContent);
2090      actionStartControllerLoggingThread(controllerName);
2091    }
2092    catch (Exception JavaDoc e)
2093    {
2094      appendDebugText("Failed to update log4j configuration for controller:"
2095          + controllerName, e);
2096    }
2097  }
2098
2099  /**
2100   * Change the log4j configuration to Debug mode for all loggers
2101   *
2102   * @param controllerName the name of the controller of this configuration
2103   * @param logConfiguration the content as a <code>String</code> of the log4j
2104   * configuration
2105   */

2106  public void publicActionSetLogConfigurationDebug(String JavaDoc controllerName,
2107      String JavaDoc logConfiguration)
2108  {
2109    try
2110    {
2111      String JavaDoc newContent = actionReplaceInConfiguration(logConfiguration,
2112          "INFO", "DEBUG");
2113      publicActionUpdateControllerLogConfiguration(controllerName, newContent);
2114    }
2115    catch (Exception JavaDoc e)
2116    {
2117      appendDebugText("Setting log configation to debug failed for controller:"
2118          + controllerName, e);
2119    }
2120  }
2121
2122  /**
2123   * Add/remove log4j server output
2124   *
2125   * @param enableServer <tt>true</tt> to enable
2126   * @param controllerName of the controller for this configuration
2127   * @param logConfiguration logFile name
2128   */

2129  public void publicActionSetLogConfigurationServer(boolean enableServer,
2130      String JavaDoc controllerName, String JavaDoc logConfiguration)
2131  {
2132    try
2133    {
2134      String JavaDoc msg = "Setting server configuration to " + enableServer
2135          + " for controller:" + controllerName;
2136      appendDebugText(msg);
2137      String JavaDoc newContent = "";
2138      if (enableServer)
2139      {
2140        // if it was enabled before ?
2141
String JavaDoc tmp = actionReplaceInConfiguration(logConfiguration,
2142            "Console,server", "Console");
2143        newContent = actionReplaceInConfiguration(tmp, "Console,",
2144            "Console,server,");
2145      }
2146      else
2147      {
2148        newContent = actionReplaceInConfiguration(logConfiguration,
2149            "Console,server", "Console");
2150      }
2151      publicActionUpdateControllerLogConfiguration(controllerName, newContent);
2152    }
2153    catch (Exception JavaDoc e)
2154    {
2155      appendDebugText(
2156          "Setting log configation of appender server failed for controller:"
2157              + controllerName, e);
2158    }
2159
2160  }
2161
2162  private String JavaDoc actionReplaceInConfiguration(String JavaDoc logConfiguration,
2163      String JavaDoc oldMode, String JavaDoc newMode) throws IOException JavaDoc
2164  {
2165    BufferedReader JavaDoc reader = new BufferedReader JavaDoc(new StringReader JavaDoc(
2166        logConfiguration));
2167    StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
2168    String JavaDoc line;
2169    int index = 0;
2170    while ((line = reader.readLine()) != null)
2171    {
2172      while ((index = line.indexOf(oldMode, index + 1)) != -1)
2173      {
2174        line = line.substring(0, index) + newMode
2175            + line.substring(index + oldMode.length());
2176      }
2177      buffer.append(line + System.getProperty("line.separator"));
2178    }
2179    logConfigTextPane.setText(buffer.toString());
2180    return buffer.toString();
2181  }
2182
2183  /**
2184   * Change the log4j configuration to Info mode for all loggers
2185   *
2186   * @param controllerName the name of the controller of this configuration
2187   * @param logConfiguration the content as a <code>String</code> of the log4j
2188   * configuration
2189   */

2190  public void publicActionSetLogConfigurationInfo(String JavaDoc controllerName,
2191      String JavaDoc logConfiguration)
2192  {
2193    try
2194    {
2195      String JavaDoc newContent = actionReplaceInConfiguration(logConfiguration,
2196          "DEBUG", "INFO");
2197      publicActionUpdateControllerLogConfiguration(controllerName, newContent);
2198    }
2199    catch (Exception JavaDoc e)
2200    {
2201      appendDebugText("Setting log configation to debug failed for controller:"
2202          + controllerName, e);
2203    }
2204
2205  }
2206
2207  /**
2208   * Returns the backendList value.
2209   *
2210   * @return Returns the backendList.
2211   */

2212  public Hashtable JavaDoc getBackendList()
2213  {
2214    return backendList;
2215  }
2216
2217  /**
2218   * Clean the content of the logging text pane and repaint
2219   */

2220  public void publicActioncleanLoggingPane()
2221  {
2222    loggingTextPane.setText("");
2223    loggingTextPane.validate();
2224    loggingTextPane.repaint();
2225  }
2226
2227  /**
2228   * Remove a configuration file from the list
2229   *
2230   * @param cfo the file object associated
2231   */

2232  public void publicActionRemoveConfigurationFile(ConfigurationFileObject cfo)
2233  {
2234    Container JavaDoc container = cfo.getParent();
2235    container.remove(cfo);
2236    System.out.println(guiSession.getConfigurationFiles().remove(
2237        new File JavaDoc(cfo.getFilePath())));
2238    container.validate();
2239    container.repaint();
2240  }
2241
2242  /**
2243   * Removes a controller from the gui
2244   *
2245   * @param controllerName the name of the controller
2246   */

2247  public void publicActionControllerRemove(String JavaDoc controllerName)
2248  {
2249    ControllerObject co = (ControllerObject) controllerList
2250        .remove(controllerName);
2251    if (co != null)
2252    {
2253      controllerListPanel.remove(co);
2254      controllerListPanel.validate();
2255      controllerListPanel.repaint();
2256    }
2257    guiSession.getControllerItems().remove(controllerName);
2258  }
2259
2260  /**
2261   * Start monitoring console.
2262   *
2263   * @param controllerName the controller to monitor
2264   * @param displayController true if controller pane should be displayed
2265   * @param displayVdb true if virtual database pane should be displayed
2266   * @param displayBackends true if backend pane should be displayed
2267   */

2268  public void publicActionStartMonitor(String JavaDoc controllerName,
2269      boolean displayController, boolean displayVdb, boolean displayBackends)
2270  {
2271    appendDebugText("Creating monitoring console for controller:"
2272        + controllerName);
2273    try
2274    {
2275      new MonitoringConsole(controllerName, displayController
2276          ? actionGetControllerBean(controllerName)
2277          : null, displayVdb ? actionGetDatabaseBean(selectedDatabase) : null,
2278          displayBackends);
2279    }
2280    catch (Exception JavaDoc e)
2281    {
2282      appendDebugText("Loading of monitoring console failed for controller:"
2283          + controllerName, e);
2284    }
2285  }
2286
2287  /**
2288   * Create the new backend by sending the jmx command
2289   */

2290  public void publicActionCreateBackendExecute()
2291  {
2292    newBackendFrame.setVisible(false);
2293    BackendObject bob = newBackendFrame.getBob();
2294    VirtualDatabaseMBean database = actionGetDatabaseBean(bob.getDatabase());
2295    String JavaDoc oldname = bob.getName();
2296    String JavaDoc newname = newBackendFrame.getNewName().getText();
2297    String JavaDoc url = newBackendFrame.getNewUrl().getText();
2298    HashMap JavaDoc map = new HashMap JavaDoc();
2299    map.put("url", url);
2300    try
2301    {
2302      database.replicateBackend(oldname, newname, map);
2303    }
2304    catch (Exception JavaDoc e)
2305    {
2306      appendDebugText("Failed to create new backend:" + newname, e);
2307    }
2308  }
2309
2310  /**
2311   * Display the cache content in a new frame
2312   *
2313   * @param databaseName database name that contains the cache
2314   */

2315  public void publicActionViewCache(String JavaDoc databaseName)
2316  {
2317    try
2318    {
2319      DataCollectorMBean collector = currentJmxClient.getDataCollectorProxy();
2320      CacheViewer viewer = new CacheViewer(collector
2321          .retrieveCacheData(databaseName));
2322      viewer.display();
2323    }
2324    catch (Exception JavaDoc e)
2325    {
2326      appendDebugText("Failed to collect cache data for database:"
2327          + databaseName, e);
2328    }
2329  }
2330
2331  /**
2332   * Display the SQL stats
2333   *
2334   * @param databaseName virtual database name
2335   */

2336  public void publicActionViewSQLStats(String JavaDoc databaseName)
2337  {
2338    try
2339    {
2340      DataCollectorMBean collector = currentJmxClient.getDataCollectorProxy();
2341      SQLStatViewer viewer = new SQLStatViewer(collector
2342          .retrieveSQLStats(databaseName));
2343      viewer.display();
2344    }
2345    catch (Exception JavaDoc e)
2346    {
2347      appendDebugText(
2348          "Failed to collect sql data for database:" + databaseName, e);
2349    }
2350
2351  }
2352
2353  /**
2354   * Display the cache stats
2355   *
2356   * @param databaseName virtual database name
2357   */

2358  public void publicActionViewCacheStats(String JavaDoc databaseName)
2359  {
2360    try
2361    {
2362      DataCollectorMBean collector = currentJmxClient.getDataCollectorProxy();
2363      CacheStatsViewer viewer = new CacheStatsViewer(collector
2364          .retrieveCacheStatsData(databaseName));
2365      viewer.display();
2366    }
2367    catch (Exception JavaDoc e)
2368    {
2369      appendDebugText("Failed to collect cache stats for database:"
2370          + databaseName, e);
2371    }
2372  }
2373
2374  /**
2375   * Get the action listener for the gui
2376   *
2377   * @return the listener of events
2378   */

2379  public CjdbcGuiListener getGuiActionListener()
2380  {
2381    return guiActionListener;
2382  }
2383
2384  /**
2385   * Returns the guiSession value.
2386   *
2387   * @return Returns the guiSession.
2388   */

2389  public GuiSession getGuiSession()
2390  {
2391    return guiSession;
2392  }
2393
2394  /**
2395   * Returns the jmxClients value.
2396   *
2397   * @return Returns the jmxClients.
2398   */

2399  public Hashtable JavaDoc getJmxClients()
2400  {
2401    return jmxClients;
2402  }
2403
2404  /**
2405   * Remove the backend graphic object from the gui
2406   *
2407   * @param backendName the backend to remove
2408   */

2409  public void publicActionRemoveBackendFromGui(String JavaDoc backendName)
2410  {
2411    BackendObject bo = (BackendObject) backendList.remove(backendName);
2412    if (bo != null)
2413    {
2414      backendIcons.remove(bo);
2415      JPanel JavaDoc panel = (JPanel JavaDoc) backendsState.get(bo.getState());
2416      panel.remove(bo);
2417      paintBackendPane();
2418    }
2419  }
2420
2421  /**
2422   * Remove a backend from the backend list, and from the controller
2423   *
2424   * @param bo the <code>BackendObject</code> that originated the action
2425   */

2426  public void publicActionRemoveBackend(BackendObject bo)
2427  {
2428    boolean confirm = actionDisplayConfirmFrame(GuiTranslate.get(
2429        "gui.confirm.remove.backend", bo.getName()));
2430    if (!confirm)
2431    {
2432      appendDebugText("Cancelling backend deletion...");
2433      return;
2434    }
2435
2436    String JavaDoc controllerName = bo.getControllerName();
2437    String JavaDoc databaseName = bo.getDatabase();
2438    String JavaDoc backendName = bo.getName();
2439    RmiJmxClient jmxClient = (RmiJmxClient) jmxClients.get(controllerName);
2440    String JavaDoc user = guiSession.getAuthenticatedDatabaseLogin(databaseName);
2441    String JavaDoc password = guiSession.getAuthenticatedDatabasePassword(databaseName);
2442    try
2443    {
2444      VirtualDatabaseMBean mbean = jmxClient.getVirtualDatabaseProxy(
2445          databaseName, user, password);
2446      mbean.removeBackend(backendName);
2447      publicActionRemoveBackendFromGui(backendName);
2448    }
2449    catch (Exception JavaDoc e)
2450    {
2451      appendDebugText("Cannot remove backend:" + backendName, e);
2452    }
2453
2454  }
2455
2456  /**
2457   * Execute a backend transfer from one controller to an other one
2458   *
2459   * @param backendName the name of the backend to transfer
2460   * @param controllerName the target controller to transfer to
2461   */

2462  public void publicActionExecuteTransfer(String JavaDoc backendName,
2463      String JavaDoc controllerName)
2464  {
2465    BackendObject bo = (BackendObject) backendList.get(backendName);
2466    String JavaDoc controllerNameOrigin = bo.getControllerName();
2467    RmiJmxClient jmxClient = (RmiJmxClient) jmxClients
2468        .get(controllerNameOrigin);
2469    String JavaDoc databaseName = bo.getDatabase();
2470    String JavaDoc user = guiSession.getAuthenticatedDatabaseLogin(databaseName);
2471    String JavaDoc password = guiSession.getAuthenticatedDatabasePassword(databaseName);
2472    try
2473    {
2474      VirtualDatabaseMBean mbean = jmxClient.getVirtualDatabaseProxy(
2475          databaseName, user, password);
2476      mbean.transferBackend(backendName, controllerName);
2477      bo.setControllerName(controllerName);
2478      // publicActionRemoveBackendFromGui(backendName);
2479
}
2480    catch (Exception JavaDoc e)
2481    {
2482      appendDebugText("Cannot remove backend:" + backendName, e);
2483    }
2484  }
2485
2486  /**
2487   * Performs checks before calling <method>publicActionRemoveBackendFromGui
2488   * </method>
2489   *
2490   * @param backendName the backend name to remove
2491   * @param controller the controller that it was removed from
2492   */

2493  public void publicActionRemoveBackendFromGui(String JavaDoc backendName,
2494      String JavaDoc controller)
2495  {
2496    BackendObject bo = (BackendObject) backendList.get(backendName);
2497    if (bo != null)
2498    {
2499      String JavaDoc boController = bo.getControllerName();
2500      if (boController.equals(controller))
2501        publicActionRemoveBackendFromGui(backendName);
2502      else
2503      {
2504        appendDebugText("Call for removing backend:" + backendName
2505            + " from controller:" + controller
2506            + " but backend is on controller:" + boController);
2507      }
2508    }
2509
2510  }
2511
2512  /**
2513   * Display the shutdown dialog and then shutdown the database with the
2514   * corresponding level
2515   *
2516   * @param database the database name we want to shutdown.
2517   */

2518  public void publicActionDisplayShutdownFrame(DatabaseObject database)
2519  {
2520    if (selectShutdownFrame == null)
2521    {
2522      selectShutdownFrame = new GuiSelectShutdownFrame(this, guiActionListener);
2523      selectShutdownFrame.setVisible(true);
2524    }
2525    String JavaDoc shutdownLevel = selectShutdownFrame.getValueField().getText();
2526    // Defaults to safe mode
2527
int iLevel = Constants.SHUTDOWN_SAFE;
2528    if (shutdownLevel.equals(GuiCommands.COMMAND_SHUTDOWN_SAFE))
2529      iLevel = Constants.SHUTDOWN_SAFE;
2530    else if (shutdownLevel.equals(GuiCommands.COMMAND_SHUTDOWN_FORCE))
2531      iLevel = Constants.SHUTDOWN_FORCE;
2532    else if (shutdownLevel.equals(GuiCommands.COMMAND_SHUTDOWN_WAIT))
2533      iLevel = Constants.SHUTDOWN_WAIT;
2534    appendDebugText("shudown level of database:" + database.getName() + " is:"
2535        + shutdownLevel);
2536    selectShutdownFrame = null;
2537    publicActionShutdownDatabase(database, iLevel);
2538  }
2539
2540  /**
2541   * Display the content of the recovery log in a frame
2542   *
2543   * @param databaseName the database that containts the recovery log we want
2544   */

2545  public void publicActionViewRecoveryLog(String JavaDoc databaseName)
2546  {
2547    try
2548    {
2549      DataCollectorMBean collector = currentJmxClient.getDataCollectorProxy();
2550      RecoveryLogViewer viewer = new RecoveryLogViewer(collector
2551          .retrieveRecoveryLogData(databaseName));
2552      viewer.display();
2553    }
2554    catch (Exception JavaDoc e)
2555    {
2556      appendDebugText("Failed to collect cache stats for database:"
2557          + databaseName, e);
2558    }
2559  }
2560
2561  /**
2562   * Set the checkpoint of a backend
2563   *
2564   * @param bo the backend to change the checkpoint
2565   */

2566  public void publicActionSetCheckpoint(BackendObject bo)
2567  {
2568    String JavaDoc backendName = bo.getName();
2569    String JavaDoc database = bo.getDatabase();
2570    String JavaDoc checkpoint = actionDisplaySelectCheckpointFrame(database);
2571    try
2572    {
2573      appendDebugText("Setting checkpoint for backend:" + backendName + ":"
2574          + checkpoint);
2575      bo.getMbean().setLastKnownCheckpoint(checkpoint);
2576    }
2577    catch (Exception JavaDoc e)
2578    {
2579      appendDebugText("Failed to set checkpoint for backend:" + backendName, e);
2580    }
2581  }
2582
2583  /**
2584   * Unset checkpoint of a backend (set it to null)
2585   *
2586   * @param bo backend object
2587   */

2588  public void publicActionUnSetCheckpoint(BackendObject bo)
2589  {
2590    String JavaDoc backendName = bo.getName();
2591    boolean confirm = actionDisplayConfirmFrame(GuiTranslate.get(
2592        "gui.confirm.unset.backend.checkpoint", backendName));
2593    if (!confirm)
2594    {
2595      appendDebugText("Cancelling backend null checkpoint...");
2596      return;
2597    }
2598    try
2599    {
2600      appendDebugText("UnSetting checkpoint for backend:" + backendName);
2601      bo.getMbean().setLastKnownCheckpoint(null);
2602    }
2603    catch (Exception JavaDoc e)
2604    {
2605      appendDebugText("Failed to unset checkpoint for backend:" + backendName,
2606          e);
2607    }
2608    finally
2609    {
2610      actionRefreshBackendState(bo);
2611    }
2612
2613  }
2614
2615  /**
2616   * Test jdbc connection on this backend
2617   *
2618   * @param bo the backend object to test the connection on
2619   */

2620  public void publicActionTestBackendConnection(BackendObject bo)
2621  {
2622    try
2623    {
2624      DatabaseBackendMBean bean = bo.getMbean();
2625      boolean ok = bean.isJDBCConnected();
2626      String JavaDoc message = "Backend " + bo.getName();
2627      if (ok)
2628        message += " has ";
2629      else
2630        message += " does not have ";
2631      message += "JDBC Connectivity.";
2632
2633      appendDebugText("Result of JDBC Connect[" + bo.getName() + "]:" + ok);
2634
2635      Icon JavaDoc icon = (ok)
2636          ? GuiIcons.BACKEND_ENABLED_ICON
2637          : GuiIcons.BACKEND_DISABLED_ICON;
2638      JOptionPane.showMessageDialog(this, message, bo.getName(),
2639          JOptionPane.INFORMATION_MESSAGE, icon);
2640    }
2641    catch (Exception JavaDoc e)
2642    {
2643      appendDebugText(
2644          "Cannot determine if backend has still JDBC connectivity", e);
2645    }
2646  }
2647
2648  /**
2649   * Refresh the list of mbeans
2650   */

2651  public void publicActionRefreshMBeans()
2652  {
2653    Set JavaDoc set;
2654    if (currentJmxClient == null)
2655    {
2656      appendDebugText("Jmx Client has not been set yet");
2657      return;
2658    }
2659    try
2660    {
2661      appendDebugText("Refreshing mbeans for jmx server:"
2662          + currentJmxClient.getRemoteName());
2663      set = currentJmxClient.listCJDBCMBeans();
2664      int size = set.size();
2665      Iterator JavaDoc iter = set.iterator();
2666      Object JavaDoc[] data = new Object JavaDoc[size];
2667      for (int i = 0; i < size; i++)
2668        data[i] = ((ObjectInstance JavaDoc) iter.next()).getObjectName();
2669      mbeanList.setListData(data);
2670      mbeanList.validate();
2671      appendDebugText("Finished Refreshing mbeans for jmx server:"
2672          + currentJmxClient.getRemoteName());
2673    }
2674    catch (Exception JavaDoc e)
2675    {
2676      appendDebugText("Failed Refreshing mbeans for jmx server:"
2677          + currentJmxClient.getRemoteName());
2678    }
2679  }
2680
2681  /**
2682   * Position the jmx frames on the desktop
2683   *
2684   * @param vertical tile the frames vertically if true, horizontally if false
2685   */

2686  public void publicActionTileJmxFrames(boolean vertical)
2687  {
2688    Dimension JavaDoc dim = jmxPanel.getSize();
2689    double height = dim.getHeight();
2690    double width = dim.getWidth();
2691    if (vertical)
2692      width = width / 3;
2693    else
2694      height = height / 3;
2695
2696    Dimension JavaDoc newDim = new Dimension JavaDoc((int) width, (int) height);
2697    attributeFrame.setSize(newDim);
2698    operationFrame.setSize(newDim);
2699    mbeanFrame.setSize(newDim);
2700
2701    int x = (int) jmxPanel.getLocation().getX();
2702    int y = 0; // problem with y value
2703

2704    mbeanFrame.setLocation(x, y);
2705    if (vertical)
2706    {
2707      mbeanFrame.setLocation(x, y);
2708      attributeFrame.setLocation((int) (x + width), y);
2709      operationFrame.setLocation((int) (x + 2 * width), y);
2710    }
2711    else
2712    {
2713      mbeanFrame.setLocation(x, y);
2714      attributeFrame.setLocation(x, (int) (y + height));
2715      operationFrame.setLocation(x, (int) (y + 2 * height));
2716    }
2717
2718    jmxPanel.validate();
2719
2720  }
2721
2722  /**
2723   * Refresh MBean attributes.
2724   *
2725   * @param mbean the MBean to refresh
2726   */

2727  public void publicActionRefreshMBeanAttributes(ObjectName JavaDoc mbean)
2728  {
2729    try
2730    {
2731      appendDebugText("Fetching attributes for mbean:" + mbean);
2732      MBeanInfo JavaDoc info = currentJmxClient.getMBeanInfo(mbean);
2733      MBeanAttributeInfo JavaDoc[] attrInfo = info.getAttributes();
2734
2735      AttributeModel dataModel = new AttributeModel(attrInfo, currentJmxClient,
2736          mbean);
2737      attributeTable.setModel(dataModel);
2738    }
2739    catch (Exception JavaDoc e)
2740    {
2741      appendDebugText("Could not fetch attributes for mbean:" + mbean);
2742    }
2743  }
2744
2745  /**
2746   * Refresh MBean methods.
2747   *
2748   * @param mbean the MBean to refresh
2749   */

2750  public void publicActionRefreshMBeanMethods(ObjectName JavaDoc mbean)
2751  {
2752    try
2753    {
2754      appendDebugText("Fetching methods for mbean:" + mbean);
2755      MBeanInfo JavaDoc info = currentJmxClient.getMBeanInfo(mbean);
2756      MBeanOperationInfo JavaDoc[] operInfo = info.getOperations();
2757
2758      OperationModel dataModel = new OperationModel(operInfo);
2759      operationTable.setModel(dataModel);
2760    }
2761    catch (Exception JavaDoc e)
2762    {
2763      appendDebugText("Could not fetch methods for mbean:" + mbean);
2764    }
2765  }
2766
2767  /**
2768   * Returns the currentJmxClient value.
2769   *
2770   * @return Returns the currentJmxClient.
2771   */

2772  public RmiJmxClient getCurrentJmxClient()
2773  {
2774    return currentJmxClient;
2775  }
2776
2777  /**
2778   * Sets the currentJmxClient value.
2779   *
2780   * @param currentJmxClient The currentJmxClient to set.
2781   */

2782  public void setCurrentJmxClient(RmiJmxClient currentJmxClient)
2783  {
2784    this.currentJmxClient = currentJmxClient;
2785  }
2786
2787  /**
2788   * Opens a window to perform a jmx operation
2789   *
2790   * @param info an <code>MBeanOperationInfo</code> object
2791   * @param name name of the JMX object
2792   */

2793  public void getOperationCallDialog(ObjectName JavaDoc name, MBeanOperationInfo JavaDoc info)
2794  {
2795    new OperationCallDialog(this, name, info).setVisible(true);
2796  }
2797
2798  /**
2799   * Opens a window t ochange an attribute
2800   *
2801   * @param info an <code>MBeanOperationInfo</code> object
2802   * @param name name of the JMX object
2803   */

2804  public void getAttributeChangeDialog(ObjectName JavaDoc name, MBeanAttributeInfo JavaDoc info)
2805  {
2806    new AttributeChangeDialog(this, name, info).setVisible(true);
2807  }
2808
2809}
Popular Tags