1 19 package org.netbeans.modules.xml.tools.generator; 20 21 import java.awt.*; 22 import java.util.*; 23 import java.beans.*; 24 25 import org.openide.util.*; 28 29 import javax.swing.*; 30 import javax.swing.table.*; 31 import java.net.URL ; 32 import java.net.MalformedURLException ; 33 34 42 public final class SAXGeneratorParsletPanel extends SAXGeneratorAbstractPanel { 43 44 45 private static final long serialVersionUID =6038099487791703339L; 46 47 48 private TableModel tableModel; 50 private static final int ELEMENT_COLUMN = 0; 51 private static final int METHOD_COLUMN = 1; private static final int TYPE_COLUMN = 2; 53 private static final int COLUMNS = 3; 54 55 private static final String NO_METHOD = "[none]"; 57 private final String [] COLUMN_NAMES = new String [] { 58 Util.THIS.getString ("SAXGeneratorParsletPanel.table.column1"), 59 Util.THIS.getString ("SAXGeneratorParsletPanel.table.column2"), 60 Util.THIS.getString ("SAXGeneratorParsletPanel.table.column3"), 61 }; 62 63 private final ValidatingTextField.Validator TYPE_VALIDATOR = new ValidatingTextField.Validator() { 64 public boolean isValid(String value) { 65 boolean ret = GenerateSupportUtils.isValidReturnType(value); 66 setValid(ret); 67 return ret; 68 } 69 70 public String getReason() { 71 return Util.THIS.getString("MSG_parslet_err_1"); 72 } 73 }; 74 75 private final ValidatingTextField.Validator METHOD_VALIDATOR = new ValidatingTextField.Validator() { 76 public boolean isValid(String value) { 77 boolean ret = NO_METHOD.equals(value) || Utilities.isJavaIdentifier(value); 78 setValid(ret); 79 return ret; 80 } 81 82 public String getReason() { 83 return Util.THIS.getString("MSG_parslet_err_2"); 84 } 85 86 }; 87 88 89 public SAXGeneratorParsletPanel() { 90 } 95 96 101 private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; 103 104 descTextArea = new javax.swing.JTextArea (); 105 tableScrollPane = new javax.swing.JScrollPane (); 106 table = new javax.swing.JTable (); 107 108 setLayout(new java.awt.GridBagLayout ()); 109 110 setPreferredSize(new java.awt.Dimension (480, 350)); 111 setName(Util.THIS.getString ("SAXGeneratorParsletPanel.Form.name")); 112 descTextArea.setWrapStyleWord(true); 113 descTextArea.setLineWrap(true); 114 descTextArea.setEditable(false); 115 descTextArea.setForeground(new java.awt.Color (102, 102, 153)); 116 descTextArea.setFont(javax.swing.UIManager.getFont ("Label.font")); 117 descTextArea.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/xml/tools/generator/Bundle").getString("DESC_saxw_convertors")); 118 descTextArea.setDisabledTextColor(javax.swing.UIManager.getColor ("Label.foreground")); 119 descTextArea.setEnabled(false); 120 descTextArea.setOpaque(false); 121 gridBagConstraints = new java.awt.GridBagConstraints (); 122 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 123 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 124 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 125 gridBagConstraints.weightx = 1.0; 126 add(descTextArea, gridBagConstraints); 127 128 table.setModel(tableModel); 129 tableScrollPane.setViewportView(table); 130 131 gridBagConstraints = new java.awt.GridBagConstraints (); 132 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 133 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 134 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 135 gridBagConstraints.weightx = 1.0; 136 gridBagConstraints.weighty = 1.0; 137 gridBagConstraints.insets = new java.awt.Insets (12, 0, 0, 0); 138 add(tableScrollPane, gridBagConstraints); 139 140 } 142 143 146 private void initModels() { 147 148 150 tableModel = new ParsletsTableModel(); 151 } 152 153 154 157 protected void initView() { 158 initModels(); 159 initComponents (); 160 161 table = new ParsletsTable(); 162 table.setModel(tableModel); 163 tableScrollPane.setViewportView(table); 165 initAccessibility(); 166 } 167 168 protected void updateView() { 169 } 170 171 175 protected void updateModel() { 176 } 180 181 182 184 187 private class ParsletsTable extends JTable { 188 189 190 private static final long serialVersionUID =1076091649418718319L; 191 192 public ParsletsTable() { 193 getTableHeader().setReorderingAllowed(false); 194 setRowHeight(Util.getTextCellHeight(this)); 195 } 196 197 public TableCellEditor getCellEditor(int row, int column) { 198 199 switch (column) { 200 201 case METHOD_COLUMN: 202 Vector all = new Vector(model.getParsletBindings().keySet()); 203 JComboBox editor = new JComboBox(all); 204 editor.addItem(NO_METHOD); 205 ValidatingTextField methodInput = new ValidatingTextField(); 206 methodInput.setValidator(METHOD_VALIDATOR); 207 editor.setEditor(methodInput); 208 editor.setEditable(true); 209 return new DefaultCellEditor(editor); 210 211 case TYPE_COLUMN: 212 String [] vals = { 213 "int", "boolean","long", "java.util.Date", "java.net.URL", "java.lang.String", "java.lang.String[]" }; 216 JComboBox type_editor = new JComboBox(vals); 217 ValidatingTextField typeInput = new ValidatingTextField(); 218 typeInput.setValidator(TYPE_VALIDATOR); 219 type_editor.setEditor(typeInput); 220 type_editor.setEditable(true); 221 return new DefaultCellEditor(type_editor); 222 223 224 default: 225 return super.getCellEditor(row, column); 226 } 227 } 228 229 } 230 231 234 private class ParsletsTableModel extends AbstractTableModel { 235 236 237 private static final long serialVersionUID =3516749023312029787L; 238 239 public String getColumnName(int col) { 240 return COLUMN_NAMES[col]; 241 } 242 243 public int getRowCount() { 244 if (model == null) return 0; 245 return model.getElementBindings().size(); 246 } 247 248 public int getColumnCount() { 249 return COLUMNS; 250 } 251 252 253 256 public Object getValueAt(int row, int column) { 257 ElementBindings.Entry entry = model.getElementBindings().getEntry(row); 258 ParsletBindings parslets = model.getParsletBindings(); 259 260 String parslet = entry.getParslet(); 262 263 switch (column) { 264 265 case ELEMENT_COLUMN: 266 return entry.getElement(); 267 268 case TYPE_COLUMN: 269 if (parslet == null) { 270 return String .class.getName(); 271 } else { 272 } 275 276 case METHOD_COLUMN: 277 if (parslet == null) { 278 return NO_METHOD; 279 } else { 280 return parslet; 281 } 282 } 283 return null; 284 } 285 286 289 public void setValueAt(Object value, int row, int col) { 290 291 293 352 } 353 354 public boolean isCellEditable(int row, int col) { 355 return col != ELEMENT_COLUMN; 356 } 357 }; 359 360 private javax.swing.JTable table; 362 private javax.swing.JTextArea descTextArea; 363 private javax.swing.JScrollPane tableScrollPane; 364 366 368 public void initAccessibility(){ 369 370 this.getAccessibleContext().setAccessibleDescription(Util.THIS.getString("ACSD_SAXGeneratorParsletPanel")); 371 table.getAccessibleContext().setAccessibleDescription(Util.THIS.getString("ACSD_ParsletsTable")); 372 table.getAccessibleContext().setAccessibleName(Util.THIS.getString("ACSN_ParsletsTable")); 373 } 374 } 375 | Popular Tags |