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