/src/mpv5/ui/panels/HistoryPanel.java
Java | 355 lines | 279 code | 40 blank | 36 comment | 21 complexity | b60f3ca0c324cd4c991ea6fa92581276 MD5 | raw file
1/* 2 * This file is part of YaBS. 3 * 4 * YaBS is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * YaBS is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with YaBS. If not, see <http://www.gnu.org/licenses/>. 16 */ 17/* 18 * HistoryPanel.java 19 * 20 * Created on 30.03.2009, 12:05:51 21 */ 22package mpv5.ui.panels; 23 24import java.awt.Component; 25import java.util.Date; 26import java.util.logging.Level; 27import java.util.logging.Logger; 28import javax.swing.DefaultComboBoxModel; 29import javax.swing.JComponent; 30import javax.swing.JTable; 31import javax.swing.table.DefaultTableModel; 32import javax.swing.table.TableCellRenderer; 33import mpv5.db.common.Context; 34import mpv5.db.common.QueryCriteria; 35import mpv5.db.common.DatabaseObject; 36import mpv5.db.common.NodataFoundException; 37import mpv5.db.common.QueryCriteria2; 38import mpv5.db.common.QueryHandler; 39import mpv5.db.common.QueryParameter; 40import mpv5.globals.Headers; 41import mpv5.db.objects.Group; 42import mpv5.logging.Log; 43import mpv5.db.objects.User; 44import mpv5.ui.misc.MPTable; 45import mpv5.utils.arrays.ArrayUtilities; 46import mpv5.utils.date.DateConverter; 47import mpv5.utils.date.vTimeframe; 48import mpv5.utils.models.MPTableModel; 49import mpv5.utils.tables.TableFormat; 50import mpv5.ui.misc.TableViewPersistenceHandler; 51 52/** 53 * 54 * 55 */ 56public class HistoryPanel extends javax.swing.JPanel implements ListPanel { 57 58 private static HistoryPanel t; 59 private static final long serialVersionUID = 1L; 60 private java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle(); 61 62 public static Component instanceOf() { 63 if (t == null) { 64 t = new HistoryPanel(); 65 } 66 return t; 67 } 68 69 /** Creates new form HistoryPanel */ 70 public HistoryPanel() { 71 initComponents(); 72 setName("historypanel"); 73 timeframeChooser1.setTime(new vTimeframe(DateConverter.getDate(DateConverter.getYear()), new Date())); 74 prinitingComboBox1.init(jTable1); 75 Object[] dat; 76 Object[] dat2; 77 try { 78 dat = DatabaseObject.getObjects(Context.getUser()).toArray(); 79 dat = ArrayUtilities.merge(new Object[]{User.DEFAULT}, dat); 80 users.setModel(new DefaultComboBoxModel(dat)); 81 } catch (NodataFoundException ex) { 82 Log.Debug(ex); 83 users.setModel(new DefaultComboBoxModel()); 84 } 85 86 try { 87 dat2 = DatabaseObject.getObjects(Context.getGroup()).toArray(); 88 dat2 = ArrayUtilities.merge(new Object[]{new Group("")}, dat2); 89 groups.setModel(new DefaultComboBoxModel(dat2)); 90 } catch (NodataFoundException ex) { 91 Log.Debug(ex); 92 groups.setModel(new DefaultComboBoxModel()); 93 } 94 95 refresh(null, null); 96 ((MPTable) jTable1).setPersistanceHandler(new TableViewPersistenceHandler((MPTable)jTable1, this)); 97 98 } 99 100 /** This method is called from within the constructor to 101 * initialize the form. 102 * WARNING: Do NOT modify this code. The content of this method is 103 * always regenerated by the Form Editor. 104 */ 105 @SuppressWarnings("unchecked") 106 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents 107 private void initComponents() { 108 109 jPanel1 = new javax.swing.JPanel(); 110 jToolBar1 = new javax.swing.JToolBar(); 111 jLabel1 = new javax.swing.JLabel(); 112 users = new javax.swing.JComboBox(); 113 jLabel2 = new javax.swing.JLabel(); 114 groups = new javax.swing.JComboBox(); 115 jSeparator6 = new javax.swing.JToolBar.Separator(); 116 jButton1 = new javax.swing.JButton(); 117 prinitingComboBox1 = new mpv5.ui.beans.PrinitingComboBox(); 118 jScrollPane1 = new javax.swing.JScrollPane(); 119 jTable1 = new mpv5.ui.misc.MPTable(this) { 120 public Component prepareRenderer(TableCellRenderer renderer, 121 int rowIndex, int vColIndex) { 122 Component c = super.prepareRenderer(renderer, rowIndex, vColIndex); 123 if (c instanceof JComponent) { 124 JComponent jc = (JComponent)c; 125 jc.setToolTipText(String.valueOf(getValueAt(rowIndex, vColIndex))); 126 } 127 return c; 128 } 129 }; 130 jToolBar2 = new javax.swing.JToolBar(); 131 jLabel3 = new javax.swing.JLabel(); 132 timeframeChooser1 = new mpv5.ui.beans.TimeframeChooser(); 133 134 setName("Form"); // NOI18N 135 136 java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle(); // NOI18N 137 jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("HistoryPanel.jPanel1.border.title"))); // NOI18N 138 jPanel1.setName("jPanel1"); // NOI18N 139 140 jToolBar1.setFloatable(false); 141 jToolBar1.setRollover(true); 142 jToolBar1.setName("jToolBar1"); // NOI18N 143 144 jLabel1.setText(bundle.getString("HistoryPanel.jLabel1.text")); // NOI18N 145 jLabel1.setMaximumSize(new java.awt.Dimension(333, 20)); 146 jLabel1.setMinimumSize(new java.awt.Dimension(100, 20)); 147 jLabel1.setName("jLabel1"); // NOI18N 148 jLabel1.setPreferredSize(new java.awt.Dimension(120, 20)); 149 jToolBar1.add(jLabel1); 150 151 users.setMaximumSize(new java.awt.Dimension(333, 20)); 152 users.setMinimumSize(new java.awt.Dimension(100, 20)); 153 users.setName("users"); // NOI18N 154 users.setPreferredSize(new java.awt.Dimension(120, 20)); 155 users.addActionListener(new java.awt.event.ActionListener() { 156 public void actionPerformed(java.awt.event.ActionEvent evt) { 157 usersActionPerformed(evt); 158 } 159 }); 160 jToolBar1.add(users); 161 162 jLabel2.setText(bundle.getString("HistoryPanel.jLabel2.text")); // NOI18N 163 jLabel2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); 164 jLabel2.setMaximumSize(new java.awt.Dimension(333, 20)); 165 jLabel2.setMinimumSize(new java.awt.Dimension(100, 20)); 166 jLabel2.setName("jLabel2"); // NOI18N 167 jLabel2.setPreferredSize(new java.awt.Dimension(120, 20)); 168 jToolBar1.add(jLabel2); 169 170 groups.setMaximumSize(new java.awt.Dimension(333, 20)); 171 groups.setMinimumSize(new java.awt.Dimension(100, 20)); 172 groups.setName("groups"); // NOI18N 173 groups.setPreferredSize(new java.awt.Dimension(120, 20)); 174 groups.addActionListener(new java.awt.event.ActionListener() { 175 public void actionPerformed(java.awt.event.ActionEvent evt) { 176 groupsActionPerformed(evt); 177 } 178 }); 179 jToolBar1.add(groups); 180 181 jSeparator6.setName("jSeparator6"); // NOI18N 182 jToolBar1.add(jSeparator6); 183 184 jButton1.setText(bundle.getString("HistoryPanel.jButton1.text")); // NOI18N 185 jButton1.setFocusable(false); 186 jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); 187 jButton1.setMaximumSize(new java.awt.Dimension(333, 20)); 188 jButton1.setMinimumSize(new java.awt.Dimension(100, 20)); 189 jButton1.setName("jButton1"); // NOI18N 190 jButton1.setPreferredSize(new java.awt.Dimension(120, 20)); 191 jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); 192 jButton1.addActionListener(new java.awt.event.ActionListener() { 193 public void actionPerformed(java.awt.event.ActionEvent evt) { 194 jButton1ActionPerformed(evt); 195 } 196 }); 197 jToolBar1.add(jButton1); 198 199 prinitingComboBox1.setMaximumSize(new java.awt.Dimension(333, 20)); 200 prinitingComboBox1.setMinimumSize(new java.awt.Dimension(100, 20)); 201 prinitingComboBox1.setName("prinitingComboBox1"); // NOI18N 202 prinitingComboBox1.setPreferredSize(new java.awt.Dimension(120, 20)); 203 jToolBar1.add(prinitingComboBox1); 204 205 jScrollPane1.setName("jScrollPane1"); // NOI18N 206 207 jTable1.setAutoCreateRowSorter(true); 208 jTable1.setModel(new javax.swing.table.DefaultTableModel( 209 new Object [][] { 210 {}, 211 {}, 212 {}, 213 {} 214 }, 215 new String [] { 216 217 } 218 )); 219 jTable1.setName("jTable1"); // NOI18N 220 jScrollPane1.setViewportView(jTable1); 221 222 jToolBar2.setFloatable(false); 223 jToolBar2.setRollover(true); 224 jToolBar2.setName("jToolBar2"); // NOI18N 225 226 jLabel3.setText(bundle.getString("HistoryPanel.jLabel3.text")); // NOI18N 227 jLabel3.setMaximumSize(new java.awt.Dimension(333, 20)); 228 jLabel3.setName("jLabel3"); // NOI18N 229 jLabel3.setPreferredSize(new java.awt.Dimension(100, 20)); 230 jToolBar2.add(jLabel3); 231 232 timeframeChooser1.setName("timeframeChooser1"); // NOI18N 233 jToolBar2.add(timeframeChooser1); 234 235 javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); 236 jPanel1.setLayout(jPanel1Layout); 237 jPanel1Layout.setHorizontalGroup( 238 jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 239 .addComponent(jToolBar2, javax.swing.GroupLayout.DEFAULT_SIZE, 606, Short.MAX_VALUE) 240 .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 606, Short.MAX_VALUE) 241 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 606, Short.MAX_VALUE) 242 ); 243 jPanel1Layout.setVerticalGroup( 244 jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 245 .addGroup(jPanel1Layout.createSequentialGroup() 246 .addComponent(jToolBar2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) 247 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 248 .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE) 249 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 250 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 258, Short.MAX_VALUE)) 251 ); 252 253 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); 254 this.setLayout(layout); 255 layout.setHorizontalGroup( 256 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 257 .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 258 ); 259 layout.setVerticalGroup( 260 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 261 .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 262 ); 263 }// </editor-fold>//GEN-END:initComponents 264 265 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed 266 try { 267 if (users.getSelectedIndex() > 0 && groups.getSelectedIndex() > 0) { 268 refresh((User) users.getSelectedItem(), (Group) groups.getSelectedItem()); 269 } else if (groups.getSelectedIndex() > 0) { 270 refresh(null, (Group) groups.getSelectedItem()); 271 } else if (users.getSelectedIndex() > 0) { 272 refresh((User) users.getSelectedItem(), null); 273 } else { 274 refresh(null, null); 275 } 276 } catch (Exception ignore) { 277 refresh(null, null); 278 } 279 }//GEN-LAST:event_jButton1ActionPerformed 280 281 private void groupsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_groupsActionPerformed 282 }//GEN-LAST:event_groupsActionPerformed 283 284 private void usersActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_usersActionPerformed 285 }//GEN-LAST:event_usersActionPerformed 286 287 // Variables declaration - do not modify//GEN-BEGIN:variables 288 private javax.swing.JComboBox groups; 289 private javax.swing.JButton jButton1; 290 private javax.swing.JLabel jLabel1; 291 private javax.swing.JLabel jLabel2; 292 private javax.swing.JLabel jLabel3; 293 private javax.swing.JPanel jPanel1; 294 private javax.swing.JScrollPane jScrollPane1; 295 private javax.swing.JToolBar.Separator jSeparator6; 296 private javax.swing.JTable jTable1; 297 private javax.swing.JToolBar jToolBar1; 298 private javax.swing.JToolBar jToolBar2; 299 private mpv5.ui.beans.PrinitingComboBox prinitingComboBox1; 300 private mpv5.ui.beans.TimeframeChooser timeframeChooser1; 301 private javax.swing.JComboBox users; 302 // End of variables declaration//GEN-END:variables 303 304 private void refresh(User forUser, Group forGroup) { 305 QueryCriteria2 dh = new QueryCriteria2(); 306 Object[][] d = new Object[0][0]; 307 308 if (forUser != null && !forUser.equals(User.DEFAULT)) { 309 try { 310 dh.and(new QueryParameter(Context.getHistory(), forUser.getType() + "name", forUser.getName(), QueryParameter.EQUALS)); 311 if (forGroup != null && !forGroup.__getCname().equals("")) { 312 dh.and(new QueryParameter(Context.getHistory(), forGroup.getDbIdentity() + "ids", forGroup.__getIDS(), QueryParameter.EQUALS)); 313 } 314 Context c = Context.getHistory(); 315 c.addReference(Context.getGroup()); 316 d = QueryHandler.instanceOf().clone(c).select(Context.DETAILS_HISTORY, dh, timeframeChooser1.getTime()).getData(); 317 318 } catch (NodataFoundException ex) { 319 Log.Debug(this, ex.getMessage()); 320 } 321 } else if (forGroup != null && !forGroup.__getCname().equals("")) { 322 try { 323 dh.and(new QueryParameter(Context.getHistory(), forGroup.getDbIdentity() + "ids", forGroup.__getIDS(), QueryParameter.EQUALS)); 324 Context c = Context.getHistory(); 325 c.addReference(Context.getGroup()); 326 d = QueryHandler.instanceOf().clone(c).select(Context.DETAILS_HISTORY, dh, timeframeChooser1.getTime()).getData(); 327 328 } catch (NodataFoundException ex) { 329 Log.Debug(this, ex.getMessage()); 330 } 331 } else { 332 try { 333 Context c = Context.getHistory(); 334 c.addReference(Context.getGroup()); 335 d = QueryHandler.instanceOf().clone(c).select(Context.DETAILS_HISTORY, dh, timeframeChooser1.getTime()).getData(); 336 } catch (NodataFoundException ex) { 337 Log.Debug(this, ex.getMessage()); 338 } 339 340 } 341 342 jTable1.setModel(new MPTableModel(ArrayUtilities.changeToClassValue(d, 4, Date.class), Headers.HISTORY.getValue(), new Class[]{String.class, String.class, String.class, String.class, Date.class})); 343 TableFormat.stripColumn(jTable1, 0); 344// TableFormat.stripColumn(jTable1, 3); 345// TableFormat.stripColumn(jTable1, 4); 346 } 347 348 public void refresh() { 349 refresh(null,null); 350 } 351 352 public void flush() { 353 jTable1.setModel(new DefaultTableModel()); 354 } 355}