PageRenderTime 244ms CodeModel.GetById 106ms app.highlight 67ms RepoModel.GetById 68ms app.codeStats 0ms

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

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