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