proyal 2002/07/26 13:16:37 Added: phyre .cvsignore build.xml default.properties readme.txt phyre/lib LICENSE.mx4j.txt avalon-framework-20020725.jar mx4j-jmx.jar mx4j-tools.jar xalan-2.3.1.jar xerces-2.0.1.jar xml-apis.jar phyre/src/java/org/apache/avalon/phyre Main.java MenuBar.java PhyreFrame.java phyre/src/java/org/apache/avalon/phyre/actions MBeanInvokeAction.java MBeanSwitchContentPanelAction.java SwitchContentPanelAction.java phyre/src/java/org/apache/avalon/phyre/dialogs AbstractOptionDialog.java AbstractTabularOptionDialog.java ConnectDialog.java phyre/src/java/org/apache/avalon/phyre/mbean MBeanAccessor.java MBeanManager.java phyre/src/java/org/apache/avalon/phyre/panels AbstractContentPanel.java AbstractMBeanPanel.java ApplicationPanel.java HomePanel.java ModifyConfigurationPanel.java phyre/src/java/org/apache/avalon/phyre/panels/applist ApplicationListPanel.java ApplicationTableModel.java ApplicationTableMouseListener.java phyre/src/java/org/apache/avalon/phyre/panels/blocklist BlockListPanel.java BlockTableModel.java BlockTableMouseListener.java phyre/src/java/org/apache/avalon/phyre/panels/navigation AbstractNavigationPanel.java ApplicationNavigationPanel.java PrimaryNavigationPanel.java Log: First cut at phoenix mgmt console THIS IS VERY RAW AND WILL BE CHANGING THIS IS A PROOF OF CONCEPT FIRST CHECKIN *phew* there will be a more detailed followup msg on avalon-phoenix-dev Revision Changes Path 1.1 jakarta-avalon-apps/phyre/.cvsignore Index: .cvsignore =================================================================== build dist local.properties pss ins.ior .cvsignore 1.1 jakarta-avalon-apps/phyre/build.xml Index: build.xml =================================================================== <?xml version="1.0"?> <!-- ============================================================================== Avalon Applications Phyre build file Type 'ant' to build. The flag '-projecthelp' will list normal targets. If combined with '-verbose', all targets are printed. This buildfile delegates all of the actual functionality to the main avalon-apps buildfile using the <ant/> task, calling targets that are named module:{xxx}. Authors: Peter Royal <[EMAIL PROTECTED]> Legal: Copyright (c) 2002 The Apache Software Foundation. All Rights Reserved. ============================================================================== --> <project name="Phyre" default="main" basedir="."> <!-- ========================================================================================== DEFAULT TARGETS ========================================================================================== --> <target name="main" depends="jar" description="Default target to generate build products minus docs"/> <target name="all" depends="main,docs" description="Generate build products including docs"/> <target name="docs" depends="html-docs,javadocs" description="generates all the Avalon documentation"/> <!-- ========================================================================================== COMPILE TARGETS ========================================================================================== --> <target name="compile"> <ant antfile="${basedir}/../build.xml" target="module:compiler"/> </target> <target name="test" description="Run unit tests to verify the application works corretly."> <ant antfile="${basedir}/../build.xml" target="module:test"/> </target> <!-- ========================================================================================== DISTRIBUTION TARGETS ========================================================================================== --> <target name="jar"> <ant antfile="${basedir}/../build.xml" target="module:jar"/> </target> <target name="dist"> <ant antfile="${basedir}/../build.xml" target="module:dist"/> </target> <target name="bin-dist"> <ant antfile="${basedir}/../build.xml" target="module:bin-dist"/> </target> <target name="src-dist"> <ant antfile="${basedir}/../build.xml" target="module:src-dist"/> </target> <target name="install" description="Installs into Phoenix"> <ant antfile="${basedir}/../build.xml" target="module:install"/> </target> <target name="uninstall" description="Uninstalls from Phoenix"> <ant antfile="${basedir}/../build.xml" target="module:uninstall"/> </target> <target name="clean" description="Cleans up artifacts from build process"> <ant antfile="${basedir}/../build.xml" target="module:clean"/> </target> <target name="distclean"> <echo message="-------------------------------------------------------------" /> <echo message="WARNING: Deprecated. Use the real-clean target instead" /> <echo message="-------------------------------------------------------------" /> <ant antfile="${basedir}/../build.xml" target="module:real-clean"/> </target> <target name="real-clean" description="Cleans up all generated files and directories"> <ant antfile="${basedir}/../build.xml" target="module:real-clean"/> </target> <!-- ========================================================================================== DOCUMENTATION GENERATION ========================================================================================== --> <!-- copy docs to site dir --> <target name="site" depends="docs" description=" Places Docs ready for hosting on website"> <ant antfile="${basedir}/../build.xml" target="module:site"/> </target> <!-- Creates javadocs --> <target name="javadocs" depends="compile" description="Generates the javadocs" unless="skip.javadocs"> <ant antfile="${basedir}/../build.xml" target="module:javadocs"/> </target> <target name="html-docs" description="generates the xdocs-based documentation"> <ant antfile="${basedir}/../build.xml" target="module:html-docs"/> </target> </project> 1.1 jakarta-avalon-apps/phyre/default.properties Index: default.properties =================================================================== # ============================================================================ # Standard Build Properties for XCommander # ============================================================================ # Overrides the incorrect values in ../default.properties. # ---------------------------------------------------------------------------- # DOC GENERATION CONFIGURATION # ---------------------------------------------------------------------------- name = phyre Name = Avalon Apps Phyre dir-name = phyre version = 0.1 package-version = 1.0 year = 2002 1.1 jakarta-avalon-apps/phyre/readme.txt Index: readme.txt =================================================================== Avalons Applications Phyre -------------------------- What is Phyre? ------------------- Extensible swing GUI for controlling phoenix How do I use it? ---------------- <fill in here...> What are the plans for Phyre? ---------------------------------- <fill in here...> Who wrote it? ------------- That'd be me, Peter Royal <[EMAIL PROTECTED]>. primarily on time paid for by the pace systems group, inc. <http://pace2020.com> Can I get support? ------------------ If you have trouble getting it running, try the avalon-user list and we'll try and help you out. Isn't there any more documentation? ----------------------------------- Not yet. Feel free to help! 1.1 jakarta-avalon-apps/phyre/lib/LICENSE.mx4j.txt Index: LICENSE.mx4j.txt =================================================================== /* ==================================================================== * The MX4J License, Version 1.0 * * Copyright (c) 2001 MX4J. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * MX4J project (http://mx4j.sourceforge.net)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "MX4J" and "mx4j" must not be used to endorse or promote * products derived from this software without prior written * permission. For written permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "MX4J", * nor may "MX4J" appear in their name, without prior written * permission of Simone Bordet. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL CARLOS QUIROZ OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of MX4J. For more information on * MX4J, please see * <http://mx4j.sourceforge.net>. */ 1.1 jakarta-avalon-apps/phyre/lib/avalon-framework-20020725.jar <<Binary file>> 1.1 jakarta-avalon-apps/phyre/lib/mx4j-jmx.jar <<Binary file>> 1.1 jakarta-avalon-apps/phyre/lib/mx4j-tools.jar <<Binary file>> 1.1 jakarta-avalon-apps/phyre/lib/xalan-2.3.1.jar <<Binary file>> 1.1 jakarta-avalon-apps/phyre/lib/xerces-2.0.1.jar <<Binary file>> 1.1 jakarta-avalon-apps/phyre/lib/xml-apis.jar <<Binary file>> 1.1 jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/Main.java Index: Main.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.avalon.phyre; /** * @author <a href="mailto:[EMAIL PROTECTED]">Peter Royal</a> */ public class Main { public static void main( String args[] ) { final PhyreFrame frame = new PhyreFrame( "phyre" ); frame.show(); } } 1.1 jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/MenuBar.java Index: MenuBar.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.avalon.phyre; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import java.awt.Event; import javax.swing.AbstractAction; import javax.swing.Action; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.KeyStroke; /** * * @author <a href="mailto:[EMAIL PROTECTED]">Peter Royal</a> */ public class MenuBar extends JMenuBar { private PhyreFrame m_frame; private JMenu m_menuFile; private JMenu m_menuOptions; private JMenu m_menuWindow; /*--------------------------------------------------------------- * Constructors *-------------------------------------------------------------*/ MenuBar( PhyreFrame frame/*, ProfilerManager profilerManager*/ ) { m_frame = frame; add( buildFileMenu() ); } /*--------------------------------------------------------------- * Methods *-------------------------------------------------------------*/ private JMenu buildFileMenu() { m_menuFile = new JMenu( "File" ); m_menuFile.setMnemonic( KeyEvent.VK_F ); // Clear Action connectAction = new AbstractAction( "Connect" ) { public void actionPerformed( ActionEvent event ) { m_frame.connect(); } }; JMenuItem connectItem = new JMenuItem( connectAction ); connectItem.setMnemonic( 'C' ); m_menuFile.add( connectItem ); // Seperator m_menuFile.addSeparator(); // Exit Action exitAction = new AbstractAction( "Exit" ) { public void actionPerformed( ActionEvent event ) { m_frame.fileExit(); } }; JMenuItem exit = new JMenuItem( exitAction ); exit.setMnemonic( 'X' ); exit.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_Q, Event.CTRL_MASK) ); m_menuFile.add( exit ); return m_menuFile; } } 1.1 jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/PhyreFrame.java Index: PhyreFrame.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.avalon.phyre; import java.awt.BorderLayout; import java.awt.Component; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.SwingUtilities; import org.apache.avalon.phyre.actions.SwitchContentPanelAction; import org.apache.avalon.phyre.dialogs.ConnectDialog; import org.apache.avalon.phyre.mbean.MBeanManager; import org.apache.avalon.phyre.panels.HomePanel; import org.apache.avalon.phyre.panels.navigation.PrimaryNavigationPanel; /** * @author <a href="mailto:[EMAIL PROTECTED]">Peter Royal</a> */ public class PhyreFrame extends JFrame { private final String m_title; private MenuBar m_menuBar; private JPanel m_lhsPanel; private Component m_content; private Component m_nav; private MBeanManager m_beanManager; public PhyreFrame( String title ) { super(); m_title = title; init(); } private void init() { setTitle( m_title ); getContentPane().setLayout( new BorderLayout() ); this.m_lhsPanel = new JPanel( new BorderLayout() ); getContentPane().add( m_lhsPanel, BorderLayout.WEST ); final JButton button = new JButton( new SwitchContentPanelAction( "Phoenix Management Console", HomePanel.class, this ) ); button.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent e ) { if( e.getID() == ActionEvent.ACTION_PERFORMED ) { setNavigationPanel( new PrimaryNavigationPanel( PhyreFrame.this ) ); } } } ); m_lhsPanel.add( button, BorderLayout.NORTH ); setNavigationPanel( new PrimaryNavigationPanel( this ) ); setContentPanel( new JLabel( "not connected" ) ); // Create a Menu Bar m_menuBar = new MenuBar( this ); setJMenuBar( m_menuBar ); setLocation( 50, 50 ); setSize( 800, 600 ); addWindowListener( new WindowAdapter() { public void windowClosing( WindowEvent e ) { shutdown(); } } ); //just for testing, immediately connect try { this.m_beanManager = new MBeanManager( "localhost", 1099 ); setContentPanel( new HomePanel( this ) ); } catch( Exception e ) { e.printStackTrace(); } } public void setContentPanel( JComponent component ) { if( null != this.m_content ) { getContentPane().remove( this.m_content ); } getContentPane().add( component, BorderLayout.CENTER ); getContentPane().validate(); this.m_content = component; } public void setNavigationPanel( Component component ) { if( null != this.m_nav ) { this.m_lhsPanel.remove( m_nav ); } this.m_lhsPanel.add( component, BorderLayout.CENTER ); this.m_lhsPanel.validate(); this.m_nav = component; } private void shutdown() { // Kill the JVM. System.exit( 1 ); } public MBeanManager getMBeanManager() { return m_beanManager; } void fileExit() { SwingUtilities.invokeLater( new Runnable() { public void run() { shutdown(); } } ); } void connect() { final ConnectDialog dialog = new ConnectDialog( this ); dialog.show(); if( dialog.getAction() == ConnectDialog.BUTTON_OK ) { try { this.m_beanManager = new MBeanManager( dialog.getHost(), dialog.getPort() ); setContentPanel( new HomePanel( this ) ); } catch( Exception e ) { e.printStackTrace(); } } } } 1.1 jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/actions/MBeanInvokeAction.java Index: MBeanInvokeAction.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.avalon.phyre.actions; import java.awt.event.ActionEvent; import javax.swing.AbstractAction; import org.apache.avalon.phyre.mbean.MBeanAccessor; /** * @author <a href="mailto:[EMAIL PROTECTED]">Peter Royal</a> */ public class MBeanInvokeAction extends AbstractAction { private final MBeanAccessor m_mBeanAccessor; private final String m_invokeName; public MBeanInvokeAction( final String caption, final String invokeName, final MBeanAccessor mBeanAccessor ) { super( caption ); m_mBeanAccessor = mBeanAccessor; m_invokeName = invokeName; } public void actionPerformed( ActionEvent event ) { if( event.getID() == ActionEvent.ACTION_PERFORMED ) { try { m_mBeanAccessor.invoke( m_invokeName ); } catch( Exception e ) { e.printStackTrace(); } } } } 1.1 jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/actions/MBeanSwitchContentPanelAction.java Index: MBeanSwitchContentPanelAction.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.avalon.phyre.actions; import org.apache.avalon.phyre.PhyreFrame; import org.apache.avalon.phyre.mbean.MBeanAccessor; /** * @author <a href="mailto:[EMAIL PROTECTED]">Peter Royal</a> */ public class MBeanSwitchContentPanelAction extends SwitchContentPanelAction { private final MBeanAccessor m_mbean; public MBeanSwitchContentPanelAction( final String caption, final MBeanAccessor mbean, final Class panelClass, final PhyreFrame frame ) { super( caption, panelClass, frame ); m_mbean = mbean; } protected Object[] getParameters() { return new Object[]{m_mbean, getFrame()}; } protected Class[] getParameterTypes() { return new Class[]{MBeanAccessor.class, PhyreFrame.class}; } } 1.1 jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/actions/SwitchContentPanelAction.java Index: SwitchContentPanelAction.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.avalon.phyre.actions; import java.awt.event.ActionEvent; import java.lang.reflect.Constructor; import javax.swing.AbstractAction; import javax.swing.JComponent; import org.apache.avalon.phyre.PhyreFrame; /** * @author <a href="mailto:[EMAIL PROTECTED]">Peter Royal</a> */ public class SwitchContentPanelAction extends AbstractAction { private final Constructor m_panelConstructor; private final PhyreFrame m_frame; public SwitchContentPanelAction( final String caption, final Class panelClass, final PhyreFrame frame ) { super( caption ); m_frame = frame; try { m_panelConstructor = panelClass.getConstructor( getParameterTypes() ); } catch( Exception e ) { e.printStackTrace(); throw new RuntimeException( "invalid class: " + e.getMessage() ); } } protected Class[] getParameterTypes() { return new Class[]{PhyreFrame.class}; } public void actionPerformed( ActionEvent e ) { if( ActionEvent.ACTION_PERFORMED == e.getID() ) { try { final JComponent pane = ( JComponent ) m_panelConstructor.newInstance( getParameters() ); getFrame().setContentPanel( pane ); } catch( Exception e1 ) { e1.printStackTrace(); } } } protected Object[] getParameters() { return new Object[]{getFrame()}; } protected PhyreFrame getFrame() { return m_frame; } } 1.1 jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/dialogs/AbstractOptionDialog.java Index: AbstractOptionDialog.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.avalon.phyre.dialogs; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Point; import java.awt.event.ActionEvent; import javax.swing.AbstractAction; import javax.swing.Action; import javax.swing.Box; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.SwingConstants; import javax.swing.border.CompoundBorder; import javax.swing.border.EmptyBorder; import javax.swing.border.EtchedBorder; /** * * @author <a href="mailto:[EMAIL PROTECTED]">Leif Mortenson</a> * @version CVS $Revision: 1.1 $ $Date: 2002/07/26 20:16:36 $ * @since 4.1 */ public abstract class AbstractOptionDialog extends JDialog { public static final int BUTTON_OK = 1; public static final int BUTTON_CANCEL = 2; private int m_action = BUTTON_CANCEL; /*--------------------------------------------------------------- * Constructors *-------------------------------------------------------------*/ /** * Creates a new AbstractOptionDialog. * * @param frame Frame which owns the dialog. * @param title Title for the dialog. * @param buttons List of buttons to display. */ protected AbstractOptionDialog( JFrame frame, String title, int buttons ) { super( frame, title, true ); JPanel contentPane = ( JPanel ) getContentPane(); contentPane.setLayout( new BorderLayout() ); contentPane.setBorder( new EmptyBorder( 5, 5, 5, 5 ) ); JPanel backPane = new JPanel(); backPane.setLayout( new BorderLayout() ); backPane.setBorder( new CompoundBorder( new EmptyBorder( 0, 0, 5, 0 ), new CompoundBorder( new EtchedBorder( EtchedBorder.LOWERED ), new EmptyBorder( 5, 5, 5, 5 ) ) ) ); contentPane.add( backPane, BorderLayout.CENTER ); // Build the message backPane.add( new JLabel( getMessage(), SwingConstants.LEFT ), BorderLayout.NORTH ); // Build the main panel JPanel mainPanel = getMainPanel(); mainPanel.setBorder( new EmptyBorder( 5, 0, 0, 0 ) ); backPane.add( mainPanel, BorderLayout.CENTER ); // Build the button panel JPanel buttonPanel = new JPanel(); buttonPanel.setLayout( new FlowLayout( FlowLayout.CENTER ) ); Box buttonBox = Box.createHorizontalBox(); if( ( buttons & BUTTON_OK ) != 0 ) { Action action = new AbstractAction( "OK" ) { public void actionPerformed( ActionEvent event ) { if( validateFields() ) { m_action = BUTTON_OK; AbstractOptionDialog.this.hide(); } } }; JButton button = new JButton( action ); buttonBox.add( button ); buttonBox.add( Box.createHorizontalStrut( 5 ) ); } if( ( buttons & BUTTON_CANCEL ) != 0 ) { Action action = new AbstractAction( "Cancel" ) { public void actionPerformed( ActionEvent event ) { m_action = BUTTON_CANCEL; AbstractOptionDialog.this.hide(); } }; JButton button = new JButton( action ); buttonBox.add( button ); buttonBox.add( Box.createHorizontalStrut( 5 ) ); } buttonPanel.add( buttonBox ); contentPane.add( buttonPanel, BorderLayout.SOUTH ); pack(); // Position the dialog. Point frameLocation = frame.getLocation(); Dimension frameSize = frame.getSize(); Dimension size = getSize(); setLocation( ( int ) ( frameLocation.getX() + ( frameSize.getWidth() - size.getWidth() ) / 2 ), ( int ) ( frameLocation.getY() + ( frameSize.getHeight() - size.getHeight() ) / 2 ) ); // Make the dialog a fixed size. setResizable( false ); } /*--------------------------------------------------------------- * Methods *-------------------------------------------------------------*/ /** * Returns the message to show at the top of the dialog. * * @return The text of the message. */ protected abstract String getMessage(); /** * Returns the main panel which makes up the guts of the dialog. * * @return The main panel. */ protected abstract JPanel getMainPanel(); /** * Goes through and validates the fields in the dialog. * * @return True if the fields were Ok. */ protected boolean validateFields() { return true; } /** * Returns the button which the user selected. */ public int getAction() { return m_action; } } 1.1 jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/dialogs/AbstractTabularOptionDialog.java Index: AbstractTabularOptionDialog.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.avalon.phyre.dialogs; import java.awt.Component; import java.awt.Dimension; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import javax.swing.Box; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; /** * Creates a dialog which displays a table of labeled components to the user. * * @author <a href="mailto:[EMAIL PROTECTED]">Leif Mortenson</a> * @version CVS $Revision: 1.1 $ $Date: 2002/07/26 20:16:36 $ * @since 4.1 */ public abstract class AbstractTabularOptionDialog extends AbstractOptionDialog { /*--------------------------------------------------------------- * Constructors *-------------------------------------------------------------*/ /** * Creates a new AbstractTabularOptionDialog. * * @param frame Frame which owns the dialog. * @param title Title for the dialog. * @param buttons List of buttons to display. */ protected AbstractTabularOptionDialog( JFrame frame, String title, int buttons ) { super( frame, title, buttons ); } /*--------------------------------------------------------------- * AbstractOptionDialog Methods *-------------------------------------------------------------*/ /** * Returns the main panel which makes up the guts of the dialog. * This implementaton builds a table of labeled components using * arrays returned by getMainPanelLabels() and getMainPanelComponents(); * * @return The main panel. */ protected JPanel getMainPanel() { String[] labels = getMainPanelLabels(); Component[] components = getMainPanelComponents(); JPanel panel = new JPanel(); GridBagLayout gbl = new GridBagLayout(); GridBagConstraints gbc = new GridBagConstraints(); panel.setLayout( gbl ); for( int i = 0; i < labels.length; i++ ) { addRow( panel, labels[i], components[i], gbl, gbc ); } return panel; } /*--------------------------------------------------------------- * Methods *-------------------------------------------------------------*/ /** * Returns an array of labels to use for the components returned from * getMainPanelComponents(). * * @returns An array of labels. */ protected abstract String[] getMainPanelLabels(); /** * Returns an array of components to show in the main panel of the dialog. * * @returns An array of components. */ protected abstract Component[] getMainPanelComponents(); /** * Adds a row to the panel consisting of a label and component, separated by * a 5 pixel spacer and followed by a 5 pixel high row between this and the * next row. * * @param panel Panel to which the row will be added. * @param label Text of the label for the component. * @param component Component which makes up the row. * @param gbl GridBagLayout which must have been set as the layour of the * panel. * @param gbc GridBagConstraints to use when laying out the row. */ private void addRow( JPanel panel, String label, Component component, GridBagLayout gbl, GridBagConstraints gbc ) { JLabel jLabel = new JLabel( label ); gbc.gridwidth = 1; gbc.anchor = GridBagConstraints.EAST; gbl.setConstraints( jLabel, gbc ); panel.add( jLabel ); // Add a 5 pixel high spacer Component spacer = Box.createRigidArea( new Dimension( 5, 5 ) ); gbc.gridwidth = GridBagConstraints.RELATIVE; gbc.anchor = GridBagConstraints.WEST; gbl.setConstraints( spacer, gbc ); panel.add( spacer ); gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.anchor = GridBagConstraints.WEST; gbl.setConstraints( component, gbc ); panel.add( component ); // Add a 5 pixel high spacer spacer = Box.createRigidArea( new Dimension( 5, 5 ) ); gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.anchor = GridBagConstraints.WEST; gbl.setConstraints( spacer, gbc ); panel.add( spacer ); } } 1.1 jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/dialogs/ConnectDialog.java Index: ConnectDialog.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.avalon.phyre.dialogs; import java.awt.Component; import javax.swing.JOptionPane; import javax.swing.JTextField; import org.apache.avalon.phyre.PhyreFrame; /** * * @author <a href="mailto:[EMAIL PROTECTED]">Leif Mortenson</a> * @version CVS $Revision: 1.1 $ $Date: 2002/07/26 20:16:36 $ * @since 4.1 */ public class ConnectDialog extends AbstractTabularOptionDialog { private JTextField m_hostField; private String m_host; private JTextField m_portField; private int m_port; /*--------------------------------------------------------------- * Constructors *-------------------------------------------------------------*/ /** * Creates a new ConnectDialog. * * @param frame Frame which owns the dialog. */ public ConnectDialog( PhyreFrame frame ) { super( frame, "Connect to Remote Instrument Manager", AbstractOptionDialog.BUTTON_OK | AbstractOptionDialog.BUTTON_CANCEL ); } /*--------------------------------------------------------------- * AbstractOptionDialog Methods *-------------------------------------------------------------*/ /** * Returns the message to show at the top of the dialog. * * @return The text of the message. */ protected String getMessage() { return "Please enter the host and port of the InstrumentManager to connect to."; } /** * Goes through and validates the fields in the dialog. * * @return True if the fields were Ok. */ protected boolean validateFields() { // Check the host. String host = m_hostField.getText().trim(); if( host.length() == 0 ) { JOptionPane.showMessageDialog( this, "Please enter a valid host name or IP address.", "Invalid host", JOptionPane.ERROR_MESSAGE ); return false; } m_host = host; // Check the port. boolean portOk = true; int port = 0; try { port = Integer.parseInt( m_portField.getText().trim() ); } catch( NumberFormatException e ) { portOk = false; } if( ( port < 0 ) || ( port > 65535 ) ) { portOk = false; } if( !portOk ) { JOptionPane.showMessageDialog( this, "Please enter a valid port. (1-65535)", "Invalid port", JOptionPane.ERROR_MESSAGE ); return false; } m_port = port; return true; } /*--------------------------------------------------------------- * AbstractTabularOptionDialog Methods *-------------------------------------------------------------*/ /** * Returns an array of labels to use for the components returned from * getMainPanelComponents(). * * @returns An array of labels. */ protected String[] getMainPanelLabels() { return new String[] { "Host:", "Port:" }; } /** * Returns an array of components to show in the main panel of the dialog. * * @returns An array of components. */ protected Component[] getMainPanelComponents() { m_hostField = new JTextField(); m_hostField.setColumns( 20 ); m_hostField.setText( "localhost " ); m_portField = new JTextField(); m_portField.setColumns( 6 ); m_portField.setText( "1099" ); return new Component[] { m_hostField, m_portField }; } /*--------------------------------------------------------------- * Methods *-------------------------------------------------------------*/ /** * Sets the initial host to be shown in the host TextField. * * @param host The initial host. */ void setHost( String host ) { m_host = host; m_hostField.setText( host ); } /** * Returns the host set in the dialog. * * @return The host. */ public String getHost() { return m_host; } /** * Sets the initial port to be shown in the port TextField. * * @param port The initial port. */ void setPort( int port ) { m_port = port; m_portField.setText( Integer.toString( port ) ); } /** * Returns the port set in the dialog. * * @return The port. */ public int getPort() { return m_port; } } 1.1 jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/mbean/MBeanAccessor.java Index: MBeanAccessor.java =================================================================== package org.apache.avalon.phyre.mbean; import java.util.ArrayList; import javax.management.InstanceNotFoundException; import javax.management.MBeanAttributeInfo; import javax.management.MBeanException; import javax.management.MBeanInfo; import javax.management.ObjectInstance; import javax.management.ObjectName; import javax.management.ReflectionException; import mx4j.connector.RemoteMBeanServer; /** * This is a small utility class to allow easy access to mbean attributes. * * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a> */ public class MBeanAccessor { private final RemoteMBeanServer m_mBeanServer; private final ObjectName m_objectName; private MBeanInfo m_mBeanInfo; private ObjectInstance m_objectInstance; /** Hold the attribute objects by attribute name */ private ArrayList m_attributes = new ArrayList(); /** * Create an accessor that treats, mBean attributes as normal attributes. * It also adds a special attribute "meta" via which you can get the * MBeanInfo. * * @param mBeanInfo the MBeanInfo to wrap */ public MBeanAccessor( final ObjectName objectName, final RemoteMBeanServer mBeanServer ) { m_objectName = objectName; m_mBeanServer = mBeanServer; } public String className() throws Exception { return getObjectInstance().getClassName(); } public MBeanInfo info() throws Exception { return getMBeanInfo(); } public ObjectName name() { return m_objectName; } /** * Accessor method to get the fields by name. * * @param fieldName Name of static field to retrieve * * @return The value of the given field. */ public Object get( String fieldName ) throws Exception { //We need to force load the MBeanInfo //If it hasn't yet been loaded getMBeanInfo(); if( m_attributes.contains( fieldName ) ) { return m_mBeanServer.getAttribute( m_objectName, fieldName ); } else { return null; } } private MBeanInfo getMBeanInfo() throws Exception { if( null == m_mBeanInfo ) { m_mBeanInfo = m_mBeanServer.getMBeanInfo( m_objectName ); final MBeanAttributeInfo[] attributes = m_mBeanInfo.getAttributes(); if( null != attributes ) { for( int i = 0; i < attributes.length; i++ ) { final MBeanAttributeInfo attribute = attributes[i]; m_attributes.add( attribute.getName() ); } } } return m_mBeanInfo; } private ObjectInstance getObjectInstance() throws Exception { if( null == m_objectInstance ) { m_objectInstance = m_mBeanServer.getObjectInstance( m_objectName ); } return m_objectInstance; } public Object invoke( final String name ) throws Exception { return invoke( name, new Object[0], new String[0] ); } private String[] getParameterTypes( final Object[] params ) { final String[] types = new String[params.length]; for( int i = 0; i < params.length; i++ ) { types[i] = params[i].getClass().getName(); } return types; } public Object invoke( final String name, final Object[] params ) throws Exception { return invoke( name, params, getParameterTypes( params ) ); } public Object invoke( final String name, final Object[] params, final String[] paramTypes ) throws Exception { try { return m_mBeanServer.invoke( m_objectName, name, params, paramTypes ); } catch( InstanceNotFoundException e ) { throw new RuntimeException( "Unable to locate MBean: " + e.getMessage() ); } catch( MBeanException e ) { e.printStackTrace(); throw new RuntimeException( "Exception invoking method: " + e.getMessage() ); } catch( ReflectionException e ) { throw e.getTargetException(); } } } 1.1 jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/mbean/MBeanManager.java Index: MBeanManager.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.avalon.phyre.mbean; import java.util.Hashtable; import javax.management.ObjectName; import mx4j.connector.RemoteMBeanServer; import mx4j.connector.rmi.RMIConnector; import mx4j.connector.rmi.jrmp.JRMPConnector; /** * @author <a href="mailto:[EMAIL PROTECTED]">Peter Royal</a> */ public class MBeanManager { private final RMIConnector m_connector; private final RemoteMBeanServer m_server; private final String m_host; private final int m_port; public MBeanManager( String host, int port ) throws Exception { this.m_host = host; this.m_port = port; this.m_connector = new JRMPConnector(); this.m_connector.connect( "jrmp", createProperties( host, port ) ); this.m_server = this.m_connector.getRemoteMBeanServer(); } private Hashtable createProperties( String host, int port ) { Hashtable h = new Hashtable( 2 ); h.put( "java.naming.provider.url", "rmi://" + host + ":" + port ); h.put( "java.naming.factory.initial", "com.sun.jndi.rmi.registry.RegistryContextFactory" ); return h; } public MBeanAccessor getObject( final String name ) throws Exception { return new MBeanAccessor( getObjectName( name ), m_server ); } private ObjectName getObjectName( final String name ) throws Exception { //Deal with domains et al here return new ObjectName( name ); } public void close() { this.m_connector.close(); } } 1.1 jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/panels/AbstractContentPanel.java Index: AbstractContentPanel.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.avalon.phyre.panels; import java.awt.LayoutManager; import javax.swing.JPanel; import org.apache.avalon.phyre.PhyreFrame; /** * @author <a href="mailto:[EMAIL PROTECTED]">Peter Royal</a> */ public class AbstractContentPanel extends JPanel { protected final PhyreFrame m_phyreFrame; public AbstractContentPanel( PhyreFrame phyreFrame, LayoutManager layout ) { super( layout ); this.m_phyreFrame = phyreFrame; } } 1.1 jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/panels/AbstractMBeanPanel.java Index: AbstractMBeanPanel.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.avalon.phyre.panels; import java.awt.BorderLayout; import java.awt.GridLayout; import javax.management.MBeanAttributeInfo; import javax.management.MBeanInfo; import javax.swing.JLabel; import javax.swing.JPanel; import org.apache.avalon.phyre.PhyreFrame; import org.apache.avalon.phyre.mbean.MBeanAccessor; /** * @author <a href="mailto:[EMAIL PROTECTED]">Peter Royal</a> */ public abstract class AbstractMBeanPanel extends AbstractContentPanel { private MBeanAccessor m_mbean; public AbstractMBeanPanel( PhyreFrame phyreFrame ) { super( phyreFrame, new BorderLayout() ); } protected void initialize() throws Exception { final JPanel panel = new JPanel( new GridLayout( 0, 2 ) ); add( panel, BorderLayout.CENTER ); addAttributes( panel ); addOperations(); } protected void setMBean( MBeanAccessor mbean ) { m_mbean = mbean; } protected void addAttributes( JPanel panel ) throws Exception { final MBeanInfo info = this.getMBean().info(); final MBeanAttributeInfo[] attributeInfos = info.getAttributes(); for( int i = 0; i < attributeInfos.length; i++ ) { panel.add( new JLabel( attributeInfos[i].getName() ) ); panel.add( new JLabel( this.getMBean().get( attributeInfos[i].getName() ).toString() ) ); } } protected abstract void addOperations(); protected MBeanAccessor getMBean() { return m_mbean; } } 1.1 jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/panels/ApplicationPanel.java Index: ApplicationPanel.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.avalon.phyre.panels; import java.awt.BorderLayout; import javax.swing.JButton; import javax.swing.JPanel; import org.apache.avalon.phyre.PhyreFrame; import org.apache.avalon.phyre.actions.MBeanInvokeAction; import org.apache.avalon.phyre.mbean.MBeanAccessor; /** * @author <a href="mailto:[EMAIL PROTECTED]">Peter Royal</a> */ public class ApplicationPanel extends AbstractMBeanPanel { private static final String OBJECT_NAME = "Phoenix:application="; public ApplicationPanel( MBeanAccessor mbean, PhyreFrame phyreFrame ) throws Exception { super( phyreFrame ); setMBean( mbean ); initialize(); } protected void addOperations() { try { final JPanel panel = new JPanel(); final String name = ( String ) getMBean().get( "displayName" ); panel.add( new JButton( new MBeanInvokeAction( "Stop " + name, "stop", getMBean() ) ) ); panel.add( new JButton( new MBeanInvokeAction( "Restart " + name, "restart", getMBean() ) ) ); panel.add( new JButton( "Undeploy " + name ) ); this.add( panel, BorderLayout.SOUTH ); } catch( Exception e ) { e.printStackTrace(); } } } 1.1 jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/panels/HomePanel.java Index: HomePanel.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.avalon.phyre.panels; import java.awt.BorderLayout; import javax.swing.JButton; import javax.swing.JPanel; import org.apache.avalon.phyre.PhyreFrame; import org.apache.avalon.phyre.actions.MBeanInvokeAction; /** * @author <a href="mailto:[EMAIL PROTECTED]">Peter Royal</a> */ public class HomePanel extends AbstractMBeanPanel { private static final String OBJECT_NAME = "Phoenix:component=Embeddor"; public HomePanel( PhyreFrame phyreFrame ) throws Exception { super( phyreFrame ); setMBean( this.m_phyreFrame.getMBeanManager().getObject( OBJECT_NAME ) ); initialize(); } protected void addOperations() { final JPanel panel = new JPanel(); //TODO: Probably want to close the app or otherwise halt the console if they shutdown //phoenix okay :) panel.add( new JButton( new MBeanInvokeAction( "Shutdown Phoenix", "shutdown", getMBean() ) ) ); panel.add( new JButton( new MBeanInvokeAction( "Restart Phoenix", "restart", getMBean() ) ) ); // panel.add( new JButton( "Restart Phoenix in new JVM" ) ); this.add( panel, BorderLayout.SOUTH ); } } 1.1 jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/panels/ModifyConfigurationPanel.java Index: ModifyConfigurationPanel.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.avalon.phyre.panels; import java.awt.BorderLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.StringReader; import javax.swing.JButton; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import org.xml.sax.InputSource; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder; import org.apache.avalon.framework.configuration.DefaultConfigurationSerializer; import org.apache.avalon.phyre.PhyreFrame; import org.apache.avalon.phyre.mbean.MBeanAccessor; /** * @author <a href="mailto:[EMAIL PROTECTED]">Peter Royal</a> */ public class ModifyConfigurationPanel extends AbstractContentPanel { private static final String VALIDATOR = "Phoenix:component=ConfigurationValidator"; private static final String[] CONFIG_METHOD_TYPES = new String[]{String.class.getName(), String.class.getName(), Configuration.class.getName()}; private final MBeanAccessor m_configManager; private final MBeanAccessor m_configValidator; private final String m_app; private final String m_block; private final JTextArea m_textArea; public ModifyConfigurationPanel( final String app, final String block, final MBeanAccessor configManager, final PhyreFrame phyreFrame ) throws Exception { super( phyreFrame, new BorderLayout() ); m_configValidator = phyreFrame.getMBeanManager().getObject( VALIDATOR ); m_configManager = configManager; m_block = block; m_app = app; m_textArea = new JTextArea(); add( new JScrollPane( m_textArea ), BorderLayout.CENTER ); addButtons(); loadConfiguration(); } private void loadConfiguration() throws Exception { final Configuration c = ( Configuration ) m_configManager.invoke( "getConfiguration", new Object[]{m_app, m_block} ); final DefaultConfigurationSerializer serializer = new DefaultConfigurationSerializer(); serializer.setIndent( true ); m_textArea.setText( serializer.serialize( c ) ); } private Configuration createConfiguration() throws ConfigurationException { final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(); try { return builder.build( new InputSource( new StringReader( m_textArea.getText() ) ) ); } catch( ConfigurationException e ) { throw e; } catch( Exception e ) { e.printStackTrace(); throw new RuntimeException( "unable to create configuration: " + e.getMessage() ); } } private boolean isConfigurationValid( final Configuration c ) { try { final Boolean b = ( Boolean ) m_configValidator.invoke( "isValid", new Object[]{m_app, m_block, c}, CONFIG_METHOD_TYPES ); return b.booleanValue(); } catch( Exception e ) { e.printStackTrace(); } return false; } private void showValidationResult() { try { final boolean valid = isConfigurationValid( createConfiguration() ); showValidationResultsDialog( valid ); } catch( ConfigurationException e ) { showConfigurationExceptionDialog( e ); } } private void showValidationResultsDialog( final boolean valid ) { JOptionPane.showMessageDialog( this, valid ? "Valid" : "Invalid", "Validation Results", JOptionPane.INFORMATION_MESSAGE, null ); } private void showConfigurationExceptionDialog( ConfigurationException e ) { JOptionPane.showMessageDialog( this, "Error in configuration: " + e.getMessage(), "Invalid Configuration", JOptionPane.ERROR_MESSAGE, null ); } private void storeConfiguration() { Configuration c = null; try { c = createConfiguration(); } catch( ConfigurationException e ) { showConfigurationExceptionDialog( e ); return; } if( isConfigurationValid( c ) ) { try { m_configManager.invoke( "storeConfiguration", new Object[]{m_app, m_block, c}, CONFIG_METHOD_TYPES ); JOptionPane.showMessageDialog( this, "Configuration Updated!"); } catch( Exception e ) { e.printStackTrace(); } } else { showValidationResultsDialog( false ); } } private void addButtons() { final JPanel buttons = new JPanel( new GridLayout( 1, 0 ) ); final JButton validateButton = new JButton( "Validate" ); validateButton.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent e ) { if( ActionEvent.ACTION_PERFORMED == e.getID() ) { showValidationResult(); } } } ); buttons.add( validateButton ); final JButton updateButton = new JButton( "Update" ); updateButton.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent e ) { if( ActionEvent.ACTION_PERFORMED == e.getID() ) { storeConfiguration(); } } } ); buttons.add( updateButton ); add( buttons, BorderLayout.SOUTH ); } } 1.1 jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/panels/applist/ApplicationListPanel.java Index: ApplicationListPanel.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.avalon.phyre.panels.applist; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JScrollPane; import javax.swing.JTable; import org.apache.avalon.phyre.PhyreFrame; import org.apache.avalon.phyre.panels.AbstractContentPanel; /** * @author <a href="mailto:[EMAIL PROTECTED]">Peter Royal</a> */ public class ApplicationListPanel extends AbstractContentPanel { public ApplicationListPanel( PhyreFrame phyreFrame ) throws Exception { super( phyreFrame, new GridBagLayout() ); final GridBagConstraints constraints = new GridBagConstraints(); constraints.fill = GridBagConstraints.BOTH; constraints.weightx = 2.0; constraints.gridwidth = GridBagConstraints.REMAINDER; add( new JLabel( "Applications", JLabel.CENTER ), constraints ); constraints.weightx = 1.0; constraints.gridwidth = 1; add( new JButton( "Deploy an Application" ), constraints ); constraints.gridwidth = GridBagConstraints.REMAINDER; add( new JButton( "Query Applications" ), constraints ); constraints.weightx = 2.0; constraints.weighty = 1.0; final JTable table = new JTable( new ApplicationTableModel( m_phyreFrame ) ); table.addMouseListener( new ApplicationTableMouseListener( m_phyreFrame ) ); add( new JScrollPane( table ), constraints ); } } 1.1 jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/panels/applist/ApplicationTableModel.java Index: ApplicationTableModel.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.avalon.phyre.panels.applist; import javax.swing.table.AbstractTableModel; import org.apache.avalon.phyre.PhyreFrame; import org.apache.avalon.phyre.mbean.MBeanAccessor; import org.apache.avalon.phyre.mbean.MBeanManager; /** * @author <a href="mailto:[EMAIL PROTECTED]">Peter Royal</a> */ public class ApplicationTableModel extends AbstractTableModel { private static final String KERNEL = "Phoenix:component=Kernel"; private static final String APP = "Phoenix:application="; private static final String[] COLUMNS = new String[]{"Name", "Description", "Status"}; private final String[] m_applications; private final MBeanAccessor[] m_mbeans; public ApplicationTableModel( final PhyreFrame phyreFrame ) throws Exception { final MBeanManager manager = phyreFrame.getMBeanManager(); final MBeanAccessor object = manager.getObject( KERNEL ); this.m_applications = ( String[] ) object.get( "applicationNames" ); this.m_mbeans = new MBeanAccessor[this.m_applications.length]; for( int i = 0; i < m_applications.length; i++ ) { this.m_mbeans[i] = manager.getObject( APP + m_applications[i] ); } } public int getColumnCount() { return COLUMNS.length; } public int getRowCount() { return this.m_applications.length; } public Object getValueAt( int rowIndex, int columnIndex ) { try { switch( columnIndex ) { case 0: return this.m_mbeans[rowIndex].get( "displayName" ); case 1: return this.m_mbeans[rowIndex].get( "description" ); case 2: final boolean b = ( ( Boolean ) this.m_mbeans[rowIndex].get( "running" ) ).booleanValue(); return b ? "Running" : "Stopped"; default: return null; } } catch( Exception e ) { e.printStackTrace(); throw new RuntimeException( e.getMessage() ); } } public String getColumnName( int column ) { return COLUMNS[column]; } public MBeanAccessor getMBean( int rowIndex ) { return this.m_mbeans[rowIndex]; } public String getApplication( int rowIndex ) { return this.m_applications[rowIndex]; } } 1.1 jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/panels/applist/ApplicationTableMouseListener.java Index: ApplicationTableMouseListener.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.avalon.phyre.panels.applist; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.JTable; import org.apache.avalon.phyre.PhyreFrame; import org.apache.avalon.phyre.mbean.MBeanAccessor; import org.apache.avalon.phyre.panels.navigation.ApplicationNavigationPanel; import org.apache.avalon.phyre.panels.ApplicationPanel; /** * @author <a href="mailto:[EMAIL PROTECTED]">Peter Royal</a> */ public class ApplicationTableMouseListener extends MouseAdapter { private final PhyreFrame m_phyreFrame; public ApplicationTableMouseListener( PhyreFrame phyreFrame ) { m_phyreFrame = phyreFrame; } public void mouseClicked( MouseEvent e ) { if( e.getClickCount() > 1 ) { final JTable table = ( JTable ) e.getSource(); final ApplicationTableModel model = ( ApplicationTableModel ) table.getModel(); try { final MBeanAccessor bean = model.getMBean( table.getSelectedRow() ); m_phyreFrame.setContentPanel( new ApplicationPanel( bean, m_phyreFrame ) ); m_phyreFrame.setNavigationPanel( new ApplicationNavigationPanel( bean, m_phyreFrame ) ); } catch( Exception e1 ) { e1.printStackTrace(); } } } } 1.1 jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/panels/blocklist/BlockListPanel.java Index: BlockListPanel.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.avalon.phyre.panels.blocklist; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import javax.swing.JLabel; import javax.swing.JScrollPane; import javax.swing.JTable; import org.apache.avalon.phyre.PhyreFrame; import org.apache.avalon.phyre.mbean.MBeanAccessor; import org.apache.avalon.phyre.panels.AbstractContentPanel; import org.apache.avalon.phyre.panels.applist.ApplicationTableMouseListener; /** * @author <a href="mailto:[EMAIL PROTECTED]">Peter Royal</a> */ public class BlockListPanel extends AbstractContentPanel { public BlockListPanel( MBeanAccessor mbean, PhyreFrame phyreFrame ) throws Exception { super( phyreFrame, new GridBagLayout() ); final GridBagConstraints constraints = new GridBagConstraints(); constraints.fill = GridBagConstraints.BOTH; constraints.weightx = 2.0; constraints.gridwidth = GridBagConstraints.REMAINDER; add( new JLabel( "Components", JLabel.CENTER ), constraints ); constraints.weighty = 1.0; final JTable table = new JTable( new BlockTableModel( mbean, m_phyreFrame ) ); table.addMouseListener( new BlockTableMouseListener( m_phyreFrame ) ); add( new JScrollPane( table ), constraints ); } } 1.1 jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/panels/blocklist/BlockTableModel.java Index: BlockTableModel.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.avalon.phyre.panels.blocklist; import javax.swing.table.AbstractTableModel; import org.apache.avalon.phyre.PhyreFrame; import org.apache.avalon.phyre.mbean.MBeanAccessor; import org.apache.avalon.phyre.mbean.MBeanManager; /** * @author <a href="mailto:[EMAIL PROTECTED]">Peter Royal</a> */ public class BlockTableModel extends AbstractTableModel { private static final String CONFIG_MANAGER = "Phoenix:component=ConfigurationManager"; private static final String[] COLUMNS = new String[]{"Component Name", "Has Configuration"}; private final String m_name; private final MBeanAccessor m_mbean; private final MBeanAccessor m_configManager; private final String[] m_blocks; public BlockTableModel( MBeanAccessor mbean, final PhyreFrame phyreFrame ) throws Exception { final MBeanManager manager = phyreFrame.getMBeanManager(); this.m_configManager = manager.getObject( CONFIG_MANAGER ); this.m_mbean = mbean; this.m_blocks = ( String[] ) mbean.get( "blockNames" ); this.m_name = ( String ) mbean.get( "name" ); } public int getColumnCount() { return COLUMNS.length; } public int getRowCount() { return this.m_blocks.length; } public Object getValueAt( int rowIndex, int columnIndex ) { try { switch( columnIndex ) { case 0: return getBlockName(rowIndex); case 1: return this.m_configManager.invoke( "hasConfiguration", new Object[]{m_name, getBlockName(rowIndex)} ); default: throw new IllegalArgumentException("invalid column: " + columnIndex); } } catch( Exception e ) { e.printStackTrace(); throw new RuntimeException( e.getMessage() ); } } public String getColumnName( int column ) { return COLUMNS[column]; } public Class getColumnClass( int columnIndex ) { switch( columnIndex ) { case 0: return String.class; case 1: return Boolean.class; default: throw new IllegalArgumentException("invalid column: " + columnIndex); } } public MBeanAccessor getConfigManager() { return m_configManager; } public String getBlockName( int rowIndex ) { return m_blocks[ rowIndex ]; } public String getName() { return m_name; } } 1.1 jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/panels/blocklist/BlockTableMouseListener.java Index: BlockTableMouseListener.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.avalon.phyre.panels.blocklist; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.JTable; import org.apache.avalon.phyre.PhyreFrame; import org.apache.avalon.phyre.panels.ModifyConfigurationPanel; /** * @author <a href="mailto:[EMAIL PROTECTED]">Peter Royal</a> */ public class BlockTableMouseListener extends MouseAdapter { private final PhyreFrame m_phyreFrame; public BlockTableMouseListener( PhyreFrame phyreFrame ) { m_phyreFrame = phyreFrame; } public void mouseClicked( MouseEvent e ) { if( e.getClickCount() > 1 ) { final JTable table = ( JTable ) e.getSource(); final BlockTableModel model = ( BlockTableModel ) table.getModel(); try { m_phyreFrame.setContentPanel( new ModifyConfigurationPanel( model.getName(), model.getBlockName( table.getSelectedRow() ), model.getConfigManager(), m_phyreFrame ) ); } catch( Exception e1 ) { e1.printStackTrace(); } } } } 1.1 jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/panels/navigation/AbstractNavigationPanel.java Index: AbstractNavigationPanel.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.avalon.phyre.panels.navigation; import java.awt.GridLayout; import javax.swing.JPanel; /** * @author <a href="mailto:[EMAIL PROTECTED]">Peter Royal</a> */ public class AbstractNavigationPanel extends JPanel { public AbstractNavigationPanel() { super( new GridLayout( 0, 1 ) ); } } 1.1 jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/panels/navigation/ApplicationNavigationPanel.java Index: ApplicationNavigationPanel.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.avalon.phyre.panels.navigation; import javax.swing.JButton; import org.apache.avalon.phyre.PhyreFrame; import org.apache.avalon.phyre.panels.blocklist.BlockListPanel; import org.apache.avalon.phyre.panels.ApplicationPanel; import org.apache.avalon.phyre.actions.MBeanSwitchContentPanelAction; import org.apache.avalon.phyre.mbean.MBeanAccessor; /** * @author <a href="mailto:[EMAIL PROTECTED]">Peter Royal</a> */ public class ApplicationNavigationPanel extends AbstractNavigationPanel { public ApplicationNavigationPanel( final MBeanAccessor appMBean, final PhyreFrame phyreFrame ) { try { add( new JButton( new MBeanSwitchContentPanelAction( ( String ) appMBean.get( "displayName" ), appMBean, ApplicationPanel.class, phyreFrame ) ) ); add( new JButton( new MBeanSwitchContentPanelAction( "Configuration", appMBean, BlockListPanel.class, phyreFrame ) ) ); add( new JButton( "Logging" ) ); add( new JButton( "Manageable Services" ) ); add( new JButton( "Permissions" ) ); } catch( Exception e ) { e.printStackTrace(); } } } 1.1 jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/panels/navigation/PrimaryNavigationPanel.java Index: PrimaryNavigationPanel.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.avalon.phyre.panels.navigation; import javax.swing.JButton; import javax.swing.JLabel; import org.apache.avalon.phyre.PhyreFrame; import org.apache.avalon.phyre.actions.SwitchContentPanelAction; import org.apache.avalon.phyre.panels.applist.ApplicationListPanel; /** * @author <a href="mailto:[EMAIL PROTECTED]">Peter Royal</a> */ public class PrimaryNavigationPanel extends AbstractNavigationPanel { public PrimaryNavigationPanel( PhyreFrame phyreFrame ) { add( new JLabel( "Hosted Components" ) ); add( new JButton( new SwitchContentPanelAction( "Hosted Applications", ApplicationListPanel.class, phyreFrame ) ) ); add( new JButton( "Extension Libraries" ) ); add( new JButton( "Loggers" ) ); add( new JLabel( "Container Components" ) ); add( new JButton( "Configuration Repository" ) ); add( new JButton( "Deployer" ) ); add( new JButton( "Log Manager" ) ); add( new JButton( "System Manager" ) ); } }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>