Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

BackendPopUpMenu.java

00001 /**
00002  * C-JDBC: Clustered JDBC.
00003  * Copyright (C) 2002-2004 French National Institute For Research In Computer
00004  * Science And Control (INRIA).
00005  * Contact: c-jdbc@objectweb.org
00006  * 
00007  * This library is free software; you can redistribute it and/or modify it
00008  * under the terms of the GNU Lesser General Public License as published by the
00009  * Free Software Foundation; either version 2.1 of the License, or any later
00010  * version.
00011  * 
00012  * This library is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
00015  * for more details.
00016  * 
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with this library; if not, write to the Free Software Foundation,
00019  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00020  *
00021  * Initial developer(s): Nicolas Modrzyk.
00022  * Contributor(s): ______________________.
00023  */
00024 
00025 package org.objectweb.cjdbc.console.gui.popups;
00026 
00027 import java.awt.event.ActionEvent;
00028 import java.awt.event.MouseListener;
00029 
00030 import javax.swing.JMenu;
00031 import javax.swing.JMenuItem;
00032 import javax.swing.JSeparator;
00033 
00034 import org.objectweb.cjdbc.common.jmx.mbeans.DataCollectorMBean;
00035 import org.objectweb.cjdbc.common.monitor.DataCollectionNames;
00036 import org.objectweb.cjdbc.console.gui.CjdbcGui;
00037 import org.objectweb.cjdbc.console.gui.constants.GuiCommands;
00038 import org.objectweb.cjdbc.console.gui.constants.GuiConstants;
00039 import org.objectweb.cjdbc.console.gui.objects.BackendObject;
00040 import org.objectweb.cjdbc.console.jmx.RmiJmxClient;
00041 import org.objectweb.cjdbc.console.monitoring.MonitoringConsole;
00042 
00043 /**
00044  * This class defines a BackendPopUpMenu
00045  * 
00046  * @author <a href="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
00047  * @version 1.0
00048  */
00049 public class BackendPopUpMenu extends AbstractPopUpMenu
00050     implements
00051       MouseListener
00052 {
00053 
00054   private BackendObject bo;
00055   JMenuItem             backendRemove;
00056   JMenuItem             backendCreate;
00057   JMenuItem             backendCheckpoint;
00058   JMenuItem             backendUnsetCheckpoint;
00059   JMenuItem             backendEnable;
00060   JMenuItem             backendDisable;
00061   JMenuItem             backendRestore;
00062   JMenuItem             backendBackup;
00063   JMenuItem             backendTestConnection;
00064   JMenu                 monitor;
00065 
00066   /**
00067    * Creates a new <code>BackendPopUpMenu</code> object
00068    * 
00069    * @param gui the referenced gui
00070    * @param bo the backend object
00071    */
00072   public BackendPopUpMenu(CjdbcGui gui, BackendObject bo)
00073   {
00074     super(gui);
00075     this.bo = bo;
00076 
00077     JSeparator separator = new JSeparator();
00078 
00079     backendRemove = new JMenuItem(GuiCommands.COMMAND_BACKEND_REMOVE);
00080     backendCreate = new JMenuItem(GuiCommands.COMMAND_BACKEND_CREATE_NEW);
00081     backendCheckpoint = new JMenuItem(
00082         GuiCommands.COMMAND_BACKEND_SET_CHECKPOINT);
00083     backendEnable = new JMenuItem(GuiConstants.BACKEND_STATE_ENABLED);
00084     backendDisable = new JMenuItem(GuiConstants.BACKEND_STATE_DISABLED);
00085     backendRestore = new JMenuItem(GuiConstants.BACKEND_STATE_RESTORE);
00086     backendBackup = new JMenuItem(GuiConstants.BACKEND_STATE_BACKUP);
00087     backendTestConnection = new JMenuItem(
00088         GuiCommands.COMMAND_BACKEND_TEST_CONNECTION);
00089     backendUnsetCheckpoint = new JMenuItem(
00090         GuiCommands.COMMAND_BACKEND_UNSET_CHECKPOINT);
00091 
00092     this.add(backendRemove).addActionListener(this);
00093     this.add(backendCreate).addActionListener(this);
00094     this.add(backendCheckpoint).addActionListener(this);
00095     this.add(backendUnsetCheckpoint).addActionListener(this);
00096     this.add(backendTestConnection).addActionListener(this);
00097     this.add(separator);
00098     this.add(backendEnable).addActionListener(this);
00099     this.add(backendDisable).addActionListener(this);
00100     this.add(backendRestore).addActionListener(this);
00101     this.add(backendBackup).addActionListener(this);
00102     this.add(separator);
00103 
00104     buildMonitorMenu();
00105   }
00106 
00107   private void buildMonitorMenu()
00108   {
00109     monitor = new JMenu("Monitor");
00110     addToMonitorMenu(DataCollectionNames.BACKEND_ACTIVE_TRANSACTION);
00111     addToMonitorMenu(DataCollectionNames.BACKEND_PENDING_REQUESTS);
00112     addToMonitorMenu(DataCollectionNames.BACKEND_TOTAL_ACTIVE_CONNECTIONS);
00113     addToMonitorMenu(DataCollectionNames.BACKEND_TOTAL_READ_REQUEST);
00114     addToMonitorMenu(DataCollectionNames.BACKEND_TOTAL_REQUEST);
00115     addToMonitorMenu(DataCollectionNames.BACKEND_TOTAL_TRANSACTIONS);
00116     addToMonitorMenu(DataCollectionNames.BACKEND_TOTAL_WRITE_REQUEST);
00117     this.add(monitor);
00118   }
00119 
00120   private void addToMonitorMenu(int type)
00121   {
00122     String typeName = DataCollectionNames.get(type);
00123     JMenuItem item = new JMenuItem(typeName);
00124     String action = MonitoringConsole.getBackendActionCommand(typeName, bo
00125         .getDatabase(), bo.getName());
00126     item.setActionCommand(action);
00127     monitor.add(item).addActionListener(this);
00128   }
00129 
00130   /**
00131    * Returns the backendCheckpoint value.
00132    * 
00133    * @return Returns the backendCheckpoint.
00134    */
00135   public final JMenuItem getBackendCheckpoint()
00136   {
00137     return backendCheckpoint;
00138   }
00139 
00140   /**
00141    * Returns the backendCreate value.
00142    * 
00143    * @return Returns the backendCreate.
00144    */
00145   public final JMenuItem getBackendCreate()
00146   {
00147     return backendCreate;
00148   }
00149 
00150   /**
00151    * Returns the backendRemove value.
00152    * 
00153    * @return Returns the backendRemove.
00154    */
00155   public final JMenuItem getBackendRemove()
00156   {
00157     return backendRemove;
00158   }
00159 
00160   /**
00161    * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
00162    */
00163   public void actionPerformed(ActionEvent e)
00164   {
00165     String action = e.getActionCommand();
00166     if (action.startsWith("graph"))
00167     {
00168       RmiJmxClient controllerMBean = bo.getJmxClient();
00169       DataCollectorMBean dataCollectorMBean;
00170       try
00171       {
00172         dataCollectorMBean = controllerMBean.getDataCollectorProxy();
00173         MonitoringConsole.graph(action, dataCollectorMBean, -1, 3600, 1000, 1,
00174             null);
00175         return;
00176       }
00177       catch (Exception e1)
00178       {
00179         e1.printStackTrace();
00180         return;
00181       }
00182     }
00183 
00184     if (action.equals(GuiCommands.COMMAND_BACKEND_REMOVE))
00185     {
00186       gui.publicActionRemoveBackend(bo);
00187     }
00188     else if (action.equals(GuiCommands.COMMAND_BACKEND_CREATE_NEW))
00189     {
00190       gui.publicActionNewBackendPrompt(bo);
00191     }
00192     else if (action.equals(GuiCommands.COMMAND_BACKEND_SET_CHECKPOINT))
00193     {
00194       gui.publicActionSetCheckpoint(bo);
00195     }
00196     else if (action.equals(GuiCommands.COMMAND_BACKEND_TEST_CONNECTION))
00197     {
00198       gui.publicActionTestBackendConnection(bo);
00199     }
00200     else if (action.equals(GuiCommands.COMMAND_BACKEND_UNSET_CHECKPOINT))
00201     {
00202       gui.publicActionUnSetCheckpoint(bo);
00203     }
00204     else
00205     {
00206       gui.publicActionExecuteBackendDrop(action, bo.getName());
00207     }
00208 
00209   }
00210 
00211   /**
00212    * Returns the backendBackup value.
00213    * 
00214    * @return Returns the backendBackup.
00215    */
00216   public final JMenuItem getBackendBackup()
00217   {
00218     return backendBackup;
00219   }
00220 
00221   /**
00222    * Returns the backendDisable value.
00223    * 
00224    * @return Returns the backendDisable.
00225    */
00226   public final JMenuItem getBackendDisable()
00227   {
00228     return backendDisable;
00229   }
00230 
00231   /**
00232    * Returns the backendEnable value.
00233    * 
00234    * @return Returns the backendEnable.
00235    */
00236   public final JMenuItem getBackendEnable()
00237   {
00238     return backendEnable;
00239   }
00240 
00241   /**
00242    * Returns the backendRestore value.
00243    * 
00244    * @return Returns the backendRestore.
00245    */
00246   public final JMenuItem getBackendRestore()
00247   {
00248     return backendRestore;
00249   }
00250 }

Generated on Mon Apr 11 22:01:29 2005 for C-JDBC by  doxygen 1.3.9.1