[Ejtools-cvs] libraries/adwt/src/main/org/ejtools/adwt FileUtil.java,NONE,1.1 BeanContextListView.ja
Brought to you by:
letiemble
Update of /cvsroot/ejtools/libraries/adwt/src/main/org/ejtools/adwt In directory sc8-pr-cvs1:/tmp/cvs-serv8980/adwt/src/main/org/ejtools/adwt Modified Files: BeanContextListView.java GenericCustomizer.java GenericMBeanCustomizer.java GenericMBeanMethodDialog.java SimpleCustomizer.java Added Files: FileUtil.java Log Message: Address Todo #755528 Remove @created tags --- NEW FILE: FileUtil.java --- /* * EJTools, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package org.ejtools.adwt; import java.io.File; import java.net.URL; import java.util.ResourceBundle; import javax.swing.JFileChooser; import javax.swing.filechooser.FileFilter; import org.apache.log4j.Logger; /** * Description of the Class * * @author Laurent Etiemble * @version $Revision: 1.1 $ * @todo Javadoc to complete */ public class FileUtil { /** Description of the Field */ public static FileFilter WORKSPACE_FILE_FILTER = new FileFilter() { public boolean accept(File file) { return file.getName().endsWith(".xml"); } public String getDescription() { return resources.getString("workspace.file.dialog.extension.description"); } }; /** Default logger */ private static Logger logger = Logger.getLogger(FileUtil.class); /** Bundle for I18N */ private static ResourceBundle resources = ResourceBundle.getBundle("org.ejtools.adwt.Resources"); /**Constructor for the FileUtil object */ private FileUtil() { } /** * Description of the Method * * @param title Description of the Parameter * @param type Description of the Parameter * @return Description of the Return Value * @exception Exception Description of the Exception */ public static URL selectWorkspaceFile(String title, int type) throws Exception { // Fix for JFileChooser/SecurityManager bug (#4264750) SecurityManager s = System.getSecurityManager(); System.setSecurityManager(null); // Choose file JFileChooser chooser = new JFileChooser(System.getProperty("user.dir")); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setDialogTitle(title); chooser.setDialogType(type); chooser.setFileFilter(WORKSPACE_FILE_FILTER); int returnVal = chooser.showDialog(null, title); System.setSecurityManager(s); if (returnVal != JFileChooser.APPROVE_OPTION) { return null; } return chooser.getSelectedFile().toURL(); } } Index: BeanContextListView.java =================================================================== RCS file: /cvsroot/ejtools/libraries/adwt/src/main/org/ejtools/adwt/BeanContextListView.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** BeanContextListView.java 15 Sep 2003 22:37:12 -0000 1.4 --- BeanContextListView.java 27 Nov 2003 00:51:44 -0000 1.5 *************** *** 1,289 **** ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.adwt; ! ! import java.awt.Component; ! import java.beans.BeanInfo; ! import java.beans.Introspector; ! import java.beans.beancontext.BeanContext; ! import java.beans.beancontext.BeanContextChildComponentProxy; ! import java.beans.beancontext.BeanContextContainerProxy; ! import java.beans.beancontext.BeanContextMembershipEvent; ! import java.beans.beancontext.BeanContextMembershipListener; ! import java.lang.reflect.Method; ! import java.util.Iterator; ! import java.util.Vector; ! ! import javax.swing.DefaultListCellRenderer; ! import javax.swing.ImageIcon; ! import javax.swing.JLabel; ! import javax.swing.JList; ! import javax.swing.ListModel; ! import javax.swing.event.ListDataEvent; ! import javax.swing.event.ListDataListener; ! ! /** ! * Description of the Class ! * ! * @author Laurent Etiemble ! * @version $Revision$ ! */ ! public class BeanContextListView extends JList ! { ! /** ! * Constructor for the BeanContextTreeView object ! * ! * @param beancontext Description of Parameter ! */ ! public BeanContextListView(BeanContext beancontext) ! { ! this.setModel(new BeanContextListModel(beancontext)); ! this.setCellRenderer( ! new DefaultListCellRenderer() ! { ! public Component getListCellRendererComponent(JList list, Object obj, int index, boolean isSelected, boolean cellHasFocus) ! { ! try ! { ! ContextElement contextelement = (ContextElement) obj; ! Object obj1 = contextelement.getUserObject(); ! super.getListCellRendererComponent(list, obj1, index, isSelected, cellHasFocus); ! if (contextelement.icon != null) ! { ! setIcon(contextelement.icon); ! } ! return this; ! } ! catch (Exception _ex) ! { ! System.err.println(_ex.getMessage()); ! return super.getListCellRendererComponent(list, obj, index, isSelected, cellHasFocus); ! } ! } ! }); ! ! } ! ! ! /** ! * Description of the Class ! * ! * @author Administrator ! * @version $Revision$ ! * @created 16 octobre 2001 ! */ ! protected class BeanContextListModel implements ListModel, BeanContextMembershipListener ! { ! /** Description of the Field */ ! protected Vector content = new Vector(); ! /** Description of the Field */ ! protected BeanContext context; ! /** Description of the Field */ ! protected Vector listeners = new Vector(); ! ! ! /** ! * Constructor for the BeanContextListModel object ! * ! * @param beancontext Description of Parameter ! */ ! public BeanContextListModel(BeanContext beancontext) ! { ! this.context = beancontext; ! this.context.addBeanContextMembershipListener(this); ! this.updateModel(); ! } ! ! ! /** ! * Adds a feature to the ListDataListener attribute of the BeanContextListModel object ! * ! * @param l The feature to be added to the ListDataListener attribute ! */ ! public void addListDataListener(ListDataListener l) ! { ! this.listeners.add(l); ! } ! ! ! /** ! * Description of the Method ! * ! * @param beancontextmembershipevent Description of Parameter ! */ ! public void childrenAdded(BeanContextMembershipEvent beancontextmembershipevent) ! { ! this.updateModel(); ! this.notifyListener(); ! } ! ! ! /** ! * Description of the Method ! * ! * @param beancontextmembershipevent Description of Parameter ! */ ! public void childrenRemoved(BeanContextMembershipEvent beancontextmembershipevent) ! { ! this.updateModel(); ! this.notifyListener(); ! } ! ! ! /** ! * Description of the Method ! * ! * @param index Description of Parameter ! * @return Description of the Returned Value ! */ ! public Object getElementAt(int index) ! { ! return this.content.elementAt(index); ! } ! ! ! /** ! * Gets the size attribute of the BeanContextListModel object ! * ! * @return The size value ! */ ! public int getSize() ! { ! return this.context.size(); ! } ! ! ! /** ! * Description of the Method ! * ! * @param l Description of Parameter ! */ ! public void removeListDataListener(ListDataListener l) ! { ! this.listeners.remove(l); ! } ! ! ! /** Description of the Method */ ! private void notifyListener() ! { ! ListDataEvent event = new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, 0, this.content.size()); ! for (int i = 0; i < this.listeners.size(); i++) ! { ! ListDataListener listener = (ListDataListener) this.listeners.elementAt(i); ! listener.contentsChanged(event); ! } ! } ! ! ! /** Description of the Method */ ! private void updateModel() ! { ! this.content.clear(); ! Iterator iterator = this.context.iterator(); ! while (iterator.hasNext()) ! { ! this.content.addElement(new ContextElement(iterator.next())); ! } ! } ! } ! ! ! /** ! * Description of the Class ! * ! * @author Administrator ! * @version $Revision$ ! * @created 16 octobre 2001 ! */ ! protected class ContextElement implements BeanContextChildComponentProxy ! { ! /** Description of the Field */ ! protected ImageIcon icon = null; ! /** Description of the Field */ ! protected Object obj; ! /** Description of the Field */ ! protected String txt; ! ! ! /** ! * Constructor for the ContextNode object ! * ! * @param obj1 Description of Parameter ! */ ! public ContextElement(Object obj1) ! { ! obj = obj1; ! try ! { ! BeanInfo beaninfo = Introspector.getBeanInfo(obj1.getClass()); ! if (beaninfo.getIcon(1) != null) ! { ! icon = new ImageIcon(beaninfo.getIcon(1)); ! } ! Method method = obj1.getClass().getMethod("toString", new Class[0]); ! if (method.getDeclaringClass().equals(Object.class)) ! { ! txt = beaninfo.getBeanDescriptor().getDisplayName(); ! } ! } ! catch (Exception exception) ! { ! exception.printStackTrace(); ! } ! } ! ! ! /** ! * Gets the component attribute of the ContextNode object ! * ! * @return The component value ! */ ! public Component getComponent() ! { ! if (obj instanceof Component) ! { ! return (Component) obj; ! } ! if (obj instanceof BeanContextContainerProxy) ! { ! return ((BeanContextContainerProxy) obj).getContainer(); ! } ! if (obj instanceof BeanContextChildComponentProxy) ! { ! return ((BeanContextChildComponentProxy) obj).getComponent(); ! } ! else ! { ! return new JLabel("No GUI available", 0); ! } ! } ! ! ! /** ! * Gets the userObject attribute of the ContextNode object ! * ! * @return The userObject value ! */ ! public Object getUserObject() ! { ! return obj; ! } ! ! ! /** ! * Description of the Method ! * ! * @return Description of the Returned Value ! */ ! public String toString() ! { ! return txt != null ? txt : obj.toString(); ! } ! } ! } ! --- 1,287 ---- ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.adwt; ! ! import java.awt.Component; ! import java.beans.BeanInfo; ! import java.beans.Introspector; ! import java.beans.beancontext.BeanContext; ! import java.beans.beancontext.BeanContextChildComponentProxy; ! import java.beans.beancontext.BeanContextContainerProxy; ! import java.beans.beancontext.BeanContextMembershipEvent; ! import java.beans.beancontext.BeanContextMembershipListener; ! import java.lang.reflect.Method; ! import java.util.Iterator; ! import java.util.Vector; ! ! import javax.swing.DefaultListCellRenderer; ! import javax.swing.ImageIcon; ! import javax.swing.JLabel; ! import javax.swing.JList; ! import javax.swing.ListModel; ! import javax.swing.event.ListDataEvent; ! import javax.swing.event.ListDataListener; ! ! /** ! * Description of the Class ! * ! * @author Laurent Etiemble ! * @version $Revision$ ! */ ! public class BeanContextListView extends JList ! { ! /** ! * Constructor for the BeanContextTreeView object ! * ! * @param beancontext Description of Parameter ! */ ! public BeanContextListView(BeanContext beancontext) ! { ! this.setModel(new BeanContextListModel(beancontext)); ! this.setCellRenderer( ! new DefaultListCellRenderer() ! { ! public Component getListCellRendererComponent(JList list, Object obj, int index, boolean isSelected, boolean cellHasFocus) ! { ! try ! { ! ContextElement contextelement = (ContextElement) obj; ! Object obj1 = contextelement.getUserObject(); ! super.getListCellRendererComponent(list, obj1, index, isSelected, cellHasFocus); ! if (contextelement.icon != null) ! { ! setIcon(contextelement.icon); ! } ! return this; ! } ! catch (Exception _ex) ! { ! System.err.println(_ex.getMessage()); ! return super.getListCellRendererComponent(list, obj, index, isSelected, cellHasFocus); ! } ! } ! }); ! ! } ! ! ! /** ! * Description of the Class ! * ! * @author Administrator ! * @version $Revision$ ! */ ! protected class BeanContextListModel implements ListModel, BeanContextMembershipListener ! { ! /** Description of the Field */ ! protected Vector content = new Vector(); ! /** Description of the Field */ ! protected BeanContext context; ! /** Description of the Field */ ! protected Vector listeners = new Vector(); ! ! ! /** ! * Constructor for the BeanContextListModel object ! * ! * @param beancontext Description of Parameter ! */ ! public BeanContextListModel(BeanContext beancontext) ! { ! this.context = beancontext; ! this.context.addBeanContextMembershipListener(this); ! this.updateModel(); ! } ! ! ! /** ! * Adds a feature to the ListDataListener attribute of the BeanContextListModel object ! * ! * @param l The feature to be added to the ListDataListener attribute ! */ ! public void addListDataListener(ListDataListener l) ! { ! this.listeners.add(l); ! } ! ! ! /** ! * Description of the Method ! * ! * @param beancontextmembershipevent Description of Parameter ! */ ! public void childrenAdded(BeanContextMembershipEvent beancontextmembershipevent) ! { ! this.updateModel(); ! this.notifyListener(); ! } ! ! ! /** ! * Description of the Method ! * ! * @param beancontextmembershipevent Description of Parameter ! */ ! public void childrenRemoved(BeanContextMembershipEvent beancontextmembershipevent) ! { ! this.updateModel(); ! this.notifyListener(); ! } ! ! ! /** ! * Description of the Method ! * ! * @param index Description of Parameter ! * @return Description of the Returned Value ! */ ! public Object getElementAt(int index) ! { ! return this.content.elementAt(index); ! } ! ! ! /** ! * Gets the size attribute of the BeanContextListModel object ! * ! * @return The size value ! */ ! public int getSize() ! { ! return this.context.size(); ! } ! ! ! /** ! * Description of the Method ! * ! * @param l Description of Parameter ! */ ! public void removeListDataListener(ListDataListener l) ! { ! this.listeners.remove(l); ! } ! ! ! /** Description of the Method */ ! private void notifyListener() ! { ! ListDataEvent event = new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, 0, this.content.size()); ! for (int i = 0; i < this.listeners.size(); i++) ! { ! ListDataListener listener = (ListDataListener) this.listeners.elementAt(i); ! listener.contentsChanged(event); ! } ! } ! ! ! /** Description of the Method */ ! private void updateModel() ! { ! this.content.clear(); ! Iterator iterator = this.context.iterator(); ! while (iterator.hasNext()) ! { ! this.content.addElement(new ContextElement(iterator.next())); ! } ! } ! } ! ! ! /** ! * Description of the Class ! * ! * @author Administrator ! * @version $Revision$ ! */ ! protected class ContextElement implements BeanContextChildComponentProxy ! { ! /** Description of the Field */ ! protected ImageIcon icon = null; ! /** Description of the Field */ ! protected Object obj; ! /** Description of the Field */ ! protected String txt; ! ! ! /** ! * Constructor for the ContextNode object ! * ! * @param obj1 Description of Parameter ! */ ! public ContextElement(Object obj1) ! { ! obj = obj1; ! try ! { ! BeanInfo beaninfo = Introspector.getBeanInfo(obj1.getClass()); ! if (beaninfo.getIcon(1) != null) ! { ! icon = new ImageIcon(beaninfo.getIcon(1)); ! } ! Method method = obj1.getClass().getMethod("toString", new Class[0]); ! if (method.getDeclaringClass().equals(Object.class)) ! { ! txt = beaninfo.getBeanDescriptor().getDisplayName(); ! } ! } ! catch (Exception exception) ! { ! exception.printStackTrace(); ! } ! } ! ! ! /** ! * Gets the component attribute of the ContextNode object ! * ! * @return The component value ! */ ! public Component getComponent() ! { ! if (obj instanceof Component) ! { ! return (Component) obj; ! } ! if (obj instanceof BeanContextContainerProxy) ! { ! return ((BeanContextContainerProxy) obj).getContainer(); ! } ! if (obj instanceof BeanContextChildComponentProxy) ! { ! return ((BeanContextChildComponentProxy) obj).getComponent(); ! } ! else ! { ! return new JLabel("No GUI available", 0); ! } ! } ! ! ! /** ! * Gets the userObject attribute of the ContextNode object ! * ! * @return The userObject value ! */ ! public Object getUserObject() ! { ! return obj; ! } ! ! ! /** ! * Description of the Method ! * ! * @return Description of the Returned Value ! */ ! public String toString() ! { ! return txt != null ? txt : obj.toString(); ! } ! } ! } ! Index: GenericCustomizer.java =================================================================== RCS file: /cvsroot/ejtools/libraries/adwt/src/main/org/ejtools/adwt/GenericCustomizer.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** GenericCustomizer.java 15 Sep 2003 22:37:12 -0000 1.9 --- GenericCustomizer.java 27 Nov 2003 00:51:44 -0000 1.10 *************** *** 1,664 **** ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.adwt; ! ! import java.awt.Color; ! import java.awt.Component; [...1296 lines suppressed...] ! } ! catch (InvocationTargetException invocationtargetexception) ! { ! invocationtargetexception.getTargetException().printStackTrace(); ! JOptionPane.showMessageDialog(((Component) (obj)), invocationtargetexception.getTargetException().getMessage(), "Error", 0); ! } ! catch (Exception exception) ! { ! System.err.println(exception); ! JOptionPane.showMessageDialog(((Component) (obj)), "An exception occured. Check log for details", "Error", 0); ! } ! } ! else ! { ! new GenericMethodDialog(object, methoddescriptor, (Frame) obj); ! } ! } ! } ! } ! Index: GenericMBeanCustomizer.java =================================================================== RCS file: /cvsroot/ejtools/libraries/adwt/src/main/org/ejtools/adwt/GenericMBeanCustomizer.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** GenericMBeanCustomizer.java 15 Sep 2003 22:37:12 -0000 1.7 --- GenericMBeanCustomizer.java 27 Nov 2003 00:51:44 -0000 1.8 *************** *** 1,888 **** ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.adwt; ! ! import java.awt.Component; ! import java.awt.Container; [...1743 lines suppressed...] ! * ! * @param e Description of the Parameter ! */ ! public void actionPerformed(ActionEvent e) ! { ! Container frame = SwingUtilities.getAncestorOfClass(Frame.class, p); ! ! try ! { ! object.unregisterMBean(); ! } ! catch (Exception ex) ! { ! System.err.println(ex); ! JOptionPane.showMessageDialog(frame, "An exception occured. Check log for details", "Error", JOptionPane.ERROR_MESSAGE); ! } ! } ! } ! } ! Index: GenericMBeanMethodDialog.java =================================================================== RCS file: /cvsroot/ejtools/libraries/adwt/src/main/org/ejtools/adwt/GenericMBeanMethodDialog.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** GenericMBeanMethodDialog.java 15 Sep 2003 22:37:12 -0000 1.7 --- GenericMBeanMethodDialog.java 27 Nov 2003 00:51:44 -0000 1.8 *************** *** 1,298 **** ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.adwt; ! ! import java.awt.Component; ! import java.awt.Dimension; ! import java.awt.Frame; ! import java.awt.GridBagConstraints; ! import java.awt.GridBagLayout; ! import java.awt.Insets; ! import java.awt.event.ActionEvent; ! import java.awt.event.ActionListener; ! import java.beans.PropertyEditor; ! import java.beans.PropertyEditorManager; ! import java.util.Arrays; ! import java.util.Iterator; ! import java.util.Vector; ! ! import javax.management.MBeanOperationInfo; ! import javax.management.MBeanParameterInfo; ! import javax.management.ObjectName; ! import javax.swing.JButton; ! import javax.swing.JDialog; ! import javax.swing.JLabel; ! import javax.swing.JOptionPane; ! import javax.swing.JPanel; ! import javax.swing.SwingConstants; ! ! import org.ejtools.jmx.MBeanAccessor; ! import org.ejtools.util.ClassTools; ! ! import com.dreambean.awt.GenericPropertyCustomizer; ! ! /** ! * Description of the Class ! * ! * @author Laurent Etiemble ! * @version $Revision$ ! */ ! public class GenericMBeanMethodDialog extends JDialog implements ActionListener ! { ! /** Description of the Field */ ! private MBeanAccessor mConnector; ! ! /** Description of the Field */ ! private Vector mEditors = new Vector(); ! /** Description of the Field */ ! private MBeanOperationInfo mOperation; ! /** Description of the Field */ ! private ObjectName mService; ! ! ! /** ! * Create a new dialog. ! * ! * @param pConnector Connector to the remote MBean Server ! * @param pService Remote Service Bean on which the method should be invoked ! * @param pOperation Operation to be invoked if accepted ! * @param pOwner Owner of the dialog controlling its appearance ! */ ! public GenericMBeanMethodDialog(MBeanAccessor pConnector, ObjectName pService, MBeanOperationInfo pOperation, Frame pOwner) ! { ! super(pOwner, true); ! ! // Check the parameters ! if (pConnector == null) ! { ! throw new IllegalArgumentException("MBeanAccessor must be defined"); ! } ! if (pService == null) ! { ! throw new IllegalArgumentException("Service must be defined"); ! } ! if (pOperation == null) ! { ! throw new IllegalArgumentException("Operation must be defined"); ! } ! mConnector = pConnector; ! mService = pService; ! mOperation = pOperation; ! ! JPanel con = (JPanel) getContentPane(); ! con.setLayout(new GridBagLayout()); ! ! try ! { ! GridBagConstraints c = new GridBagConstraints(); ! c.insets = new Insets(3, 3, 3, 3); ! c.anchor = GridBagConstraints.NORTH; ! c.weighty = 1; ! ! // Header ! JLabel lName = new JLabel(mOperation.getName()); ! c.gridwidth = GridBagConstraints.REMAINDER; ! con.add(lName, c); ! ! // Parameters ! Iterator i = Arrays.asList(mOperation.getSignature()).iterator(); ! while (i.hasNext()) ! { ! MBeanParameterInfo lParameter = (MBeanParameterInfo) i.next(); ! Class cl = ClassTools.getClass(lParameter.getType()); ! ! lName = new JLabel(lParameter.getName() + ":", SwingConstants.RIGHT); ! c.gridwidth = GridBagConstraints.RELATIVE; ! c.fill = GridBagConstraints.NONE; ! c.weightx = 0; ! con.add(lName, c); ! ! if (cl != null) ! { ! PropertyEditor lEditor = PropertyEditorManager.findEditor(cl); ! if (lEditor != null) ! { ! // Set initial value ! if (lEditor.getTags() != null) ! { ! // Set to first value ! lEditor.setAsText(lEditor.getTags()[0]); ! } ! ! Component lEditorComp; ! if (lEditor.supportsCustomEditor()) ! { ! lEditorComp = lEditor.getCustomEditor(); ! } ! else ! { ! String[] lTags = lEditor.getTags(); ! if (lTags != null) ! { ! lEditorComp = new GenericPropertyCustomizer(lEditor, lTags); ! } ! else ! { ! lEditorComp = new GenericPropertyCustomizer(lEditor); ! } ! } ! ! c.gridwidth = GridBagConstraints.REMAINDER; ! c.fill = GridBagConstraints.HORIZONTAL; ! c.weightx = 1; ! con.add(lEditorComp, c); ! ! mEditors.addElement(new Editor(lEditor, lParameter.getType())); ! } ! } ! else ! { ! Component lEditorComp; ! lEditorComp = new JLabel("Unsupported class " + lParameter.getType()); ! ! c.gridwidth = GridBagConstraints.REMAINDER; ! c.fill = GridBagConstraints.HORIZONTAL; ! c.weightx = 1; ! con.add(lEditorComp, c); ! } ! c.weighty = 1; ! } ! ! // Button ! c.gridwidth = GridBagConstraints.REMAINDER; ! JPanel p = new JPanel(); ! JButton ok = new JButton("Invoke"); ! p.add(ok); ! ok.addActionListener(this); ! JButton cancel = new JButton("Cancel"); ! p.add(cancel); ! cancel.addActionListener(this); ! con.add(p, c); ! ! pack(); ! if (getWidth() < 300) ! { ! setSize(new Dimension(300, getHeight())); ! } ! setLocationRelativeTo(pOwner); ! setVisible(true); ! } ! catch (Exception e) ! { ! System.out.println("Exception occurred"); ! e.printStackTrace(); ! } ! } ! ! ! // Public -------------------------------------------------------- ! ! // ActionListener implementation --------------------------------- ! /** ! * Ok or Cancel has been pressed. ! * ! * @param e the event ! */ ! public void actionPerformed(ActionEvent e) ! { ! if (e.getActionCommand().equals("Ok")) ! { ! Object[] params = new Object[mEditors.size()]; ! String[] lTypes = new String[mEditors.size()]; ! Iterator i = mEditors.iterator(); ! int j = 0; ! while (i.hasNext()) ! { ! Editor lEditor = (Editor) i.next(); ! params[j] = lEditor.getEditor().getValue(); ! lTypes[j] = lEditor.getType(); ! j++; ! } ! ! try ! { ! Object lReturn = mConnector.invoke( ! mOperation.getName(), ! params, ! lTypes ! ); ! if (lReturn != null) ! { ! JOptionPane.showMessageDialog( ! this, ! lReturn.toString(), ! "Result", ! JOptionPane.INFORMATION_MESSAGE ! ); ! } ! } ! catch (Exception ex) ! { ! System.err.println(ex); ! JOptionPane.showMessageDialog( ! this, ! "An exception occured. Check log for details", ! "Error", ! JOptionPane.ERROR_MESSAGE ! ); ! } ! } ! setVisible(false); ! } ! ! ! /** ! * Description of the Class ! * ! * @author letiembl ! * @version $Revision$ ! * @created 7 f?vrier 2002 ! */ ! private class Editor ! { ! /** Description of the Field */ ! private PropertyEditor mEditor; ! /** Description of the Field */ ! private String mType; ! ! ! /** ! * Constructor for the Editor object ! * ! * @param pEditor Description of Parameter ! * @param pType Description of Parameter ! */ ! public Editor(PropertyEditor pEditor, String pType) ! { ! mEditor = pEditor; ! mType = pType; ! } ! ! ! /** ! * Getter for the editor attribute ! * ! * @return The value of editor attribute ! */ ! public PropertyEditor getEditor() ! { ! return mEditor; ! } ! ! ! /** ! * Getter for the type attribute ! * ! * @return The value of type attribute ! */ ! public String getType() ! { ! return mType; ! } ! } ! } ! --- 1,297 ---- ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.adwt; ! ! import java.awt.Component; ! import java.awt.Dimension; ! import java.awt.Frame; ! import java.awt.GridBagConstraints; ! import java.awt.GridBagLayout; ! import java.awt.Insets; ! import java.awt.event.ActionEvent; ! import java.awt.event.ActionListener; ! import java.beans.PropertyEditor; ! import java.beans.PropertyEditorManager; ! import java.util.Arrays; ! import java.util.Iterator; ! import java.util.Vector; ! ! import javax.management.MBeanOperationInfo; ! import javax.management.MBeanParameterInfo; ! import javax.management.ObjectName; ! import javax.swing.JButton; ! import javax.swing.JDialog; ! import javax.swing.JLabel; ! import javax.swing.JOptionPane; ! import javax.swing.JPanel; ! import javax.swing.SwingConstants; ! ! import org.ejtools.jmx.MBeanAccessor; ! import org.ejtools.util.ClassTools; ! ! import com.dreambean.awt.GenericPropertyCustomizer; ! ! /** ! * Description of the Class ! * ! * @author Laurent Etiemble ! * @version $Revision$ ! */ ! public class GenericMBeanMethodDialog extends JDialog implements ActionListener ! { ! /** Description of the Field */ ! private MBeanAccessor mConnector; ! ! /** Description of the Field */ ! private Vector mEditors = new Vector(); ! /** Description of the Field */ ! private MBeanOperationInfo mOperation; ! /** Description of the Field */ ! private ObjectName mService; ! ! ! /** ! * Create a new dialog. ! * ! * @param pConnector Connector to the remote MBean Server ! * @param pService Remote Service Bean on which the method should be invoked ! * @param pOperation Operation to be invoked if accepted ! * @param pOwner Owner of the dialog controlling its appearance ! */ ! public GenericMBeanMethodDialog(MBeanAccessor pConnector, ObjectName pService, MBeanOperationInfo pOperation, Frame pOwner) ! { ! super(pOwner, true); ! ! // Check the parameters ! if (pConnector == null) ! { ! throw new IllegalArgumentException("MBeanAccessor must be defined"); ! } ! if (pService == null) ! { ! throw new IllegalArgumentException("Service must be defined"); ! } ! if (pOperation == null) ! { ! throw new IllegalArgumentException("Operation must be defined"); ! } ! mConnector = pConnector; ! mService = pService; ! mOperation = pOperation; ! ! JPanel con = (JPanel) getContentPane(); ! con.setLayout(new GridBagLayout()); ! ! try ! { ! GridBagConstraints c = new GridBagConstraints(); ! c.insets = new Insets(3, 3, 3, 3); ! c.anchor = GridBagConstraints.NORTH; ! c.weighty = 1; ! ! // Header ! JLabel lName = new JLabel(mOperation.getName()); ! c.gridwidth = GridBagConstraints.REMAINDER; ! con.add(lName, c); ! ! // Parameters ! Iterator i = Arrays.asList(mOperation.getSignature()).iterator(); ! while (i.hasNext()) ! { ! MBeanParameterInfo lParameter = (MBeanParameterInfo) i.next(); ! Class cl = ClassTools.getClass(lParameter.getType()); ! ! lName = new JLabel(lParameter.getName() + ":", SwingConstants.RIGHT); ! c.gridwidth = GridBagConstraints.RELATIVE; ! c.fill = GridBagConstraints.NONE; ! c.weightx = 0; ! con.add(lName, c); ! ! if (cl != null) ! { ! PropertyEditor lEditor = PropertyEditorManager.findEditor(cl); ! if (lEditor != null) ! { ! // Set initial value ! if (lEditor.getTags() != null) ! { ! // Set to first value ! lEditor.setAsText(lEditor.getTags()[0]); ! } ! ! Component lEditorComp; ! if (lEditor.supportsCustomEditor()) ! { ! lEditorComp = lEditor.getCustomEditor(); ! } ! else ! { ! String[] lTags = lEditor.getTags(); ! if (lTags != null) ! { ! lEditorComp = new GenericPropertyCustomizer(lEditor, lTags); ! } ! else ! { ! lEditorComp = new GenericPropertyCustomizer(lEditor); ! } ! } ! ! c.gridwidth = GridBagConstraints.REMAINDER; ! c.fill = GridBagConstraints.HORIZONTAL; ! c.weightx = 1; ! con.add(lEditorComp, c); ! ! mEditors.addElement(new Editor(lEditor, lParameter.getType())); ! } ! } ! else ! { ! Component lEditorComp; ! lEditorComp = new JLabel("Unsupported class " + lParameter.getType()); ! ! c.gridwidth = GridBagConstraints.REMAINDER; ! c.fill = GridBagConstraints.HORIZONTAL; ! c.weightx = 1; ! con.add(lEditorComp, c); ! } ! c.weighty = 1; ! } ! ! // Button ! c.gridwidth = GridBagConstraints.REMAINDER; ! JPanel p = new JPanel(); ! JButton ok = new JButton("Invoke"); ! p.add(ok); ! ok.addActionListener(this); ! JButton cancel = new JButton("Cancel"); ! p.add(cancel); ! cancel.addActionListener(this); ! con.add(p, c); ! ! pack(); ! if (getWidth() < 300) ! { ! setSize(new Dimension(300, getHeight())); ! } ! setLocationRelativeTo(pOwner); ! setVisible(true); ! } ! catch (Exception e) ! { ! System.out.println("Exception occurred"); ! e.printStackTrace(); ! } ! } ! ! ! // Public -------------------------------------------------------- ! ! // ActionListener implementation --------------------------------- ! /** ! * Ok or Cancel has been pressed. ! * ! * @param e the event ! */ ! public void actionPerformed(ActionEvent e) ! { ! if (e.getActionCommand().equals("Ok")) ! { ! Object[] params = new Object[mEditors.size()]; ! String[] lTypes = new String[mEditors.size()]; ! Iterator i = mEditors.iterator(); ! int j = 0; ! while (i.hasNext()) ! { ! Editor lEditor = (Editor) i.next(); ! params[j] = lEditor.getEditor().getValue(); ! lTypes[j] = lEditor.getType(); ! j++; ! } ! ! try ! { ! Object lReturn = mConnector.invoke( ! mOperation.getName(), ! params, ! lTypes ! ); ! if (lReturn != null) ! { ! JOptionPane.showMessageDialog( ! this, ! lReturn.toString(), ! "Result", ! JOptionPane.INFORMATION_MESSAGE ! ); ! } ! } ! catch (Exception ex) ! { ! System.err.println(ex); ! JOptionPane.showMessageDialog( ! this, ! "An exception occured. Check log for details", ! "Error", ! JOptionPane.ERROR_MESSAGE ! ); ! } ! } ! setVisible(false); ! } ! ! ! /** ! * Description of the Class ! * ! * @author letiembl ! * @version $Revision$ ! */ ! private class Editor ! { ! /** Description of the Field */ ! private PropertyEditor mEditor; ! /** Description of the Field */ ! private String mType; ! ! ! /** ! * Constructor for the Editor object ! * ! * @param pEditor Description of Parameter ! * @param pType Description of Parameter ! */ ! public Editor(PropertyEditor pEditor, String pType) ! { ! mEditor = pEditor; ! mType = pType; ! } ! ! ! /** ! * Getter for the editor attribute ! * ! * @return The value of editor attribute ! */ ! public PropertyEditor getEditor() ! { ! return mEditor; ! } ! ! ! /** ! * Getter for the type attribute ! * ! * @return The value of type attribute ! */ ! public String getType() ! { ! return mType; ! } ! } ! } ! Index: SimpleCustomizer.java =================================================================== RCS file: /cvsroot/ejtools/libraries/adwt/src/main/org/ejtools/adwt/SimpleCustomizer.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** SimpleCustomizer.java 15 Sep 2003 22:37:12 -0000 1.9 --- SimpleCustomizer.java 27 Nov 2003 00:51:44 -0000 1.10 *************** *** 1,620 **** ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.adwt; ! ! import java.awt.Color; ! import java.awt.Component; [...1208 lines suppressed...] ! } ! catch (InvocationTargetException invocationtargetexception) ! { ! invocationtargetexception.getTargetException().printStackTrace(); ! JOptionPane.showMessageDialog(((Component) (obj)), invocationtargetexception.getTargetException().getMessage(), "Error", 0); ! } ! catch (Exception exception) ! { ! System.err.println(exception); ! JOptionPane.showMessageDialog(((Component) (obj)), "An exception occured. Check log for details", "Error", 0); ! } ! } ! else ! { ! new GenericMethodDialog(object, this.methodDescriptor, (Frame) obj); ! } ! } ! } ! } ! |