FileDocCategorySizeDatePackage
PropertyElementsEditor.javaAPI DocGlassfish v2 API8119Fri May 04 22:34:56 BST 2007com.sun.enterprise.tools.common.properties

PropertyElementsEditor

public class PropertyElementsEditor extends PropertyEditorSupport
author
vkraemer
version

Fields Summary
private PropertyElements
propElements
private static ResourceBundle
bundle
private JTable
table
TableCellEditor
acell
Constructors Summary
public PropertyElementsEditor()
Creates new PropertyElementsEditor


        
      
    
Methods Summary
public java.lang.StringgetAsText()
The String is not editable in the sheet.

        return null;
    
public java.awt.ComponentgetCustomEditor()
return the UI components to edit this object

        //System.out.println("PropElEd.getCustomEditor(" + propElements.toString() +") " + //NOI18N
        //propElements.hashCode());
        table = new JTable(new PropertyElementsTableModel(propElements));
        table.setDefaultEditor(Object.class, acell);
        if (table.getModel().getRowCount() > 0)
            table.editCellAt(0,0);
        //JTable tab = new JTable(propElements);
        JScrollPane sp = new JScrollPane(table);
        return sp;
    
public java.lang.ObjectgetValue()

//        Reporter.info(propElements.toString() + ",   " + propElements.hashCode());  //NOI18N
        return new PropertyElements((PropertyElements) propElements);//*/ propElements;
    
public booleanisPaintable()
Does this editor use painting to illuminate the property state in the property sheet

        return true;
    
public java.util.ListisValueValid(PropertyElements value)

        String propName = null;
        String propValue = null;
        Vector errors = new Vector();
        HashSet propNames = new HashSet();
        try {
            for (int row = 0; row < value.getLength(); row++) {
                if ((propName = (String)value.getAttributeDetail(row, 0)) == null || propName.trim().length() == 0 || //NOI18N
                   (propValue = (String)value.getAttributeDetail(row, 1)) == null || propValue.trim().length() == 0) { //NOI18N
                    String format = bundle.getString("ERR_InvalidEntry");  //NOI18N
                    errors.add(java.text.MessageFormat.format(format, new Object[] { new Integer(row + 1) }));
                }
                else if (propNames.contains(propName)) {
                    String format = bundle.getString("ERR_DuplicateProperty");  //NOI18N
                    errors.add(java.text.MessageFormat.format(format, new Object[] { propName, new Integer(row + 1) }));
                }
                else 
                    propNames.add(propName);
            }
        } catch (Exception ex) {
            errors.add(ex.getLocalizedMessage());
        }
        Reporter.info(new Integer(errors.size())); //NOI18N
        return errors;
    
public voidpaintValue(java.awt.Graphics gfx, java.awt.Rectangle box)

        //System.out.println("PropElEd.paintValue(" + propElements.toString() +") " + //NOI18N
        //propElements.hashCode());
        int num = propElements.getLength();
        String s = "" + num + " "; // NOI18N
        
        String format = null;
        if(num == 1)
            format = bundle.getString("PROP_TEXT_ONE_PROPERTY");//NOI18N
        else
            format = bundle.getString("PROP_TEXT_N_PROPERTIES");//NOI18N

        s = java.text.MessageFormat.format(format, new Object[]  { s });
        
        java.awt.FontMetrics fm = gfx.getFontMetrics();
        
        gfx.drawString(s, 4, (box.height - fm.getHeight()) / 2 + 1 + fm.getMaxAscent());
    
public voidsetAsText(java.lang.String text)

        throw new IllegalArgumentException(bundle.getString("ERR_SET_AS_TEXT_ILLEGAL"));//NOI18N
    
public voidsetValue(java.lang.Object value)

//      Reporter.info(value.toString() + ",  " + value.hashCode());  //NOI18N
        List errors = null;
        if (table != null) {
            Reporter.info("table");  //NOI18N
            TableCellEditor cell = table.getCellEditor();
            if (null != cell) {
                Reporter.info("There is a cell: " + cell);//NOI18N
                Reporter.info("  this is the value of the cell: " + cell.getCellEditorValue());//NOI18N
                int r = table.getEditingRow();
                int c = table.getEditingColumn();
                if (r > -1 && c > -1) {
                    table.setValueAt(cell.getCellEditorValue(), r, c);
                }
            } 
            if (value instanceof PropertyElements) {
                errors = isValueValid((PropertyElements) value);
                if (!errors.isEmpty()) {
                    StringBuffer str = new StringBuffer(bundle.getString("ERR_Properties"));  //NOI18N
                    Iterator iter = errors.iterator();
                    while (iter.hasNext()) {
                        str.append("\n\t -" + (String)iter.next()); // NOI18N
                    }
                    JOptionPane.showMessageDialog(null, str.toString(), bundle.getString ("Error"), JOptionPane.ERROR_MESSAGE);//NOI18N 
                }
            }
        }
        if (value instanceof PropertyElements) {
            if (errors == null || errors.isEmpty()) {
                Reporter.info("");  //NOI18N
                propElements = (PropertyElements) value; //*/ new PropertyElements((PropertyElements) value);
            }
        }
        //firePropertyChange();
    
public booleansupportsCustomEditor()

        return true;