PageRenderTime 27ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/src/mpv5/ui/panels/TrashPanel.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 177 lines | 119 code | 23 blank | 35 comment | 5 complexity | 0a163a4a7275dedfab0185240c4acc74 MD5 | raw file
Possible License(s): LGPL-3.0, Apache-2.0, GPL-3.0, GPL-2.0, AGPL-3.0, JSON, BSD-3-Clause
  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. * GeneralListPanel.java
  19. *
  20. * Created on 03.04.2009, 15:26:37
  21. */
  22. package mpv5.ui.panels;
  23. import java.awt.Component;
  24. import java.awt.event.ActionEvent;
  25. import java.awt.event.ActionListener;
  26. import javax.swing.JComponent;
  27. import javax.swing.table.TableCellRenderer;
  28. import mpv5.handler.TrashHandler;
  29. import mpv5.globals.Headers;
  30. import mpv5.globals.Messages;
  31. import mpv5.ui.misc.MPTable;
  32. import mpv5.ui.popups.TablePopUp;
  33. import mpv5.utils.models.MPTableModel;
  34. import mpv5.utils.tables.TableFormat;
  35. import mpv5.ui.misc.TableViewPersistenceHandler;
  36. /**
  37. *
  38. *
  39. */
  40. public class TrashPanel extends javax.swing.JPanel {
  41. private static final long serialVersionUID = 1L;
  42. private static TrashPanel ident;
  43. private java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle();
  44. public static TrashPanel instanceOf() {
  45. if (ident == null) {
  46. ident = new TrashPanel();
  47. }
  48. ident.setData();
  49. return ident;
  50. }
  51. private TablePopUp tablePopUp;
  52. /** Creates new form GeneralListPanel */
  53. private TrashPanel() {
  54. initComponents();
  55. setName("trashpanel");
  56. setData();
  57. tablePopUp = new TablePopUp(jTable1, new String[]{Messages.DELETE.toString(), Messages.RESTORE.toString(), null, Messages.RELOAD.getValue()}, new ActionListener[]{new ActionListener() {
  58. public void actionPerformed(ActionEvent e) {
  59. for (int i = 0; i < jTable1.getSelectedRows().length; i++) {
  60. try {
  61. int id = Integer.valueOf(jTable1.getModel().getValueAt(jTable1.getSelectedRows()[i], 1).toString());
  62. String type = String.valueOf(jTable1.getModel().getValueAt(jTable1.getSelectedRows()[i], 0).toString());
  63. TrashHandler.delete(type, id, String.valueOf(jTable1.getModel().getValueAt(jTable1.getSelectedRows()[i], 2).toString()) + Messages.DELETED);
  64. } catch (Exception numberFormatException) {
  65. }
  66. } setData();
  67. }
  68. }, new ActionListener() {
  69. public void actionPerformed(ActionEvent e) {
  70. for (int i = 0; i < jTable1.getSelectedRows().length; i++) {
  71. try {
  72. int id = Integer.valueOf(jTable1.getModel().getValueAt(jTable1.getSelectedRows()[i], 1).toString());
  73. String type = String.valueOf(jTable1.getModel().getValueAt(jTable1.getSelectedRows()[i], 0).toString());
  74. TrashHandler.restore(type, id, String.valueOf(jTable1.getModel().getValueAt(jTable1.getSelectedRows()[i], 2).toString()) + Messages.RESTORED);
  75. } catch (Exception numberFormatException) {
  76. }
  77. }setData();
  78. }
  79. }, null, new ActionListener() {
  80. public void actionPerformed(ActionEvent e) {
  81. setData();
  82. }
  83. }});
  84. ((MPTable) jTable1).setPersistanceHandler(new TableViewPersistenceHandler((MPTable)jTable1, this));
  85. }
  86. public void setData() {
  87. jTable1.setModel(new MPTableModel(TrashHandler.getData(), Headers.TRASHBIN));
  88. }
  89. /** This method is called from within the constructor to
  90. * initialize the form.
  91. * WARNING: Do NOT modify this code. The content of this method is
  92. * always regenerated by the Form Editor.
  93. */
  94. @SuppressWarnings("unchecked")
  95. // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  96. private void initComponents() {
  97. jPopupMenu1 = new javax.swing.JPopupMenu();
  98. jScrollPane1 = new javax.swing.JScrollPane();
  99. jTable1 = new mpv5.ui.misc.MPTable(this) {
  100. public Component prepareRenderer(TableCellRenderer renderer,
  101. int rowIndex, int vColIndex) {
  102. Component c = super.prepareRenderer(renderer, rowIndex, vColIndex);
  103. if (c instanceof JComponent) {
  104. JComponent jc = (JComponent)c;
  105. jc.setToolTipText(String.valueOf(getValueAt(rowIndex, vColIndex)));
  106. }
  107. return c;
  108. }
  109. };
  110. jPopupMenu1.setName("jPopupMenu1"); // NOI18N
  111. java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle(); // NOI18N
  112. setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("TrashPanel.border.title"))); // NOI18N
  113. setName("Form"); // NOI18N
  114. jScrollPane1.setName("jScrollPane1"); // NOI18N
  115. jTable1.setModel(new javax.swing.table.DefaultTableModel(
  116. new Object [][] {
  117. {},
  118. {},
  119. {},
  120. {}
  121. },
  122. new String [] {
  123. }
  124. ));
  125. jTable1.setDragEnabled(true);
  126. jTable1.setFillsViewportHeight(true);
  127. jTable1.setName("jTable1"); // NOI18N
  128. jTable1.setSurrendersFocusOnKeystroke(true);
  129. jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
  130. public void mouseReleased(java.awt.event.MouseEvent evt) {
  131. jTable1MouseReleased(evt);
  132. }
  133. });
  134. jScrollPane1.setViewportView(jTable1);
  135. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
  136. this.setLayout(layout);
  137. layout.setHorizontalGroup(
  138. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  139. .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 399, Short.MAX_VALUE)
  140. );
  141. layout.setVerticalGroup(
  142. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  143. .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 289, Short.MAX_VALUE)
  144. );
  145. }// </editor-fold>//GEN-END:initComponents
  146. private void jTable1MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseReleased
  147. //tablePopUp.show(jTable1, evt.getX(),evt.getY());
  148. }//GEN-LAST:event_jTable1MouseReleased
  149. // Variables declaration - do not modify//GEN-BEGIN:variables
  150. private javax.swing.JPopupMenu jPopupMenu1;
  151. private javax.swing.JScrollPane jScrollPane1;
  152. private javax.swing.JTable jTable1;
  153. // End of variables declaration//GEN-END:variables
  154. }