PageRenderTime 282ms CodeModel.GetById 116ms app.highlight 74ms RepoModel.GetById 87ms app.codeStats 1ms

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