PageRenderTime 43ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 336 lines | 277 code | 49 blank | 10 comment | 6 complexity | 727899a456b7dafb26fe6dfe95ee9fda 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. package mpv5.ui.dialogs.subcomponents;
  2. import java.awt.Component;
  3. import java.util.HashMap;
  4. import java.util.Iterator;
  5. import java.util.Map.Entry;
  6. import javax.swing.SwingUtilities;
  7. import mpv5.data.PropertyStore;
  8. import mpv5.db.common.Context;
  9. import mpv5.db.common.QueryHandler;
  10. import mpv5.db.objects.HistoryItem;
  11. import mpv5.db.objects.User;
  12. import mpv5.globals.LocalSettings;
  13. import mpv5.globals.Messages;
  14. import mpv5.logging.Log;
  15. import mpv5.ui.beans.LabeledTextField;
  16. import mpv5.ui.dialogs.ControlApplet;
  17. import mpv5.ui.dialogs.Popup;
  18. import mpv5.usermanagement.MPSecurityManager;
  19. import mpv5.utils.text.TypeConversion;
  20. import mpv5.utils.ui.PanelUtils;
  21. /**
  22. *
  23. *
  24. */
  25. public final class ControlPanel_Company extends javax.swing.JPanel implements ControlApplet {
  26. private static final long serialVersionUID = 1L;
  27. /**
  28. * This unique name identifies this control applet
  29. */
  30. public final String UNAME = "companyinfo";
  31. private PropertyStore oldvalues;
  32. private static ControlPanel_Company ident;
  33. public ControlPanel_Company() {
  34. initComponents();
  35. setValues(User.getCurrentUser().getProperties().getProperties("companyinfo."));
  36. setVisible(true);
  37. }
  38. // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  39. private void initComponents() {
  40. jPanel2 = new javax.swing.JPanel();
  41. jPanel3 = new javax.swing.JPanel();
  42. business = new mpv5.ui.beans.LabeledTextField();
  43. name = new mpv5.ui.beans.LabeledTextField();
  44. firstname = new mpv5.ui.beans.LabeledTextField();
  45. street = new mpv5.ui.beans.LabeledTextField();
  46. city = new mpv5.ui.beans.LabeledTextField();
  47. zip = new mpv5.ui.beans.LabeledTextField();
  48. country = new mpv5.ui.beans.LabeledTextField();
  49. phoneprefix = new mpv5.ui.beans.LabeledTextField();
  50. phone = new mpv5.ui.beans.LabeledTextField();
  51. email = new mpv5.ui.beans.LabeledTextField();
  52. fax = new mpv5.ui.beans.LabeledTextField();
  53. taxauthority = new mpv5.ui.beans.LabeledTextField();
  54. taxmandant = new mpv5.ui.beans.LabeledTextField();
  55. taxadvsior = new mpv5.ui.beans.LabeledTextField();
  56. taxadvjob = new mpv5.ui.beans.LabeledTextField();
  57. taxnumber = new mpv5.ui.beans.LabeledTextField();
  58. bankname = new mpv5.ui.beans.LabeledTextField();
  59. banknumber = new mpv5.ui.beans.LabeledTextField();
  60. account = new mpv5.ui.beans.LabeledTextField();
  61. account1 = new mpv5.ui.beans.LabeledTextField();
  62. jScrollPane1 = new javax.swing.JScrollPane();
  63. jTextArea1 = new javax.swing.JTextArea();
  64. jPanel1 = new javax.swing.JPanel();
  65. jButton2 = new javax.swing.JButton();
  66. jButton1 = new javax.swing.JButton();
  67. jButton3 = new javax.swing.JButton();
  68. setBackground(new java.awt.Color(255, 255, 255));
  69. setName("Form"); // NOI18N
  70. setLayout(new java.awt.BorderLayout());
  71. java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle(); // NOI18N
  72. jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("ControlPanel_Company.jPanel2.border.title"))); // NOI18N
  73. jPanel2.setName("jPanel2"); // NOI18N
  74. jPanel3.setName("jPanel3"); // NOI18N
  75. jPanel3.setLayout(new java.awt.GridLayout(10, 2, 5, 1));
  76. business.set_Label(bundle.getString("ControlPanel_Company.business._Label")); // NOI18N
  77. business.setName("business"); // NOI18N
  78. jPanel3.add(business);
  79. name.set_Label(bundle.getString("ControlPanel_Company.name._Label")); // NOI18N
  80. name.setName("name"); // NOI18N
  81. jPanel3.add(name);
  82. firstname.set_Label(bundle.getString("ControlPanel_Company.firstname._Label")); // NOI18N
  83. firstname.setName("firstname"); // NOI18N
  84. jPanel3.add(firstname);
  85. street.set_Label(bundle.getString("ControlPanel_Company.street._Label")); // NOI18N
  86. street.setName("street"); // NOI18N
  87. jPanel3.add(street);
  88. city.set_Label(bundle.getString("ControlPanel_Company.city._Label")); // NOI18N
  89. city.setName("city"); // NOI18N
  90. jPanel3.add(city);
  91. zip.set_Label(bundle.getString("ControlPanel_Company.zip._Label")); // NOI18N
  92. zip.setName("zip"); // NOI18N
  93. jPanel3.add(zip);
  94. country.set_Label(bundle.getString("ControlPanel_Company.country._Label")); // NOI18N
  95. country.setName("country"); // NOI18N
  96. jPanel3.add(country);
  97. phoneprefix.set_Label(bundle.getString("ControlPanel_Company.phoneprefix._Label")); // NOI18N
  98. phoneprefix.setName("phoneprefix"); // NOI18N
  99. jPanel3.add(phoneprefix);
  100. phone.set_Label(bundle.getString("ControlPanel_Company.phone._Label")); // NOI18N
  101. phone.setName("phone"); // NOI18N
  102. jPanel3.add(phone);
  103. email.set_Label(bundle.getString("ControlPanel_Company.email._Label")); // NOI18N
  104. email.setName("email"); // NOI18N
  105. jPanel3.add(email);
  106. fax.set_Label(bundle.getString("ControlPanel_Company.fax._Label")); // NOI18N
  107. fax.setName("fax"); // NOI18N
  108. jPanel3.add(fax);
  109. taxauthority.set_Label(bundle.getString("ControlPanel_Company.taxauthority._Label")); // NOI18N
  110. taxauthority.setName("taxauthority"); // NOI18N
  111. jPanel3.add(taxauthority);
  112. taxmandant.set_Label(bundle.getString("ControlPanel_Company.taxmandant._Label")); // NOI18N
  113. taxmandant.setName("taxmandant"); // NOI18N
  114. jPanel3.add(taxmandant);
  115. taxadvsior.set_Label(bundle.getString("ControlPanel_Company.taxadvsior._Label")); // NOI18N
  116. taxadvsior.setName("taxadvsior"); // NOI18N
  117. jPanel3.add(taxadvsior);
  118. taxadvjob.set_Label(bundle.getString("ControlPanel_Company.taxadvjob._Label")); // NOI18N
  119. taxadvjob.setName("taxadvjob"); // NOI18N
  120. jPanel3.add(taxadvjob);
  121. taxnumber.set_Label(bundle.getString("ControlPanel_Company.taxnumber._Label")); // NOI18N
  122. taxnumber.setName("taxnumber"); // NOI18N
  123. jPanel3.add(taxnumber);
  124. bankname.set_Label(bundle.getString("ControlPanel_Company.bankname._Label")); // NOI18N
  125. bankname.setName("bankname"); // NOI18N
  126. jPanel3.add(bankname);
  127. banknumber.set_Label(bundle.getString("ControlPanel_Company.banknumber._Label")); // NOI18N
  128. banknumber.setName("banknumber"); // NOI18N
  129. jPanel3.add(banknumber);
  130. account.set_Label(bundle.getString("ControlPanel_Company.account._Label")); // NOI18N
  131. account.setName("account"); // NOI18N
  132. jPanel3.add(account);
  133. account1.set_Label(bundle.getString("ControlPanel_Company.account1._Label")); // NOI18N
  134. account1.setName("account1"); // NOI18N
  135. jPanel3.add(account1);
  136. jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
  137. jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
  138. jScrollPane1.setName("jScrollPane1"); // NOI18N
  139. jTextArea1.setBackground(new java.awt.Color(240, 240, 240));
  140. jTextArea1.setColumns(20);
  141. jTextArea1.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
  142. jTextArea1.setLineWrap(true);
  143. jTextArea1.setRows(5);
  144. jTextArea1.setText(bundle.getString("ControlPanel_Company.jTextArea1.text")); // NOI18N
  145. jTextArea1.setWrapStyleWord(true);
  146. jTextArea1.setName("jTextArea1"); // NOI18N
  147. jTextArea1.setOpaque(false);
  148. jScrollPane1.setViewportView(jTextArea1);
  149. javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
  150. jPanel2.setLayout(jPanel2Layout);
  151. jPanel2Layout.setHorizontalGroup(
  152. jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  153. .addGroup(jPanel2Layout.createSequentialGroup()
  154. .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  155. .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 614, javax.swing.GroupLayout.PREFERRED_SIZE)
  156. .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 614, javax.swing.GroupLayout.PREFERRED_SIZE))
  157. .addContainerGap(90, Short.MAX_VALUE))
  158. );
  159. jPanel2Layout.setVerticalGroup(
  160. jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  161. .addGroup(jPanel2Layout.createSequentialGroup()
  162. .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
  163. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  164. .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  165. .addContainerGap(51, Short.MAX_VALUE))
  166. );
  167. add(jPanel2, java.awt.BorderLayout.CENTER);
  168. jPanel1.setBackground(new java.awt.Color(255, 255, 255));
  169. jPanel1.setName("jPanel1"); // NOI18N
  170. jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
  171. jButton2.setBackground(new java.awt.Color(255, 153, 153));
  172. jButton2.setText(bundle.getString("ControlPanel_Company.jButton2.text")); // NOI18N
  173. jButton2.setName("jButton2"); // NOI18N
  174. jButton2.addActionListener(new java.awt.event.ActionListener() {
  175. public void actionPerformed(java.awt.event.ActionEvent evt) {
  176. jButton2ActionPerformed(evt);
  177. }
  178. });
  179. jPanel1.add(jButton2);
  180. jButton1.setText(bundle.getString("ControlPanel_Company.jButton1.text")); // NOI18N
  181. jButton1.setName("jButton1"); // NOI18N
  182. jButton1.addActionListener(new java.awt.event.ActionListener() {
  183. public void actionPerformed(java.awt.event.ActionEvent evt) {
  184. jButton1ActionPerformed(evt);
  185. }
  186. });
  187. jPanel1.add(jButton1);
  188. jButton3.setText(bundle.getString("ControlPanel_Company.jButton3.text")); // NOI18N
  189. jButton3.setName("jButton3"); // NOI18N
  190. jButton3.addActionListener(new java.awt.event.ActionListener() {
  191. public void actionPerformed(java.awt.event.ActionEvent evt) {
  192. jButton3ActionPerformed(evt);
  193. }
  194. });
  195. jPanel1.add(jButton3);
  196. add(jPanel1, java.awt.BorderLayout.PAGE_END);
  197. }// </editor-fold>//GEN-END:initComponents
  198. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
  199. setSettings();
  200. User.getCurrentUser().saveProperties();
  201. }//GEN-LAST:event_jButton1ActionPerformed
  202. private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
  203. reset();
  204. }//GEN-LAST:event_jButton3ActionPerformed
  205. private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
  206. if (mpv5.ui.dialogs.Popup.Y_N_dialog("Really delete all invoices, orders and offers from the database? This is irreversible!!! Contacts and Products will not be affected.", Messages.ARE_YOU_SURE)) {
  207. if (Popup.Y_N_dialog(Messages.ARE_YOU_SURE)) {
  208. Popup.notice(QueryHandler.instanceOf().freeQuery("delete from items", MPSecurityManager.ADMINISTRATE, "Item reset done.").getMessage());
  209. final String fmessage = "ITEM RESET: removed all invoices, orders and offers from database";
  210. final String fdbid = "items";
  211. final int fids = 0;
  212. final int fgids = 1;
  213. Runnable runnable = new Runnable() {
  214. @Override
  215. public void run() {
  216. QueryHandler.instanceOf().clone(Context.getHistory()).insertHistoryItem(fmessage, mpv5.db.objects.User.getCurrentUser().__getCname(), fdbid, fids, fgids);
  217. }
  218. };
  219. SwingUtilities.invokeLater(runnable);
  220. }
  221. }
  222. }//GEN-LAST:event_jButton2ActionPerformed
  223. public void setValues(PropertyStore values) {
  224. oldvalues = values;
  225. try {
  226. for (Component comp : jPanel3.getComponents()) {
  227. for (String[] v : values.getList()) {
  228. if (comp.getName().equalsIgnoreCase(v[0])) {
  229. ((LabeledTextField) comp).setText(v[1]);
  230. }
  231. }
  232. }
  233. } catch (Exception e) {
  234. Log.Debug(this, e);
  235. }
  236. }
  237. public String getUname() {
  238. return UNAME;
  239. }
  240. public void reset() {
  241. setValues(oldvalues);
  242. }
  243. // Variables declaration - do not modify//GEN-BEGIN:variables
  244. private mpv5.ui.beans.LabeledTextField account;
  245. private mpv5.ui.beans.LabeledTextField account1;
  246. private mpv5.ui.beans.LabeledTextField bankname;
  247. private mpv5.ui.beans.LabeledTextField banknumber;
  248. private mpv5.ui.beans.LabeledTextField business;
  249. private mpv5.ui.beans.LabeledTextField city;
  250. private mpv5.ui.beans.LabeledTextField country;
  251. private mpv5.ui.beans.LabeledTextField email;
  252. private mpv5.ui.beans.LabeledTextField fax;
  253. private mpv5.ui.beans.LabeledTextField firstname;
  254. private javax.swing.JButton jButton1;
  255. private javax.swing.JButton jButton2;
  256. private javax.swing.JButton jButton3;
  257. private javax.swing.JPanel jPanel1;
  258. private javax.swing.JPanel jPanel2;
  259. private javax.swing.JPanel jPanel3;
  260. private javax.swing.JScrollPane jScrollPane1;
  261. private javax.swing.JTextArea jTextArea1;
  262. private mpv5.ui.beans.LabeledTextField name;
  263. private mpv5.ui.beans.LabeledTextField phone;
  264. private mpv5.ui.beans.LabeledTextField phoneprefix;
  265. private mpv5.ui.beans.LabeledTextField street;
  266. private mpv5.ui.beans.LabeledTextField taxadvjob;
  267. private mpv5.ui.beans.LabeledTextField taxadvsior;
  268. private mpv5.ui.beans.LabeledTextField taxauthority;
  269. private mpv5.ui.beans.LabeledTextField taxmandant;
  270. private mpv5.ui.beans.LabeledTextField taxnumber;
  271. private mpv5.ui.beans.LabeledTextField zip;
  272. // End of variables declaration//GEN-END:variables
  273. private void setSettings() {
  274. HashMap<String, String> m = PanelUtils.getSubComponentValues(jPanel3);
  275. Iterator<Entry<String, String>> i = m.entrySet().iterator();
  276. while (i.hasNext()) {
  277. Entry<String, String> it = i.next();
  278. User.getCurrentUser().setProperty("companyinfo." + it.getKey(), it.getValue());
  279. }
  280. }
  281. @Override
  282. public Component getAndRemoveActionPanel() {
  283. this.remove(jPanel1);
  284. validate();
  285. return jPanel1;
  286. }
  287. }