1 23 24 29 30 package com.sun.enterprise.tools.common.properties; 31 32 import java.awt.Component ; 33 import java.awt.Graphics ; 34 import java.awt.Rectangle ; 35 36 import javax.swing.JTable ; 37 import javax.swing.JScrollPane ; 38 import javax.swing.table.TableCellEditor ; 39 import java.beans.*; 40 import javax.swing.*; 41 import java.awt.*; 42 43 import java.util.ResourceBundle ; 44 import com.sun.enterprise.tools.common.util.diagnostics.Reporter; 45 50 public class RoleMapElementEditor extends PropertyEditorSupport { 51 52 private RoleMapElement roleMap; 53 private JTable table = null; 54 private JTextField desc = null; 55 private static ResourceBundle bundle = 56 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"); 59 60 public RoleMapElementEditor() { 61 } 62 63 65 public String getAsText() { 66 return null; 67 } 68 69 72 public boolean isPaintable() { 73 return true; 74 } 75 76 77 public Component getCustomEditor() { 78 table = new JTable (new RoleMapElementTableModel(roleMap)); 79 table.setDefaultEditor(Object .class, c023cell); 80 if (table.getModel().getRowCount() > 0) 81 table.editCellAt(0,0); 82 javax.swing.table.TableColumnModel tcm = table.getColumnModel(); 83 javax.swing.table.TableColumn tc = tcm.getColumn(1); 87 PasswordRender pre2 = new PasswordRender(); 89 tc.setCellEditor(c1cell); 90 tc.setCellRenderer(pre2); 91 92 javax.swing.table.TableColumn principalColumn = tcm.getColumn(3); 94 principalColumn.setCellEditor(new PrincipalsEditor(null)); 95 principalColumn.setCellRenderer(new PrincipalsRenderer()); 96 JScrollPane sp = new JScrollPane (table); 97 98 JPanel pane = new JPanel(); 99 GridBagLayout gridbag = new GridBagLayout(); 100 pane.setLayout(gridbag); 101 GridBagConstraints c = new GridBagConstraints(); 102 c.weightx = 0.5; 103 c.weighty = 0.5; 104 c.gridx = 0; 105 c.gridy = 0; 106 c.gridwidth = 1; 107 c.gridheight = 1; 108 c.insets = new Insets(5, 5, 5, 5); 109 c.fill = GridBagConstraints.BOTH; 110 pane.add(sp, c); 111 112 c.weightx = 0.5; 113 c.weighty = 0.5; 114 c.gridx = 0; 115 c.gridy = 1; 116 c.gridwidth = 1; 117 c.gridheight = 1; 118 c.insets = new Insets(5, 5, 5, 5); 119 c.fill = GridBagConstraints.BOTH; 120 JLabel descLabel = new JLabel(bundle.getString("LBL_DESCRIPTION")); 132 desc = new JTextField(68); 133 desc.setText(roleMap.getRoleMapDescription()); 134 JPanel descPane = new JPanel(); 135 descLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); 136 descPane.add(descLabel); 137 descPane.add(desc); 138 pane.add(descPane, c); 139 org.openide.util.HelpCtx.setHelpIDString(pane, helpBundle.getString("role_map_editor")); return pane; 141 } 142 143 public Object getValue() { 144 if (roleMap != null && desc != null) 145 roleMap.setRoleMapDescription(desc.getText()); 146 return new RoleMapElement(roleMap); 147 } 148 149 public void paintValue(Graphics gfx, Rectangle box) { 150 int num = roleMap.getLength(); 151 String s = "" + num + " "; 153 String format = null; if(num == 1) 155 format = bundle.getString("PROP_TEXT_ONE_MAP_ELEMNT"); else 157 format = bundle.getString("PROP_TEXT_N_MAP_ELEMNT"); 159 s = java.text.MessageFormat.format(format, new Object [] { s }); 160 161 java.awt.FontMetrics fm = gfx.getFontMetrics(); 162 163 gfx.drawString(s, 4, (box.height - fm.getHeight()) / 2 + 1 + fm.getMaxAscent()); 166 } 167 168 public void setAsText(String text) throws IllegalArgumentException { 169 throw new IllegalArgumentException (bundle.getString("ERR_SET_AS_TEXT_ILLEGAL")); } 171 172 TableCellEditor c023cell = new javax.swing.DefaultCellEditor (new javax.swing.JTextField ()); 173 TableCellEditor c1cell = new javax.swing.DefaultCellEditor (new javax.swing.JPasswordField ()); 174 175 public void setValue(Object value) { 176 Reporter.info(""); if (table != null) { 178 TableCellEditor cell = table.getCellEditor(); 179 if (null != cell) { 180 Reporter.info("There is a cell: " + cell); Reporter.info(" this is the value of the cell: " + cell.getCellEditorValue()); int r = table.getEditingRow(); 183 int c = table.getEditingColumn(); 184 if (r > -1 && c > -1) { 185 table.setValueAt(cell.getCellEditorValue(), r, c); 186 } 187 } 188 } 189 if (value instanceof RoleMapElement) { 190 roleMap = (RoleMapElement) value; } 192 } 193 194 public boolean supportsCustomEditor() { 195 return true; 196 } 197 198 } 199 | Popular Tags |