1 23 24 29 30 package com.sun.enterprise.tools.common.properties; 31 32 import java.util.*; 33 import javax.swing.*; 34 import java.awt.*; 35 import java.awt.event.*; 36 import com.sun.enterprise.tools.common.util.diagnostics.Reporter; 37 38 41 public class PrincipalTableModel extends javax.swing.table.AbstractTableModel { 42 43 Vector principals = null; 44 45 private static java.util.ResourceBundle bundle = 46 java.util.ResourceBundle.getBundle("com.sun.enterprise.tools.common.properties.Bundle"); 48 49 public PrincipalTableModel(Vector values) { 50 if (values == null) 51 this.principals = new Vector(); 52 else 53 this.principals = (Vector)values.clone(); 54 } 55 56 public java.lang.Object getValueAt(int row, int column) { 57 if (row < principals.size()) 58 return ((String [])principals.elementAt(row))[column]; 59 else 60 return ""; } 62 63 public int getRowCount() { 64 return principals.size() + 1; 65 } 66 67 public int getColumnCount() { 68 return 2; 69 } 70 71 public Vector getPrincipals() { 72 return principals; 73 } 74 75 public boolean isCellEditable(int row, int col) { 76 return true; 77 } 78 79 public void setValueAt(Object val, int row, int col) { 80 82 int pre = principals.size(); 83 if (row >= pre) { 84 String [] newPrincipal = new String [2]; 85 principals.add(newPrincipal); 86 } 87 88 if (!(val instanceof String )) { 89 throw new IllegalArgumentException (); 90 } 91 String input = (String )val; 92 if (col == 0 && (input == null || input.trim().length() == 0)) { 93 Reporter.info("row has no value (" + input + ")"); principals.removeElementAt(row); 95 } else { 96 Reporter.info("(" + input.trim() + ")"); ((String [])principals.elementAt(row))[col] = input.trim(); 98 } 99 100 if (principals.size() < pre) { 101 fireTableStructureChanged(); 103 } 104 } 105 106 public String getColumnName(int col) { 107 if (0 == col) 108 return bundle.getString("COL_HEADER_PRINCIPAL"); if (1 == col) 110 return bundle.getString("COL_HEADER_DESCRIPTION"); 112 throw new RuntimeException (bundle.getString("COL_HEADER_ERR_ERR_ERR")); } 114 115 public static void main(String args[]) { 116 String [] principal = {"user-name", "description"}; Vector principals = new Vector(); 118 principals.add(principal); 119 javax.swing.JTable table = new javax.swing.JTable (new PrincipalTableModel(principals)); 120 javax.swing.JScrollPane sp = new javax.swing.JScrollPane (table); 121 127 final JDialog d = new JDialog(); 128 d.setSize(200, 150); 129 d.getContentPane().setLayout(new BorderLayout()); 130 d.getContentPane().add(sp, BorderLayout.CENTER); 131 JButton okButton = new JButton("OK"); okButton.addActionListener(new ActionListener() { 133 public void actionPerformed(ActionEvent ev) { 134 d.setVisible(false); 135 d.dispose(); 136 } 137 }); 138 JPanel buttonsPane = new JPanel(); 139 buttonsPane.add(okButton); 140 d.getContentPane().add(buttonsPane, BorderLayout.SOUTH); 141 d.setVisible(true); 142 } 143 144 static class CloseTestWindow extends java.awt.event.WindowAdapter { 145 146 private Vector principals = null; 147 148 public CloseTestWindow(Vector vec) { 149 principals = vec; 150 } 151 152 public void windowClosing(java.awt.event.WindowEvent e) { 153 System.exit(0); 154 } 155 } 156 157 } 158 | Popular Tags |