Clover coverage report - AdWT - 1.0.0
Coverage timestamp: sam. déc. 27 2003 15:14:10 CET
file stats: LOC: 140   Methods: 6
NCLOC: 91   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ArrayEditor.java 0% 0% 0% 0%
coverage
 1   
 /*
 2   
  * EJTools, the Enterprise Java Tools
 3   
  *
 4   
  * Distributable under LGPL license.
 5   
  * See terms of license at www.gnu.org.
 6   
  */
 7   
 package org.ejtools.adwt.editor;
 8   
 
 9   
 import java.awt.Component;
 10   
 import java.awt.GridLayout;
 11   
 import java.beans.PropertyChangeEvent;
 12   
 import java.beans.PropertyChangeListener;
 13   
 import java.beans.PropertyEditor;
 14   
 
 15   
 import javax.swing.JLabel;
 16   
 import javax.swing.JPanel;
 17   
 
 18   
 import org.ejtools.beans.CustomPropertyEditorManager;
 19   
 
 20   
 import com.dreambean.awt.GenericPropertyCustomizer;
 21   
 
 22   
 /**
 23   
  * @author    Laurent Etiemble
 24   
  * @version   $Revision: 1.7 $
 25   
  */
 26   
 public class ArrayEditor extends GenericEditor
 27   
 {
 28   
    /** Description of the Field */
 29   
    protected Object[] array = new Object[0];
 30   
    /** Description of the Field */
 31   
    protected Class clazz = null;
 32   
    /** Description of the Field */
 33   
    protected JPanel panel = null;
 34   
 
 35   
 
 36   
    /**
 37   
     * Constructor for ArrayEditor.
 38   
     *
 39   
     * @param clazz  Description of the Parameter
 40   
     */
 41  0
    public ArrayEditor(Class clazz)
 42   
    {
 43  0
       this.clazz = clazz;
 44  0
       this.panel = new JPanel();
 45   
    }
 46   
 
 47   
 
 48   
    /**
 49   
     * @return   The customEditor value
 50   
     */
 51  0
    public Component getCustomEditor()
 52   
    {
 53  0
       return this.panel;
 54   
    }
 55   
 
 56   
 
 57   
    /**
 58   
     * @param value  The new value value
 59   
     */
 60  0
    public void setValue(Object value)
 61   
    {
 62  0
       super.setValue(value);
 63  0
       if (this.value == null)
 64   
       {
 65  0
          return;
 66   
       }
 67  0
       this.array = (Object[]) this.value;
 68  0
       this.buildPanel();
 69   
    }
 70   
 
 71   
 
 72   
    /**
 73   
     * @return   Description of the Return Value
 74   
     */
 75  0
    public boolean supportsCustomEditor()
 76   
    {
 77  0
       return true;
 78   
    }
 79   
 
 80   
 
 81   
    /** Description of the Method */
 82  0
    private void buildPanel()
 83   
    {
 84  0
       this.panel.removeAll();
 85   
 
 86  0
       PropertyEditor editor = CustomPropertyEditorManager.findEditor(this.clazz);
 87  0
       if (editor == null)
 88   
       {
 89  0
          editor = CustomPropertyEditorManager.findEditor(String.class);
 90   
       }
 91   
 
 92  0
       this.panel = new JPanel(new GridLayout(this.array.length, 1));
 93  0
       for (int i = 0; i < this.array.length; i++)
 94   
       {
 95  0
          try
 96   
          {
 97  0
             PropertyEditor peInstance = (PropertyEditor) editor.getClass().newInstance();
 98  0
             peInstance.setValue(array[i]);
 99   
 
 100  0
             Object component;
 101   
 
 102  0
             if (peInstance.supportsCustomEditor())
 103   
             {
 104  0
                component = peInstance.getCustomEditor();
 105   
             }
 106   
             else
 107   
             {
 108  0
                String as[] = peInstance.getTags();
 109  0
                if (as != null)
 110   
                {
 111  0
                   component = new GenericPropertyCustomizer(peInstance, as);
 112   
                }
 113   
                else
 114   
                {
 115  0
                   final JLabel label = new JLabel(peInstance.getAsText());
 116  0
                   final PropertyEditor pcEditor = peInstance;
 117  0
                   component = label;
 118  0
                   pcEditor.addPropertyChangeListener(
 119   
                      new PropertyChangeListener()
 120   
                      {
 121  0
                         public void propertyChange(PropertyChangeEvent evt)
 122   
                         {
 123  0
                            label.setText(pcEditor.getAsText());
 124   
                         }
 125   
                      });
 126   
                }
 127   
             }
 128  0
             this.panel.add((Component) component);
 129   
          }
 130   
          catch (Exception exception)
 131   
          {
 132  0
             exception.printStackTrace();
 133   
          }
 134   
       }
 135   
 
 136  0
       this.panel.validate();
 137  0
       this.panel.repaint();
 138   
    }
 139   
 }
 140