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.*; 39 import javax.swing.event.*; 40 import javax.swing.table.*; 41 import java.awt.*; 42 import java.awt.event.*; 43 import java.beans.*; 44 import java.util.*; 45 46 51 public class PrincipalsEditor implements TableCellEditor { 52 53 private Vector model; 54 private transient Vector listeners; 55 private transient Vector originalValue; 56 private JTable principalsTable; 57 private JButton button; 58 private JDialog d; 59 private JFrame frame; 60 61 private static java.util.ResourceBundle bundle = 62 java.util.ResourceBundle.getBundle("com.sun.enterprise.tools.common.properties.Bundle"); static final java.util.ResourceBundle helpBundle = java.util.ResourceBundle.getBundle("com.sun.enterprise.tools.common.HelpIDBundle"); 65 public PrincipalsEditor(JFrame f) { 66 listeners = new Vector(); 67 this.frame = f; 68 69 button = new JButton(); 71 button.setBackground(Color.white); 72 button.setBorderPainted(false); 73 button.setMargin(new Insets(0,0,0,0)); 74 button.addActionListener(new ActionListener() { 77 public void actionPerformed(ActionEvent e) { 78 if (d == null) 79 createDialog(); 80 d.setVisible(true); 81 } 82 }); 83 } 84 85 public Component getTableCellEditorComponent(JTable table, Object value, 86 boolean isSelected, 87 int row, int column) { 88 if (value == null) 89 model = new Vector(); 90 else if (value instanceof String && ((String )value).length() == 0) 91 model = new Vector(); 92 else if (value instanceof Vector) 93 model = (Vector)value; 94 else 95 Reporter.error(value); 96 if (principalsTable == null) 97 createDialog(); 98 principalsTable.setModel(new PrincipalTableModel(model)); 99 originalValue = model; 100 101 table.setRowSelectionInterval(row, row); 102 table.setColumnSelectionInterval(column, column); 103 return button; 105 } 106 107 public void createDialog() { 108 JPanel pane = new JPanel(); 109 principalsTable = new JTable(); 110 JScrollPane sp = new JScrollPane(principalsTable); 111 d = new JDialog(this.frame, bundle.getString("PRIN_TITLE"), true); d.setSize(500, 300); 113 d.getContentPane().setLayout(new BorderLayout()); 114 pane.setLayout(new BorderLayout()); 115 pane.add(sp, BorderLayout.CENTER); 117 JButton okButton = new JButton(bundle.getString("OK_BUTTON_LABEL")); JButton cancelButton = new JButton(bundle.getString("CANCEL_BUTTON_LABEL")); okButton.addActionListener(new ActionListener() { 120 public void actionPerformed(ActionEvent ev) { 121 stopCellEditing(); 122 d.setVisible(false); 123 d.dispose(); 124 } 125 }); 126 cancelButton.addActionListener(new ActionListener() { 127 public void actionPerformed(ActionEvent ev) { 128 cancelCellEditing(); 129 d.setVisible(false); 130 d.dispose(); 131 } 132 }); 133 JPanel buttonsPane = new JPanel(); 134 buttonsPane.add(okButton); 135 buttonsPane.add(cancelButton); 136 org.openide.util.HelpCtx.setHelpIDString(pane, helpBundle.getString("role_map_principal_editor")); pane.add(buttonsPane, BorderLayout.SOUTH); 139 d.getContentPane().add(pane, BorderLayout.CENTER); 140 } 142 143 public void addCellEditorListener(javax.swing.event.CellEditorListener cellEditorListener) { 144 listeners.addElement(cellEditorListener); 145 } 146 147 public void cancelCellEditing() { 148 fireEditingCanceled(); 149 } 150 151 public Object getCellEditorValue() { 152 return model; 153 } 154 155 public boolean isCellEditable(java.util.EventObject eventObject) { 156 return true; 157 } 158 159 public void removeCellEditorListener(javax.swing.event.CellEditorListener cellEditorListener) { 160 listeners.removeElement(cellEditorListener); 161 } 162 163 public boolean shouldSelectCell(java.util.EventObject eventObject) { 164 return true; 165 } 166 167 public boolean stopCellEditing() { 168 if (principalsTable != null) { 169 TableCellEditor cell = principalsTable.getCellEditor(); 170 if (cell != null) 171 cell.stopCellEditing(); 172 } 173 174 model = ((PrincipalTableModel)principalsTable.getModel()).getPrincipals(); 175 fireEditingStopped(); 176 return true; 177 } 178 179 private void fireEditingCanceled() { 180 ChangeEvent ce = new ChangeEvent(this); 181 for (int i = listeners.size() - 1; i >= 0; i--) { 182 ((CellEditorListener)listeners.elementAt(i)).editingCanceled(ce); 183 } 184 } 185 186 private void fireEditingStopped() { 187 ChangeEvent ce = new ChangeEvent(this); 188 for (int i = listeners.size() - 1; i >= 0; i--) { 189 ((CellEditorListener)listeners.elementAt(i)).editingStopped(ce); 190 } 191 } 192 } 193 | Popular Tags |