1 23 24 29 30 package com.sun.enterprise.tools.common.properties; 31 32 import com.sun.enterprise.tools.common.util.diagnostics.Reporter; 33 34 import java.awt.Component ; 35 import java.awt.Graphics ; 36 import java.awt.Rectangle ; 37 38 import javax.swing.JTable ; 39 import javax.swing.table.TableCellEditor ; 40 import javax.swing.JScrollPane ; 41 import javax.swing.JOptionPane ; 42 import java.beans.*; 43 import java.util.*; 44 import java.util.ResourceBundle ; 45 46 48 53 public class PropertyElementsEditor extends PropertyEditorSupport { 54 55 private PropertyElements propElements; 56 private static ResourceBundle bundle = 57 ResourceBundle.getBundle("com.sun.enterprise.tools.common.properties.Bundle"); private JTable table = null; 59 60 61 public PropertyElementsEditor() { 62 } 63 64 66 public String getAsText() { 67 return null; 68 } 69 70 73 public boolean isPaintable() { 74 return true; 75 } 76 77 78 public Component getCustomEditor() { 79 table = new JTable (new PropertyElementsTableModel(propElements)); 82 table.setDefaultEditor(Object .class, acell); 83 if (table.getModel().getRowCount() > 0) 84 table.editCellAt(0,0); 85 JScrollPane sp = new JScrollPane (table); 87 return sp; 88 } 89 90 public Object getValue() { 91 return new PropertyElements((PropertyElements) propElements); } 94 95 public void paintValue(Graphics gfx, Rectangle box) { 96 int num = propElements.getLength(); 99 String s = "" + num + " "; 101 String format = null; 102 if(num == 1) 103 format = bundle.getString("PROP_TEXT_ONE_PROPERTY"); else 105 format = bundle.getString("PROP_TEXT_N_PROPERTIES"); 107 s = java.text.MessageFormat.format(format, new Object [] { s }); 108 109 java.awt.FontMetrics fm = gfx.getFontMetrics(); 110 111 gfx.drawString(s, 4, (box.height - fm.getHeight()) / 2 + 1 + fm.getMaxAscent()); 112 } 113 114 public void setAsText(String text) throws IllegalArgumentException { 115 throw new IllegalArgumentException (bundle.getString("ERR_SET_AS_TEXT_ILLEGAL")); } 117 118 public List isValueValid(PropertyElements value) { 119 String propName = null; 120 String propValue = null; 121 Vector errors = new Vector(); 122 HashSet propNames = new HashSet(); 123 try { 124 for (int row = 0; row < value.getLength(); row++) { 125 if ((propName = (String )value.getAttributeDetail(row, 0)) == null || propName.trim().length() == 0 || (propValue = (String )value.getAttributeDetail(row, 1)) == null || propValue.trim().length() == 0) { String format = bundle.getString("ERR_InvalidEntry"); errors.add(java.text.MessageFormat.format(format, new Object [] { new Integer (row + 1) })); 129 } 130 else if (propNames.contains(propName)) { 131 String format = bundle.getString("ERR_DuplicateProperty"); errors.add(java.text.MessageFormat.format(format, new Object [] { propName, new Integer (row + 1) })); 133 } 134 else 135 propNames.add(propName); 136 } 137 } catch (Exception ex) { 138 errors.add(ex.getLocalizedMessage()); 139 } 140 Reporter.info(new Integer (errors.size())); return errors; 142 } 143 144 public void setValue(Object value) { 145 List errors = null; 147 if (table != null) { 148 Reporter.info("table"); TableCellEditor cell = table.getCellEditor(); 150 if (null != cell) { 151 Reporter.info("There is a cell: " + cell); Reporter.info(" this is the value of the cell: " + cell.getCellEditorValue()); int r = table.getEditingRow(); 154 int c = table.getEditingColumn(); 155 if (r > -1 && c > -1) { 156 table.setValueAt(cell.getCellEditorValue(), r, c); 157 } 158 } 159 if (value instanceof PropertyElements) { 160 errors = isValueValid((PropertyElements) value); 161 if (!errors.isEmpty()) { 162 StringBuffer str = new StringBuffer (bundle.getString("ERR_Properties")); Iterator iter = errors.iterator(); 164 while (iter.hasNext()) { 165 str.append("\n\t -" + (String )iter.next()); } 167 JOptionPane.showMessageDialog(null, str.toString(), bundle.getString ("Error"), JOptionPane.ERROR_MESSAGE); } 169 } 170 } 171 if (value instanceof PropertyElements) { 172 if (errors == null || errors.isEmpty()) { 173 Reporter.info(""); propElements = (PropertyElements) value; } 176 } 177 } 179 180 public boolean supportsCustomEditor() { 181 return true; 182 } 183 184 186 TableCellEditor acell = new javax.swing.DefaultCellEditor (new javax.swing.JTextField ()); 187 188 } 189 | Popular Tags |