1 30 package com.genimen.djeneric.tools.modeler.dialogs; 31 32 import java.awt.BorderLayout ; 33 import java.awt.Dimension ; 34 import java.awt.event.ActionEvent ; 35 import java.awt.event.KeyEvent ; 36 import java.util.ArrayList ; 37 38 import javax.swing.DefaultComboBoxModel ; 39 import javax.swing.JButton ; 40 import javax.swing.JLabel ; 41 import javax.swing.JList ; 42 import javax.swing.JPanel ; 43 import javax.swing.JScrollPane ; 44 import javax.swing.JTextField ; 45 import javax.swing.event.ListSelectionEvent ; 46 47 import com.genimen.djeneric.language.Messages; 48 import com.genimen.djeneric.repository.DjPersistenceManager; 49 import com.genimen.djeneric.ui.DjVerticalFlowLayout; 50 import com.genimen.djeneric.ui.Util; 51 import com.genimen.djeneric.util.DjLogger; 52 53 public class RoleEditorPanel extends JPanel 54 { 55 private static final long serialVersionUID = 1L; 56 BorderLayout borderLayout1 = new BorderLayout (); 57 JPanel jPanel3 = new JPanel (); 58 JButton _butCreate = new JButton (); 59 JButton _butRemove = new JButton (); 60 BorderLayout borderLayout3 = new BorderLayout (); 61 JScrollPane jScrollPane1 = new JScrollPane (); 62 DjVerticalFlowLayout verticalFlowLayout1 = new DjVerticalFlowLayout(); 63 JList _lstRoles = new JList (); 64 JPanel jPanel1 = new JPanel (); 65 JLabel _lblRole = new JLabel (); 66 JTextField _edtName = new JTextField (); 67 BorderLayout borderLayout2 = new BorderLayout (); 68 JPanel jPanel2 = new JPanel (); 69 BorderLayout borderLayout4 = new BorderLayout (); 70 ArrayList _roles = new ArrayList (); 71 72 public RoleEditorPanel(DjPersistenceManager mgr) 73 { 74 try 75 { 76 jbInit(); 77 String [] roles = mgr.getRoles(); 78 for(int i=0; i<roles.length; i++) _roles.add(roles[i]); 79 updateModel(null); 80 81 } 82 catch (Exception ex) 83 { 84 DjLogger.log(ex); 85 } 86 } 87 88 public String [] getRoles() 89 { 90 return (String []) _roles.toArray(new String [0]); 91 } 92 private void updateModel(String selectThisOne) 93 { 94 _lstRoles.setModel(new DefaultComboBoxModel (_roles.toArray(new String [0]))); 95 if (selectThisOne != null) _lstRoles.setSelectedValue(selectThisOne, true); 96 } 97 98 void jbInit() throws Exception 99 { 100 this.setLayout(borderLayout1); 101 _butCreate.setText(Messages.getString("global.Create")); 102 _butCreate.addActionListener(new RoleEditorPanel__butCreate_actionAdapter(this)); 103 _butRemove.setText(Messages.getString("global.Delete")); 104 _butRemove.addActionListener(new RoleEditorPanel__butRemove_actionAdapter(this)); 105 jPanel3.setLayout(verticalFlowLayout1); 106 _lblRole.setText(Messages.getString("RoleEditorPanel.RoleName")); 107 jPanel1.setLayout(borderLayout2); 108 _edtName.setFont(new java.awt.Font ("Monospaced", 0, 11)); 109 _edtName.setPreferredSize(new Dimension (200, 21)); 110 _edtName.setText(""); 111 _edtName.addKeyListener(new RoleEditorPanel__edtName_keyAdapter(this)); 112 _lstRoles.setFont(new java.awt.Font ("Monospaced", 0, 11)); 113 _lstRoles.addListSelectionListener(new RoleEditorPanel__lstRoles_listSelectionAdapter(this)); 114 jPanel2.setLayout(borderLayout4); 115 jPanel3.add(_butCreate, null); 116 jPanel3.add(_butRemove, null); 117 this.add(jPanel2, BorderLayout.CENTER); 118 jPanel2.add(jScrollPane1, BorderLayout.CENTER); 119 jPanel2.add(jPanel1, BorderLayout.SOUTH); 120 jScrollPane1.getViewport().add(_lstRoles, null); 121 this.add(jPanel3, BorderLayout.EAST); 122 jPanel1.add(_lblRole, BorderLayout.NORTH); 123 jPanel1.add(_edtName, BorderLayout.CENTER); 124 125 Util.sizeButtons(jPanel3); 126 } 127 128 void _butCreate_actionPerformed(ActionEvent e) 129 { 130 String newRole = Messages.getString("RoleEditorPanel.NewRole"); 131 _roles.add(newRole); 132 updateModel(newRole); 133 _edtName.requestFocus(); 134 _edtName.selectAll(); 135 } 136 137 void _butRemove_actionPerformed(ActionEvent e) 138 { 139 String sel = (String ) _lstRoles.getSelectedValue(); 140 if (sel != null) _roles.remove(sel); 141 updateModel(null); 142 } 143 144 void _lstRoles_valueChanged(ListSelectionEvent e) 145 { 146 String sel = (String ) _lstRoles.getSelectedValue(); 147 if (sel != null) _edtName.setText(sel); 148 } 149 150 void _edtName_keyReleased(KeyEvent e) 151 { 152 int idx = _lstRoles.getSelectedIndex(); 153 154 if (idx != -1 && _edtName.getText().trim().length() > 0) 155 { 156 String rolename = _edtName.getText().trim().toLowerCase(); 157 _roles.set(idx, rolename); 158 updateModel(rolename); 159 _lstRoles.repaint(); 160 } 161 else _edtName.setText(""); 162 } 163 164 } 165 166 class RoleEditorPanel__butCreate_actionAdapter implements java.awt.event.ActionListener 167 { 168 RoleEditorPanel adaptee; 169 170 RoleEditorPanel__butCreate_actionAdapter(RoleEditorPanel adaptee) 171 { 172 this.adaptee = adaptee; 173 } 174 175 public void actionPerformed(ActionEvent e) 176 { 177 adaptee._butCreate_actionPerformed(e); 178 } 179 } 180 181 class RoleEditorPanel__butRemove_actionAdapter implements java.awt.event.ActionListener 182 { 183 RoleEditorPanel adaptee; 184 185 RoleEditorPanel__butRemove_actionAdapter(RoleEditorPanel adaptee) 186 { 187 this.adaptee = adaptee; 188 } 189 190 public void actionPerformed(ActionEvent e) 191 { 192 adaptee._butRemove_actionPerformed(e); 193 } 194 } 195 196 class RoleEditorPanel__lstRoles_listSelectionAdapter implements javax.swing.event.ListSelectionListener 197 { 198 RoleEditorPanel adaptee; 199 200 RoleEditorPanel__lstRoles_listSelectionAdapter(RoleEditorPanel adaptee) 201 { 202 this.adaptee = adaptee; 203 } 204 205 public void valueChanged(ListSelectionEvent e) 206 { 207 adaptee._lstRoles_valueChanged(e); 208 } 209 } 210 211 class RoleEditorPanel__edtName_keyAdapter extends java.awt.event.KeyAdapter 212 { 213 RoleEditorPanel adaptee; 214 215 RoleEditorPanel__edtName_keyAdapter(RoleEditorPanel adaptee) 216 { 217 this.adaptee = adaptee; 218 } 219 220 public void keyReleased(KeyEvent e) 221 { 222 adaptee._edtName_keyReleased(e); 223 } 224 } | Popular Tags |