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

PrincipalTableModel

public class PrincipalTableModel extends AbstractTableModel
author
shirleyc

Fields Summary
Vector
principals
private static ResourceBundle
bundle
Constructors Summary
public PrincipalTableModel(Vector values)
Creates new RoleMapElementTableModel

 //NOI18N
    
        
       
        if (values == null)
            this.principals = new Vector();
        else
            this.principals = (Vector)values.clone();
    
Methods Summary
public intgetColumnCount()

        return 2;
    
public java.lang.StringgetColumnName(int col)

        if (0 == col) 
            return bundle.getString("COL_HEADER_PRINCIPAL");    //NOI18N
        if (1 == col)
            return bundle.getString("COL_HEADER_DESCRIPTION");   //NOI18N

        throw new RuntimeException(bundle.getString("COL_HEADER_ERR_ERR_ERR"));  //NOI18N
    
public java.util.VectorgetPrincipals()

        return principals;
    
public intgetRowCount()

        return principals.size() + 1;
    
public java.lang.ObjectgetValueAt(int row, int column)

        if (row < principals.size())
            return ((String[])principals.elementAt(row))[column];
        else
            return "";    //NOI18N
    
public booleanisCellEditable(int row, int col)

        return true;
    
public static voidmain(java.lang.String[] args)

        String[] principal = {"user-name", "description"};  //NOI18N
        Vector principals = new Vector();
        principals.add(principal);
        javax.swing.JTable table = new javax.swing.JTable(new PrincipalTableModel(principals));
        javax.swing.JScrollPane sp = new javax.swing.JScrollPane(table);
/*        
        javax.swing.JFrame f = new javax.swing.JFrame();
        f.addWindowListener(new CloseTestWindow(principals));
        f.getContentPane().add(sp);
        f.show();
 */
        final JDialog d = new JDialog();
        d.setSize(200, 150);
        d.getContentPane().setLayout(new BorderLayout());
        d.getContentPane().add(sp, BorderLayout.CENTER);
        JButton okButton = new JButton("OK");  //NOI18N
        okButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ev) {
                d.setVisible(false);
                d.dispose();
            }
        });
        JPanel buttonsPane = new JPanel();
        buttonsPane.add(okButton);
        d.getContentPane().add(buttonsPane, BorderLayout.SOUTH);
        d.setVisible(true);
    
public voidsetValueAt(java.lang.Object val, int row, int col)

//        System.out.println("val = " + (String)val + ", row = " + new Integer(row) + ", col = " + new Integer(col));
        
        int pre = principals.size();
        if (row >= pre) {
            String[] newPrincipal = new String[2];
            principals.add(newPrincipal);
        }
             
        if (!(val instanceof String)) {
            throw new IllegalArgumentException();
        } 
        String input = (String)val;
        if (col == 0 && (input == null || input.trim().length() == 0)) {
            Reporter.info("row has no value (" + input + ")");    //NOI18N
            principals.removeElementAt(row);
        } else {
            Reporter.info("(" + input.trim() + ")");   //NOI18N
            ((String[])principals.elementAt(row))[col] = input.trim();
        } 
        
        if (principals.size() < pre) {
//            System.out.println("fireTableStructureChanged");
            fireTableStructureChanged();
        }