PageRenderTime 35ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 208 lines | 148 code | 26 blank | 34 comment | 10 complexity | 399135183084abec86aadfe1ee27a34e 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.ArrayList;
  25. import java.util.List;
  26. import javax.swing.JPanel;
  27. import mpv5.data.PropertyStore;
  28. import mpv5.globals.LocalSettings;
  29. import mpv5.globals.Messages;
  30. import mpv5.ui.dialogs.ControlApplet;
  31. import mpv5.ui.dialogs.Popup;
  32. import mpv5.usermanagement.MPSecurityManager;
  33. import mpv5.utils.models.MPTableModel;
  34. import mpv5.utils.tables.TableFormat;
  35. /**
  36. *
  37. *
  38. */
  39. public class ControlPanel_AdvancedLocalProperties extends javax.swing.JPanel implements ControlApplet {
  40. private static final long serialVersionUID = 1L;
  41. private static ControlPanel_AdvancedLocalProperties ident;
  42. private PropertyStore oldvals;
  43. /** Creates new form GeneralListPanel */
  44. public ControlPanel_AdvancedLocalProperties() {
  45. if (MPSecurityManager.checkAdminAccess()) {
  46. initComponents();
  47. setData(LocalSettings.getPropertyStore());
  48. }
  49. }
  50. public void setData(PropertyStore vals) {
  51. oldvals = vals;
  52. List<String[]> data = vals.getList();
  53. Object[][] list = new Object[data.size()][2];
  54. for (int i = 0; i < data.size(); i++) {
  55. String[] strings = data.get(i);
  56. list[i][0] = strings[0].toUpperCase();
  57. list[i][1] = strings[1];
  58. }
  59. MPTableModel mod = new MPTableModel(list, new String[]{Messages.PROPERTY.getValue(), Messages.VALUE.getValue()});
  60. mod.setCanEdits(new boolean[]{false, true, false});
  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_AdvancedLocalProperties.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. {},
  86. {},
  87. {},
  88. {}
  89. },
  90. new String [] {
  91. }
  92. ));
  93. jTable1.setName("jTable1"); // NOI18N
  94. jScrollPane1.setViewportView(jTable1);
  95. add(jScrollPane1);
  96. jPanel1.setBackground(new java.awt.Color(255, 255, 255));
  97. jPanel1.setName("jPanel1"); // NOI18N
  98. jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
  99. jButton1.setText(bundle.getString("ControlPanel_AdvancedLocalProperties.jButton1.text")); // NOI18N
  100. jButton1.setName("jButton1"); // NOI18N
  101. jButton1.addActionListener(new java.awt.event.ActionListener() {
  102. public void actionPerformed(java.awt.event.ActionEvent evt) {
  103. jButton1ActionPerformed(evt);
  104. }
  105. });
  106. jPanel1.add(jButton1);
  107. jButton2.setText(bundle.getString("ControlPanel_AdvancedLocalProperties.jButton2.text")); // NOI18N
  108. jButton2.setName("jButton2"); // NOI18N
  109. jButton2.addActionListener(new java.awt.event.ActionListener() {
  110. public void actionPerformed(java.awt.event.ActionEvent evt) {
  111. jButton2ActionPerformed(evt);
  112. }
  113. });
  114. jPanel1.add(jButton2);
  115. jButton3.setText(bundle.getString("ControlPanel_AdvancedLocalProperties.jButton3.text")); // NOI18N
  116. jButton3.setName("jButton3"); // NOI18N
  117. jButton3.addActionListener(new java.awt.event.ActionListener() {
  118. public void actionPerformed(java.awt.event.ActionEvent evt) {
  119. jButton3ActionPerformed(evt);
  120. }
  121. });
  122. jPanel1.add(jButton3);
  123. add(jPanel1);
  124. }// </editor-fold>//GEN-END:initComponents
  125. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
  126. if (Popup.Y_N_dialog(Messages.ADVANCED_SETTINGS_SAVE, Messages.WARNING)) {
  127. setSettings();
  128. LocalSettings.apply();
  129. LocalSettings.save();
  130. }
  131. }//GEN-LAST:event_jButton1ActionPerformed
  132. private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
  133. setSettings();
  134. LocalSettings.apply();
  135. }//GEN-LAST:event_jButton2ActionPerformed
  136. private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
  137. reset();
  138. }//GEN-LAST:event_jButton3ActionPerformed
  139. // Variables declaration - do not modify//GEN-BEGIN:variables
  140. private javax.swing.JButton jButton1;
  141. private javax.swing.JButton jButton2;
  142. private javax.swing.JButton jButton3;
  143. private javax.swing.JPanel jPanel1;
  144. private javax.swing.JScrollPane jScrollPane1;
  145. private javax.swing.JTable jTable1;
  146. // End of variables declaration//GEN-END:variables
  147. @Override
  148. public Component getAndRemoveActionPanel() {
  149. remove(jPanel1);
  150. validate();
  151. return jPanel1;
  152. }
  153. @Override
  154. public void setValues(PropertyStore values) {
  155. setData(values);
  156. }
  157. @Override
  158. public String getUname() {
  159. return "advancedlocalsettings";
  160. }
  161. @Override
  162. public void reset() {
  163. if (oldvals != null) {
  164. setValues(oldvals);
  165. }
  166. }
  167. private void setSettings() {
  168. if (jTable1.getCellEditor() != null) {
  169. try {
  170. jTable1.getCellEditor().stopCellEditing();
  171. } catch (Exception e) {
  172. }
  173. }
  174. MPTableModel data = (MPTableModel) jTable1.getModel();
  175. int i = data.getRowCount();
  176. for (int j = 0; j < i; j++) {
  177. String value = String.valueOf(data.getValueAt(j, 1));
  178. String key = String.valueOf(data.getValueAt(j, 0)).toLowerCase();
  179. if (!key.equals("null") && key.length() > 0)LocalSettings.setProperty(key, value);
  180. }
  181. }
  182. }