PageRenderTime 336ms CodeModel.GetById 81ms app.highlight 205ms RepoModel.GetById 37ms app.codeStats 1ms

/src/mpv5/ui/dialogs/subcomponents/ControlPanel_AdvancedUserProperties.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 251 lines | 185 code | 32 blank | 34 comment | 12 complexity | f0653b01da2dfe9553345acd262d0089 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.dialogs.subcomponents;
 23
 24import java.awt.Component;
 25import java.awt.event.ActionEvent;
 26import java.awt.event.ActionListener;
 27import java.util.ArrayList;
 28import java.util.List;
 29import javax.swing.JPanel;
 30import javax.swing.JTable;
 31import javax.swing.RowFilter;
 32import javax.swing.table.TableModel;
 33import javax.swing.table.TableRowSorter;
 34import mpv5.data.PropertyStore;
 35import mpv5.db.objects.User;
 36import mpv5.globals.LocalSettings;
 37import mpv5.globals.Messages;
 38import mpv5.ui.dialogs.ControlApplet;
 39import mpv5.ui.dialogs.Popup;
 40import mpv5.usermanagement.MPSecurityManager;
 41import mpv5.utils.models.MPTableModel;
 42import mpv5.utils.tables.TableFormat;
 43
 44/**
 45 *
 46 *  
 47 */
 48public class ControlPanel_AdvancedUserProperties extends javax.swing.JPanel implements ControlApplet {
 49
 50    private static final long serialVersionUID = 1L;
 51    private static ControlPanel_AdvancedUserProperties ident;
 52    private PropertyStore oldvals;
 53    private java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle();
 54
 55    /** Creates new form GeneralListPanel */
 56    public ControlPanel_AdvancedUserProperties() {
 57        initComponents();
 58        setData(User.getCurrentUser().getProperties());
 59        setupFilter();
 60    }
 61
 62    public void setData(PropertyStore vals) {
 63        oldvals = vals;
 64        List<String[]> data = vals.getList();
 65        Object[][] list = new Object[data.size() + 10][2];
 66        for (int i = 0; i < data.size(); i++) {
 67            String[] strings = data.get(i);
 68            list[i][0] = strings[0].toUpperCase();
 69            list[i][1] = strings[1];
 70        }
 71        MPTableModel mod = new MPTableModel(list, new String[]{Messages.PROPERTY.getValue(), Messages.VALUE.getValue()});
 72        mod.setCanEdits(new boolean[]{true, true});
 73        mod.addRow(5);
 74        jTable1.setModel(mod);
 75
 76    }
 77
 78    /** This method is called from within the constructor to
 79     * initialize the form.
 80     * WARNING: Do NOT modify this code. The content of this method is
 81     * always regenerated by the Form Editor.
 82     */
 83    @SuppressWarnings("unchecked")
 84    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
 85    private void initComponents() {
 86
 87        jPanel2 = new javax.swing.JPanel();
 88        filter = new mpv5.ui.beans.LabeledTextField();
 89        jScrollPane1 = new javax.swing.JScrollPane();
 90        jTable1 = new javax.swing.JTable();
 91        jPanel1 = new javax.swing.JPanel();
 92        jButton1 = new javax.swing.JButton();
 93        jButton2 = new javax.swing.JButton();
 94        jButton3 = new javax.swing.JButton();
 95
 96        java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle(); // NOI18N
 97        setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("ControlPanel_AdvancedUserProperties.border.title"))); // NOI18N
 98        setName("Form"); // NOI18N
 99        setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.PAGE_AXIS));
100
101        jPanel2.setMaximumSize(new java.awt.Dimension(2147483647, 20));
102        jPanel2.setName("jPanel2"); // NOI18N
103        jPanel2.setLayout(new java.awt.BorderLayout());
104
105        filter.set_Label(bundle.getString("ControlPanel_AdvancedUserProperties.filter._Label")); // NOI18N
106        filter.setName("filter"); // NOI18N
107        jPanel2.add(filter, java.awt.BorderLayout.CENTER);
108
109        add(jPanel2);
110
111        jScrollPane1.setName("jScrollPane1"); // NOI18N
112
113        jTable1.setAutoCreateRowSorter(true);
114        jTable1.setModel(new javax.swing.table.DefaultTableModel(
115            new Object [][] {
116                {},
117                {},
118                {},
119                {}
120            },
121            new String [] {
122
123            }
124        ));
125        jTable1.setName("jTable1"); // NOI18N
126        jScrollPane1.setViewportView(jTable1);
127
128        add(jScrollPane1);
129
130        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
131        jPanel1.setName("jPanel1"); // NOI18N
132        jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
133
134        jButton1.setText(bundle.getString("ControlPanel_AdvancedUserProperties.jButton1.text")); // NOI18N
135        jButton1.setName("jButton1"); // NOI18N
136        jButton1.addActionListener(new java.awt.event.ActionListener() {
137            public void actionPerformed(java.awt.event.ActionEvent evt) {
138                jButton1ActionPerformed(evt);
139            }
140        });
141        jPanel1.add(jButton1);
142
143        jButton2.setText(bundle.getString("ControlPanel_AdvancedUserProperties.jButton2.text")); // NOI18N
144        jButton2.setName("jButton2"); // NOI18N
145        jButton2.addActionListener(new java.awt.event.ActionListener() {
146            public void actionPerformed(java.awt.event.ActionEvent evt) {
147                jButton2ActionPerformed(evt);
148            }
149        });
150        jPanel1.add(jButton2);
151
152        jButton3.setText(bundle.getString("ControlPanel_AdvancedUserProperties.jButton3.text")); // NOI18N
153        jButton3.setName("jButton3"); // NOI18N
154        jButton3.addActionListener(new java.awt.event.ActionListener() {
155            public void actionPerformed(java.awt.event.ActionEvent evt) {
156                jButton3ActionPerformed(evt);
157            }
158        });
159        jPanel1.add(jButton3);
160
161        add(jPanel1);
162    }// </editor-fold>//GEN-END:initComponents
163
164    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
165        if (Popup.Y_N_dialog(Messages.ADVANCED_SETTINGS_SAVE, Messages.WARNING)) {
166            setSettings();
167            User.getCurrentUser().saveProperties();
168            setData(User.getCurrentUser().getProperties());
169        }
170}//GEN-LAST:event_jButton1ActionPerformed
171
172    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
173        setSettings();
174        setData(User.getCurrentUser().getProperties());
175}//GEN-LAST:event_jButton2ActionPerformed
176
177    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
178        reset();
179}//GEN-LAST:event_jButton3ActionPerformed
180    // Variables declaration - do not modify//GEN-BEGIN:variables
181    private mpv5.ui.beans.LabeledTextField filter;
182    private javax.swing.JButton jButton1;
183    private javax.swing.JButton jButton2;
184    private javax.swing.JButton jButton3;
185    private javax.swing.JPanel jPanel1;
186    private javax.swing.JPanel jPanel2;
187    private javax.swing.JScrollPane jScrollPane1;
188    private javax.swing.JTable jTable1;
189    // End of variables declaration//GEN-END:variables
190
191    @Override
192    public Component getAndRemoveActionPanel() {
193        remove(jPanel1);
194        validate();
195        return jPanel1;
196    }
197
198    @Override
199    public void setValues(PropertyStore values) {
200        setData(values);
201    }
202
203    @Override
204    public String getUname() {
205        return "advancedusersettings";
206    }
207
208    @Override
209    public void reset() {
210        if (oldvals != null) {
211            setValues(oldvals);
212        }
213    }
214
215    private void setSettings() {
216        if (jTable1.getCellEditor() != null) {
217            try {
218                jTable1.getCellEditor().stopCellEditing();
219            } catch (Exception e) {
220            }
221        }
222        MPTableModel data = (MPTableModel) jTable1.getModel();
223        int i = data.getRowCount();
224        for (int j = 0; j < i; j++) {
225            String value = String.valueOf(data.getValueAt(j, 1));
226            String key = String.valueOf(data.getValueAt(j, 0)).toLowerCase();
227            if (!key.equals("null") && key.length() > 0) {
228                User.getCurrentUser().getProperties().changeProperty(key, value);
229            }
230        }
231    }
232
233    private void setupFilter() {
234        final JTable table = jTable1;
235        final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(table.getModel());
236        table.setRowSorter(sorter);
237
238        filter.getTextField().addActionListener(new ActionListener() {
239
240            @Override
241            public void actionPerformed(ActionEvent e) {
242                String text = filter.getText();
243                if (text.length() == 0) {
244                    sorter.setRowFilter(null);
245                } else {
246                    sorter.setRowFilter(RowFilter.regexFilter(text));
247                }
248            }
249        });
250    }
251}