/src/mpv5/ui/panels/HistoryPanel.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/ · 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. */
  22. package mpv5.ui.panels;
  23. import java.awt.Component;
  24. import java.util.Date;
  25. import java.util.logging.Level;
  26. import java.util.logging.Logger;
  27. import javax.swing.DefaultComboBoxModel;
  28. import javax.swing.JComponent;
  29. import javax.swing.JTable;
  30. import javax.swing.table.DefaultTableModel;
  31. import javax.swing.table.TableCellRenderer;
  32. import mpv5.db.common.Context;
  33. import mpv5.db.common.QueryCriteria;
  34. import mpv5.db.common.DatabaseObject;
  35. import mpv5.db.common.NodataFoundException;
  36. import mpv5.db.common.QueryCriteria2;
  37. import mpv5.db.common.QueryHandler;
  38. import mpv5.db.common.QueryParameter;
  39. import mpv5.globals.Headers;
  40. import mpv5.db.objects.Group;
  41. import mpv5.logging.Log;
  42. import mpv5.db.objects.User;
  43. import mpv5.ui.misc.MPTable;
  44. import mpv5.utils.arrays.ArrayUtilities;
  45. import mpv5.utils.date.DateConverter;
  46. import mpv5.utils.date.vTimeframe;
  47. import mpv5.utils.models.MPTableModel;
  48. import mpv5.utils.tables.TableFormat;
  49. import mpv5.ui.misc.TableViewPersistenceHandler;
  50. /**
  51. *
  52. *
  53. */
  54. public class HistoryPanel extends javax.swing.JPanel implements ListPanel {
  55. private static HistoryPanel t;
  56. private static final long serialVersionUID = 1L;
  57. private java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle();
  58. public static Component instanceOf() {
  59. if (t == null) {
  60. t = new HistoryPanel();
  61. }
  62. return t;
  63. }
  64. /** Creates new form HistoryPanel */
  65. public HistoryPanel() {
  66. initComponents();
  67. setName("historypanel");
  68. timeframeChooser1.setTime(new vTimeframe(DateConverter.getDate(DateConverter.getYear()), new Date()));
  69. prinitingComboBox1.init(jTable1);
  70. Object[] dat;
  71. Object[] dat2;
  72. try {
  73. dat = DatabaseObject.getObjects(Context.getUser()).toArray();
  74. dat = ArrayUtilities.merge(new Object[]{User.DEFAULT}, dat);
  75. users.setModel(new DefaultComboBoxModel(dat));
  76. } catch (NodataFoundException ex) {
  77. Log.Debug(ex);
  78. users.setModel(new DefaultComboBoxModel());
  79. }
  80. try {
  81. dat2 = DatabaseObject.getObjects(Context.getGroup()).toArray();
  82. dat2 = ArrayUtilities.merge(new Object[]{new Group("")}, dat2);
  83. groups.setModel(new DefaultComboBoxModel(dat2));
  84. } catch (NodataFoundException ex) {
  85. Log.Debug(ex);
  86. groups.setModel(new DefaultComboBoxModel());
  87. }
  88. refresh(null, null);
  89. ((MPTable) jTable1).setPersistanceHandler(new TableViewPersistenceHandler((MPTable)jTable1, this));
  90. }
  91. /** This method is called from within the constructor to
  92. * initialize the form.
  93. * WARNING: Do NOT modify this code. The content of this method is
  94. * always regenerated by the Form Editor.
  95. */
  96. @SuppressWarnings("unchecked")
  97. // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  98. private void initComponents() {
  99. jPanel1 = new javax.swing.JPanel();
  100. jToolBar1 = new javax.swing.JToolBar();
  101. jLabel1 = new javax.swing.JLabel();
  102. users = new javax.swing.JComboBox();
  103. jLabel2 = new javax.swing.JLabel();
  104. groups = new javax.swing.JComboBox();
  105. jSeparator6 = new javax.swing.JToolBar.Separator();
  106. jButton1 = new javax.swing.JButton();
  107. prinitingComboBox1 = new mpv5.ui.beans.PrinitingComboBox();
  108. jScrollPane1 = new javax.swing.JScrollPane();
  109. jTable1 = new mpv5.ui.misc.MPTable(this) {
  110. public Component prepareRenderer(TableCellRenderer renderer,
  111. int rowIndex, int vColIndex) {
  112. Component c = super.prepareRenderer(renderer, rowIndex, vColIndex);
  113. if (c instanceof JComponent) {
  114. JComponent jc = (JComponent)c;
  115. jc.setToolTipText(String.valueOf(getValueAt(rowIndex, vColIndex)));
  116. }
  117. return c;
  118. }
  119. };
  120. jToolBar2 = new javax.swing.JToolBar();
  121. jLabel3 = new javax.swing.JLabel();
  122. timeframeChooser1 = new mpv5.ui.beans.TimeframeChooser();
  123. setName("Form"); // NOI18N
  124. java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle(); // NOI18N
  125. jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("HistoryPanel.jPanel1.border.title"))); // NOI18N
  126. jPanel1.setName("jPanel1"); // NOI18N
  127. jToolBar1.setFloatable(false);
  128. jToolBar1.setRollover(true);
  129. jToolBar1.setName("jToolBar1"); // NOI18N
  130. jLabel1.setText(bundle.getString("HistoryPanel.jLabel1.text")); // NOI18N
  131. jLabel1.setMaximumSize(new java.awt.Dimension(333, 20));
  132. jLabel1.setMinimumSize(new java.awt.Dimension(100, 20));
  133. jLabel1.setName("jLabel1"); // NOI18N
  134. jLabel1.setPreferredSize(new java.awt.Dimension(120, 20));
  135. jToolBar1.add(jLabel1);
  136. users.setMaximumSize(new java.awt.Dimension(333, 20));
  137. users.setMinimumSize(new java.awt.Dimension(100, 20));
  138. users.setName("users"); // NOI18N
  139. users.setPreferredSize(new java.awt.Dimension(120, 20));
  140. users.addActionListener(new java.awt.event.ActionListener() {
  141. public void actionPerformed(java.awt.event.ActionEvent evt) {
  142. usersActionPerformed(evt);
  143. }
  144. });
  145. jToolBar1.add(users);
  146. jLabel2.setText(bundle.getString("HistoryPanel.jLabel2.text")); // NOI18N
  147. jLabel2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
  148. jLabel2.setMaximumSize(new java.awt.Dimension(333, 20));
  149. jLabel2.setMinimumSize(new java.awt.Dimension(100, 20));
  150. jLabel2.setName("jLabel2"); // NOI18N
  151. jLabel2.setPreferredSize(new java.awt.Dimension(120, 20));
  152. jToolBar1.add(jLabel2);
  153. groups.setMaximumSize(new java.awt.Dimension(333, 20));
  154. groups.setMinimumSize(new java.awt.Dimension(100, 20));
  155. groups.setName("groups"); // NOI18N
  156. groups.setPreferredSize(new java.awt.Dimension(120, 20));
  157. groups.addActionListener(new java.awt.event.ActionListener() {
  158. public void actionPerformed(java.awt.event.ActionEvent evt) {
  159. groupsActionPerformed(evt);
  160. }
  161. });
  162. jToolBar1.add(groups);
  163. jSeparator6.setName("jSeparator6"); // NOI18N
  164. jToolBar1.add(jSeparator6);
  165. jButton1.setText(bundle.getString("HistoryPanel.jButton1.text")); // NOI18N
  166. jButton1.setFocusable(false);
  167. jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
  168. jButton1.setMaximumSize(new java.awt.Dimension(333, 20));
  169. jButton1.setMinimumSize(new java.awt.Dimension(100, 20));
  170. jButton1.setName("jButton1"); // NOI18N
  171. jButton1.setPreferredSize(new java.awt.Dimension(120, 20));
  172. jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
  173. jButton1.addActionListener(new java.awt.event.ActionListener() {
  174. public void actionPerformed(java.awt.event.ActionEvent evt) {
  175. jButton1ActionPerformed(evt);
  176. }
  177. });
  178. jToolBar1.add(jButton1);
  179. prinitingComboBox1.setMaximumSize(new java.awt.Dimension(333, 20));
  180. prinitingComboBox1.setMinimumSize(new java.awt.Dimension(100, 20));
  181. prinitingComboBox1.setName("prinitingComboBox1"); // NOI18N
  182. prinitingComboBox1.setPreferredSize(new java.awt.Dimension(120, 20));
  183. jToolBar1.add(prinitingComboBox1);
  184. jScrollPane1.setName("jScrollPane1"); // NOI18N
  185. jTable1.setAutoCreateRowSorter(true);
  186. jTable1.setModel(new javax.swing.table.DefaultTableModel(
  187. new Object [][] {
  188. {},
  189. {},
  190. {},
  191. {}
  192. },
  193. new String [] {
  194. }
  195. ));
  196. jTable1.setName("jTable1"); // NOI18N
  197. jScrollPane1.setViewportView(jTable1);
  198. jToolBar2.setFloatable(false);
  199. jToolBar2.setRollover(true);
  200. jToolBar2.setName("jToolBar2"); // NOI18N
  201. jLabel3.setText(bundle.getString("HistoryPanel.jLabel3.text")); // NOI18N
  202. jLabel3.setMaximumSize(new java.awt.Dimension(333, 20));
  203. jLabel3.setName("jLabel3"); // NOI18N
  204. jLabel3.setPreferredSize(new java.awt.Dimension(100, 20));
  205. jToolBar2.add(jLabel3);
  206. timeframeChooser1.setName("timeframeChooser1"); // NOI18N
  207. jToolBar2.add(timeframeChooser1);
  208. javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
  209. jPanel1.setLayout(jPanel1Layout);
  210. jPanel1Layout.setHorizontalGroup(
  211. jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  212. .addComponent(jToolBar2, javax.swing.GroupLayout.DEFAULT_SIZE, 606, Short.MAX_VALUE)
  213. .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 606, Short.MAX_VALUE)
  214. .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 606, Short.MAX_VALUE)
  215. );
  216. jPanel1Layout.setVerticalGroup(
  217. jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  218. .addGroup(jPanel1Layout.createSequentialGroup()
  219. .addComponent(jToolBar2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
  220. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  221. .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
  222. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  223. .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 258, Short.MAX_VALUE))
  224. );
  225. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
  226. this.setLayout(layout);
  227. layout.setHorizontalGroup(
  228. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  229. .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  230. );
  231. layout.setVerticalGroup(
  232. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  233. .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  234. );
  235. }// </editor-fold>//GEN-END:initComponents
  236. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
  237. try {
  238. if (users.getSelectedIndex() > 0 && groups.getSelectedIndex() > 0) {
  239. refresh((User) users.getSelectedItem(), (Group) groups.getSelectedItem());
  240. } else if (groups.getSelectedIndex() > 0) {
  241. refresh(null, (Group) groups.getSelectedItem());
  242. } else if (users.getSelectedIndex() > 0) {
  243. refresh((User) users.getSelectedItem(), null);
  244. } else {
  245. refresh(null, null);
  246. }
  247. } catch (Exception ignore) {
  248. refresh(null, null);
  249. }
  250. }//GEN-LAST:event_jButton1ActionPerformed
  251. private void groupsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_groupsActionPerformed
  252. }//GEN-LAST:event_groupsActionPerformed
  253. private void usersActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_usersActionPerformed
  254. }//GEN-LAST:event_usersActionPerformed
  255. // Variables declaration - do not modify//GEN-BEGIN:variables
  256. private javax.swing.JComboBox groups;
  257. private javax.swing.JButton jButton1;
  258. private javax.swing.JLabel jLabel1;
  259. private javax.swing.JLabel jLabel2;
  260. private javax.swing.JLabel jLabel3;
  261. private javax.swing.JPanel jPanel1;
  262. private javax.swing.JScrollPane jScrollPane1;
  263. private javax.swing.JToolBar.Separator jSeparator6;
  264. private javax.swing.JTable jTable1;
  265. private javax.swing.JToolBar jToolBar1;
  266. private javax.swing.JToolBar jToolBar2;
  267. private mpv5.ui.beans.PrinitingComboBox prinitingComboBox1;
  268. private mpv5.ui.beans.TimeframeChooser timeframeChooser1;
  269. private javax.swing.JComboBox users;
  270. // End of variables declaration//GEN-END:variables
  271. private void refresh(User forUser, Group forGroup) {
  272. QueryCriteria2 dh = new QueryCriteria2();
  273. Object[][] d = new Object[0][0];
  274. if (forUser != null && !forUser.equals(User.DEFAULT)) {
  275. try {
  276. dh.and(new QueryParameter(Context.getHistory(), forUser.getType() + "name", forUser.getName(), QueryParameter.EQUALS));
  277. if (forGroup != null && !forGroup.__getCname().equals("")) {
  278. dh.and(new QueryParameter(Context.getHistory(), forGroup.getDbIdentity() + "ids", forGroup.__getIDS(), QueryParameter.EQUALS));
  279. }
  280. Context c = Context.getHistory();
  281. c.addReference(Context.getGroup());
  282. d = QueryHandler.instanceOf().clone(c).select(Context.DETAILS_HISTORY, dh, timeframeChooser1.getTime()).getData();
  283. } catch (NodataFoundException ex) {
  284. Log.Debug(this, ex.getMessage());
  285. }
  286. } else if (forGroup != null && !forGroup.__getCname().equals("")) {
  287. try {
  288. dh.and(new QueryParameter(Context.getHistory(), forGroup.getDbIdentity() + "ids", forGroup.__getIDS(), QueryParameter.EQUALS));
  289. Context c = Context.getHistory();
  290. c.addReference(Context.getGroup());
  291. d = QueryHandler.instanceOf().clone(c).select(Context.DETAILS_HISTORY, dh, timeframeChooser1.getTime()).getData();
  292. } catch (NodataFoundException ex) {
  293. Log.Debug(this, ex.getMessage());
  294. }
  295. } else {
  296. try {
  297. Context c = Context.getHistory();
  298. c.addReference(Context.getGroup());
  299. d = QueryHandler.instanceOf().clone(c).select(Context.DETAILS_HISTORY, dh, timeframeChooser1.getTime()).getData();
  300. } catch (NodataFoundException ex) {
  301. Log.Debug(this, ex.getMessage());
  302. }
  303. }
  304. 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}));
  305. TableFormat.stripColumn(jTable1, 0);
  306. // TableFormat.stripColumn(jTable1, 3);
  307. // TableFormat.stripColumn(jTable1, 4);
  308. }
  309. public void refresh() {
  310. refresh(null,null);
  311. }
  312. public void flush() {
  313. jTable1.setModel(new DefaultTableModel());
  314. }
  315. }