1 package org.ozoneDB.adminGui.feature.account.users; 8 9 import java.awt.BorderLayout ; 10 import java.awt.Point ; 11 import java.awt.event.MouseEvent ; 12 import javax.swing.*; 13 14 import org.ozoneDB.adminGui.feature.account.Account; 15 import org.ozoneDB.adminGui.widget.TableSorter; 16 import org.ozoneDB.adminGui.widget.TitledPanel; 17 18 19 28 30 public class UserPanel extends TitledPanel { 31 32 33 private JComponent parent; 34 35 private UserAccount userAccount; 36 37 38 private JTable userTable = new JTable(); 39 40 private UserTableModel userTableModel = new UserTableModel(); 41 42 private TableSorter tableSorter = new TableSorter(); 43 44 private String lastUser = ""; 45 46 47 52 public UserPanel(JComponent parent) { 53 super("Users"); 54 this.parent = parent; 55 init(); 56 57 this.userAccount.list(); 59 } 60 61 64 private void init() { 65 this.userAccount = new UserAccount(this); 67 68 this.userTable.setModel(this.userTableModel); 72 73 77 JScrollPane scrollPane = new JScrollPane(this.userTable); 79 this.add(scrollPane, BorderLayout.CENTER); 80 } 81 82 86 98 103 104 115 116 121 public String getId() { 122 try { 123 return (String ) (this.userTable.getModel(). 124 getValueAt(this.userTable.getSelectedRow(), 125 Account.COLUMN_POS_USER_ID)); 126 } catch (Exception e) { 127 return null; 128 } 129 } 130 131 136 public String getName() { 137 try { 138 return (String ) (this.userTable.getModel(). 139 getValueAt(this.userTable.getSelectedRow(), 140 Account.COLUMN_POS_USER_NAME)); 141 } catch (Exception e) { 142 return null; 143 } 144 } 145 146 151 public String getPassword() { 152 try { 153 return (String ) (this.userTable.getModel(). 154 getValueAt(this.userTable.getSelectedRow(), 155 Account.COLUMN_POS_USER_PWD)); 156 } catch (Exception e) { 157 return null; 158 } 159 } 160 161 166 public String getStatus() { 167 try { 168 return (String ) (this.userTable.getModel(). 169 getValueAt(this.userTable.getSelectedRow(), 170 Account.COLUMN_POS_USER_STATUS)); 171 } catch (Exception e) { 172 return null; 173 } 174 } 175 176 181 public JTable getTable() { 182 return this.userTable; 183 } 184 185 190 public UserTableModel getModel() { 191 return this.userTableModel; 192 } 193 194 199 public TableSorter getSorter() { 200 return this.tableSorter; 201 } 202 203 208 public UserAccount getUsers() { 209 return this.userAccount; 210 } 211 212 217 241 242 245 258 259 262 308 309 315 344 345 351 396 397 404 public void mouseClicked(MouseEvent e) { 405 if (e.getSource().equals(userTable.getTableHeader())) { 408 if (e.getClickCount() == 2) { 411 Point p = e.getPoint(); 413 int x = (int) p.getX(); 414 int selCol = userTable.getColumnModel().getColumnIndexAtX(x); 415 416 if (lastUser.equals("")) { 419 } 422 else { 425 int rowCount = userTable.getRowCount(); 426 int userIdCol = userTable.getColumnModel().getColumnIndex( 427 Account.COLUMN_USER_ID); 428 int selRow = -1; 429 430 for (int i = 0; i < rowCount; i++) { 431 String userid = (String ) userTable.getValueAt(i, 432 userIdCol); 433 if (lastUser.equals(userid)) { 434 selRow = i; 435 break; 436 } 437 } 438 439 if (selRow != -1) { 440 userTable.setRowSelectionInterval(selRow, selRow); 441 userTable.setColumnSelectionInterval(selCol, selCol); 442 userTable.scrollRectToVisible( 443 userTable.getCellRect(selRow, selCol, true)); 444 userTable.repaint(); 445 } else { 446 } 449 } 450 } 451 } 452 } 453 454 } 456 457 | Popular Tags |