1 package com.calipso.reportgenerator.usermanager; 2 3 import com.calipso.reportgenerator.common.LanguageTraslator; 4 import com.calipso.reportgenerator.common.*; 5 import com.calipso.reportgenerator.reportmanager.UsersRepository; 6 7 import javax.swing.*; 8 import java.awt.event.*; 9 import java.awt.*; 10 11 import com.calipso.reportgenerator.common.InfoException; 12 13 14 18 public class UserManagerFrame extends javax.swing.JFrame implements UserManagerListener { 19 20 private javax.swing.JButton exit; 21 private javax.swing.JButton add; 22 private javax.swing.JButton del; 23 private javax.swing.JButton modify; 24 private javax.swing.JPanel jPanel1; 25 private javax.swing.JPanel jPanel2; 26 private javax.swing.JTabbedPane jTabbedPane1; 27 private JList listUsers; 28 private JList listRols; 29 private UserManager userManager; 30 private DefaultListModel listModelUsers; 31 private DefaultListModel listModelRols; 32 private boolean isEmbedded; 33 private ReportGeneratorConfiguration reportGeneratorConfiguration; 34 35 public UserManagerFrame(boolean isEmbedded, ReportGeneratorConfiguration reportGeneratorConfiguration) throws InfoException { 36 this.isEmbedded = isEmbedded; 37 String propertiesPath = ""; 38 this.reportGeneratorConfiguration = reportGeneratorConfiguration; 39 if (this.reportGeneratorConfiguration == null){ 40 this.reportGeneratorConfiguration = new ReportGeneratorConfiguration(ReportGeneratorConfiguration.getConfiguration(propertiesPath)); 41 } 42 LanguageTraslator.newLocaleFrom(this.reportGeneratorConfiguration.getLocaleLanguage(),this.reportGeneratorConfiguration.getCountry(),this.reportGeneratorConfiguration.getLanguagesPath()); 43 44 45 46 initComponents(this.reportGeneratorConfiguration); 47 try{ 48 userManager = new UserManager(this.reportGeneratorConfiguration); 49 } 50 catch(InfoException e){ 51 new ShowExceptionMessageDialog(LanguageTraslator.traslate("458"),e); 52 System.exit(0); 53 } 54 55 if (!isEmbedded()){ 56 if(!login(this.reportGeneratorConfiguration) ) { 57 System.exit(0); 58 } 59 } 60 userManager.addListener(this); 61 63 jTabbedPane1.addTab(LanguageTraslator.traslate("418"),null); 64 jTabbedPane1.addTab(LanguageTraslator.traslate("419"),null); 65 userManagerChange(userManager); 66 67 68 exit.addActionListener(new ButtonListener()); 69 modify.addActionListener(new ButtonListener()); 70 add.addActionListener(new ButtonListener()); 71 del.addActionListener(new ButtonListener()); 72 } 73 74 80 private boolean login(ReportGeneratorConfiguration reportGeneratorConfiguration) throws InfoException { 81 UsersRepository repository = new UsersRepository(reportGeneratorConfiguration.getUsersRepositoryPath()); 82 UserManagerLoginFrame userManagerLoginFrame = new UserManagerLoginFrame(this,"Login",true,"root",reportGeneratorConfiguration,userManager); 83 if(userManagerLoginFrame.login()) { 84 return true; 85 } 86 return false; 87 } 88 89 92 private void getUsers() { 93 Object [] list; 94 listModelUsers = new DefaultListModel(); 95 try { 96 list = userManager.getUsers().toArray(); 97 for(int i =0; i<list.length;i++) { 98 listModelUsers.addElement(list[i]); 99 } 100 } 101 catch(Exception e) { 102 new ShowExceptionMessageDialog(LanguageTraslator.traslate("433"),e); 103 } 104 105 listUsers = new JList(listModelUsers); 106 JScrollPane scrollpane = new JScrollPane(listUsers); 107 108 jTabbedPane1.setComponentAt(0,scrollpane); 109 } 110 111 114 private void getRols() { 115 java.util.List list; 116 listModelRols = new DefaultListModel(); 117 118 try { 119 list = (java.util.List ) userManager.getRols(); 120 for(int i =0; i<list.size();i++) { 121 listModelRols.addElement(list.get(i)); 122 } 123 } 124 catch(Exception e) { 125 new ShowExceptionMessageDialog(LanguageTraslator.traslate("434"),e); 126 } 127 128 listRols = new JList(listModelRols); 129 JScrollPane scrollpane = new JScrollPane(listRols); 130 jTabbedPane1.setComponentAt(1,scrollpane); 131 } 132 133 136 private void initComponents(ReportGeneratorConfiguration reportGeneratorConfiguration) { 137 jPanel1 = new javax.swing.JPanel (); 138 jPanel2 = new javax.swing.JPanel (); 139 jTabbedPane1 = new javax.swing.JTabbedPane (); 140 add = new javax.swing.JButton (); 141 del = new javax.swing.JButton (); 142 modify = new javax.swing.JButton (); 143 exit = new javax.swing.JButton (); 144 if(isEmbedded()){ 145 setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE); 146 }else{ 147 setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); 148 } 149 jPanel1.setLayout(new AbsoluteLayout()); 150 151 jPanel2.setLayout(new AbsoluteLayout()); 152 153 jPanel2.add(jTabbedPane1, new AbsoluteConstraints(0, 0, 290, 370)); 154 155 add.setText(LanguageTraslator.traslate("130")); 156 jPanel2.add(add, new AbsoluteConstraints(310, 40, 90, 25)); 157 158 del.setText(LanguageTraslator.traslate("421")); 159 jPanel2.add(del, new AbsoluteConstraints(310, 100, 90, 25)); 160 161 modify.setText(LanguageTraslator.traslate("428")); 162 jPanel2.add(modify, new AbsoluteConstraints(310, 70, 90, 25)); 163 164 exit.setText(LanguageTraslator.traslate("144")); 165 166 jPanel2.add(exit, new AbsoluteConstraints(310, 340, 90, 25)); 167 168 jPanel1.add(jPanel2, new AbsoluteConstraints(0, 10, 410, 370)); 169 170 getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH); 171 172 setTitle("User Manager"); 173 174 setIconImage(reportGeneratorConfiguration.getImage("ICON")); 175 176 177 Dimension scrn = getToolkit().getScreenSize(); 178 179 setLocation((scrn.width-getWidth())/3,(scrn.height-getHeight())/3); 180 setResizable(false); 181 pack(); 182 } 183 184 187 private void addUser() { 188 UserManagerModifyFrame dialog = new UserManagerModifyFrame(this, userManager); 189 dialog.setTitle(LanguageTraslator.traslate("130") + " "+ LanguageTraslator.traslate("141")); 190 dialog.setVisible(true); 191 userManagerChange(userManager); 192 } 193 194 197 private void modifyUser() { 198 UserManagerModifyFrame dialog = new UserManagerModifyFrame(this, userManager, (User)listUsers.getSelectedValue()); 199 dialog.setTitle(LanguageTraslator.traslate("432")); 200 dialog.setVisible(true); 201 userManagerChange(userManager); 202 } 203 204 207 private void delUser() { 208 int res; 209 res = JOptionPane.showConfirmDialog(this,LanguageTraslator.traslate("430"), 210 LanguageTraslator.traslate("435"),JOptionPane.YES_NO_OPTION ); 211 if( res == JOptionPane.YES_OPTION ) { 212 try { 213 for (int i = 0; i < listUsers.getSelectedValues().length; i++) { 214 userManager.removeUser((User)listUsers.getSelectedValues()[i]); 215 } 216 userManagerChange(userManager); 217 } 218 catch(Exception e) { 219 new ShowExceptionMessageDialog(LanguageTraslator.traslate("436"),e); 220 } 221 } 222 } 223 224 228 private void modifyRol() { 229 RolManagerModifyFrame dialog = new RolManagerModifyFrame(this, userManager, (Rol)listRols.getSelectedValue()); 230 dialog.setTitle(LanguageTraslator.traslate("429")); 231 dialog.setVisible(true); 232 userManagerChange(userManager); 233 } 234 235 238 private void addRol() throws InfoException { 239 RolManagerModifyFrame dialog = new RolManagerModifyFrame(this, userManager); 240 dialog.setTitle(LanguageTraslator.traslate("130") + " "+LanguageTraslator.traslate("426")); 241 dialog.setVisible(true); 242 userManagerChange(userManager); 243 } 244 245 248 private void delRol() { 249 int res; 250 res = JOptionPane.showConfirmDialog(this,LanguageTraslator.traslate("431"), 251 LanguageTraslator.traslate("438"),JOptionPane.YES_NO_OPTION ); 252 253 if( res == JOptionPane.YES_OPTION ) { 254 try { 255 for (int i = 0; i < listRols.getSelectedValues().length; i++) { 256 userManager.removeRol((Rol)listRols.getSelectedValues()[i]); 257 } 258 userManagerChange(userManager); 259 } 260 catch(Exception e) { 261 new ShowExceptionMessageDialog(LanguageTraslator.traslate("443"),e); 262 } 263 } 264 } 265 266 270 public void userManagerChange(UserManager userManager) { 271 getUsers(); 272 getRols(); 273 } 274 275 class ButtonListener implements ActionListener 276 { 277 public void actionPerformed(ActionEvent evento) { 278 if( evento.getSource()== add && jTabbedPane1.getSelectedIndex() == 0 ) { 280 addUser(); 281 } 282 283 else if ( evento.getSource()== modify && jTabbedPane1.getSelectedIndex() == 0 && listUsers.getSelectedIndices().length == 1 ) { 285 modifyUser(); 286 } 287 288 else if ( evento.getSource()== del && jTabbedPane1.getSelectedIndex() == 0 && listUsers.getSelectedValues().length > 0 ) { 290 delUser(); 291 } 292 293 else if ( evento.getSource()== add && jTabbedPane1.getSelectedIndex() == 1 ) { 295 try { 296 addRol(); 297 } catch (InfoException e) { 298 new ShowExceptionMessageDialog(LanguageTraslator.traslate("434"),e); 299 } 300 } 301 302 else if ( evento.getSource()== modify && jTabbedPane1.getSelectedIndex() == 1 && listRols.getSelectedValues().length == 1 ) { 304 try { 305 modifyRol(); 306 } catch (Exception e) { 307 new ShowExceptionMessageDialog(LanguageTraslator.traslate("445"),e); 308 } 309 } 310 311 else if ( evento.getSource()== del && jTabbedPane1.getSelectedIndex() == 1 && listRols.getSelectedValues().length > 0 ) { 313 delRol(); 314 } 315 316 else if (evento.getSource() == exit ) { 318 if (isEmbedded()){ 319 setVisible(false); 320 }else{ 321 System.exit(0); 322 } 323 324 } 325 326 } 327 } 328 329 public boolean isEmbedded() { 330 return isEmbedded; 331 } 332 } 333 334 | Popular Tags |