PageRenderTime 37ms CodeModel.GetById 22ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 320 lines | 241 code | 44 blank | 35 comment | 12 complexity | 46f2151526daca12344f1a186df7be46 MD5 | raw file
  1/*
  2This file is part of YaBS.
  3
  4YaBS is free software: you can redistribute it and/or modify
  5it under the terms of the GNU General Public License as published by
  6the Free Software Foundation, either version 3 of the License, or
  7(at your option) any later version.
  8
  9YaBS is distributed in the hope that it will be useful,
 10but WITHOUT ANY WARRANTY; without even the implied warranty of
 11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 12GNU General Public License for more details.
 13
 14You should have received a copy of the GNU General Public License
 15along with YaBS.  If not, see <http://www.gnu.org/licenses/>.
 16 */
 17/*
 18 * ContactPanel.java
 19 *
 20 * Created on Nov 20, 2008, 8:17:28 AM
 21 */
 22package mpv5.ui.dialogs.subcomponents;
 23
 24import java.awt.Component;
 25import java.math.BigDecimal;
 26import java.util.Date;
 27import mpv5.data.PropertyStore;
 28import mpv5.db.common.Context;
 29import mpv5.db.common.DatabaseObject;
 30import mpv5.db.common.NodataFoundException;
 31import mpv5.db.objects.Tax;
 32import mpv5.globals.Messages;
 33import mpv5.i18n.LanguageManager;
 34import mpv5.ui.dialogs.ControlApplet;
 35import mpv5.ui.dialogs.Popup;
 36import mpv5.ui.panels.DataPanel;
 37import mpv5.usermanagement.MPSecurityManager;
 38import mpv5.utils.ui.TextFieldUtils;
 39
 40/**
 41 *
 42 * 
 43 */
 44public class ControlPanel_Taxes extends javax.swing.JPanel implements ControlApplet, DataPanel {
 45
 46    private static final long serialVersionUID = 1L;
 47    private ControlPanel_Taxes insta;
 48    private Tax dataOwner;
 49
 50    /** Creates new form ContactPanel
 51     */
 52    public ControlPanel_Taxes() {
 53        if (MPSecurityManager.checkAdminAccess()) {
 54            initComponents();
 55            value.set_ValueClass(Double.class);
 56            value.setText(0);
 57            selecttax.setContext(Context.getTaxes());
 58            selecttax.setReceiver(this);
 59            selecttax.getComboBox().setEditable(false);
 60            selecttax.setSearchEnabled(false);
 61            refresh();
 62        }
 63    }
 64
 65    public void showRequiredFields() {
 66        TextFieldUtils.blinkerRed(cname);
 67
 68    }
 69
 70    /** This method is called from within the constructor to
 71     * initialize the form.
 72     * WARNING: Do NOT modify this code. The content of this method is
 73     * always regenerated by the Form Editor.
 74     */
 75    @SuppressWarnings("unchecked")
 76    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
 77    private void initComponents() {
 78
 79        buttonGroup1 = new javax.swing.ButtonGroup();
 80        jPanel6 = new javax.swing.JPanel();
 81        jButton2 = new javax.swing.JButton();
 82        jButton1 = new javax.swing.JButton();
 83        jButton3 = new javax.swing.JButton();
 84        jPanel1 = new javax.swing.JPanel();
 85        selecttax = new mpv5.ui.beans.LabeledCombobox();
 86        cname = new mpv5.ui.beans.LabeledTextField();
 87        value = new mpv5.ui.beans.LabeledTextField();
 88        countries = new mpv5.ui.beans.LabeledCombobox();
 89
 90        java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle(); // NOI18N
 91        setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("ControlPanel_Taxes.border.title"))); // NOI18N
 92        setName("Form"); // NOI18N
 93        setLayout(new java.awt.BorderLayout());
 94
 95        jPanel6.setBackground(new java.awt.Color(255, 255, 255));
 96        jPanel6.setName("jPanel6"); // NOI18N
 97        jPanel6.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
 98
 99        jButton2.setText(bundle.getString("ControlPanel_Taxes.jButton2.text")); // NOI18N
100        jButton2.setName("jButton2"); // NOI18N
101        jButton2.addActionListener(new java.awt.event.ActionListener() {
102            public void actionPerformed(java.awt.event.ActionEvent evt) {
103                jButton2ActionPerformed(evt);
104            }
105        });
106        jPanel6.add(jButton2);
107
108        jButton1.setText(bundle.getString("ControlPanel_Taxes.jButton1.text")); // NOI18N
109        jButton1.setName("jButton1"); // NOI18N
110        jButton1.addActionListener(new java.awt.event.ActionListener() {
111            public void actionPerformed(java.awt.event.ActionEvent evt) {
112                jButton1ActionPerformed(evt);
113            }
114        });
115        jPanel6.add(jButton1);
116
117        jButton3.setText(bundle.getString("ControlPanel_Taxes.jButton3.text")); // NOI18N
118        jButton3.setName("jButton3"); // NOI18N
119        jButton3.addActionListener(new java.awt.event.ActionListener() {
120            public void actionPerformed(java.awt.event.ActionEvent evt) {
121                jButton3ActionPerformed(evt);
122            }
123        });
124        jPanel6.add(jButton3);
125
126        add(jPanel6, java.awt.BorderLayout.PAGE_END);
127
128        jPanel1.setName("jPanel1"); // NOI18N
129
130        selecttax.set_Label(bundle.getString("ControlPanel_Taxes.selecttax._Label")); // NOI18N
131        selecttax.setName("selecttax"); // NOI18N
132
133        cname.set_Label(bundle.getString("ControlPanel_Taxes.cname._Label")); // NOI18N
134        cname.setName("cname"); // NOI18N
135
136        value.set_Label(bundle.getString("ControlPanel_Taxes.value._Label")); // NOI18N
137        value.setName("value"); // NOI18N
138
139        countries.set_Label(bundle.getString("ControlPanel_Taxes.countries._Label")); // NOI18N
140        countries.setName("countries"); // NOI18N
141
142        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
143        jPanel1.setLayout(jPanel1Layout);
144        jPanel1Layout.setHorizontalGroup(
145            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
146            .addGroup(jPanel1Layout.createSequentialGroup()
147                .addContainerGap()
148                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
149                    .addComponent(value, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
150                    .addComponent(cname, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
151                    .addComponent(selecttax, javax.swing.GroupLayout.DEFAULT_SIZE, 244, Short.MAX_VALUE)
152                    .addComponent(countries, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
153                .addContainerGap(43, Short.MAX_VALUE))
154        );
155        jPanel1Layout.setVerticalGroup(
156            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
157            .addGroup(jPanel1Layout.createSequentialGroup()
158                .addContainerGap()
159                .addComponent(selecttax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
160                .addGap(18, 18, 18)
161                .addComponent(cname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
162                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
163                .addComponent(value, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
164                .addGap(18, 18, 18)
165                .addComponent(countries, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
166                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
167        );
168
169        add(jPanel1, java.awt.BorderLayout.CENTER);
170    }// </editor-fold>//GEN-END:initComponents
171
172    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
173        collectData();
174        Tax t = new Tax();
175        if (dataOwner != null) {
176            t = dataOwner;
177        } else {
178            t.setIdentifier(cname_);
179        }
180        t.setCname(cname_);
181        t.setCountry(country_);
182        t.setTaxvalue(taxvalue_);
183        t.save();
184        actionAfterSave();
185}//GEN-LAST:event_jButton2ActionPerformed
186
187    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
188        collectData();
189        Tax t = new Tax();
190        t.setCountry(country_);
191        t.setIdentifier(cname_);
192        t.setCname(cname_);
193        t.setTaxvalue(taxvalue_);
194        t.save();
195        actionAfterCreate();
196
197}//GEN-LAST:event_jButton1ActionPerformed
198
199    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
200        if (dataOwner != null && dataOwner.isExisting()) {
201            if(!dataOwner.delete())
202                Popup.notice(Messages.IN_USE);
203        }
204        refresh();
205
206    }//GEN-LAST:event_jButton3ActionPerformed
207    // Variables declaration - do not modify//GEN-BEGIN:variables
208    private javax.swing.ButtonGroup buttonGroup1;
209    private mpv5.ui.beans.LabeledTextField cname;
210    private mpv5.ui.beans.LabeledCombobox countries;
211    private javax.swing.JButton jButton1;
212    private javax.swing.JButton jButton2;
213    private javax.swing.JButton jButton3;
214    private javax.swing.JPanel jPanel1;
215    private javax.swing.JPanel jPanel6;
216    private mpv5.ui.beans.LabeledCombobox selecttax;
217    private mpv5.ui.beans.LabeledTextField value;
218    // End of variables declaration//GEN-END:variables
219    public String cname_;
220    public int intaddedby_;
221    public int ids_;
222    public Date dateadded_;
223    public int groupsids_ = 1;
224    public BigDecimal taxvalue_;
225    public String identifier_ = "";
226    public String country_ = "";
227
228    public void setValues(PropertyStore values) {
229        throw new UnsupportedOperationException("Not supported yet.");
230    }
231
232    public String getUname() {
233        return "Taxes";
234    }
235
236    public void reset() {
237    }
238
239    public ControlApplet instanceOf() {
240        if (insta == null) {
241            insta = new ControlPanel_Taxes();
242        }
243        return insta;
244    }
245
246    public void refresh() {
247        try {
248            selecttax.setModel(DatabaseObject.getObjects(Context.getTaxes()));
249        } catch (NodataFoundException ex) {
250        }
251        countries.setModel(LanguageManager.getCountriesAsComboBoxModel());
252    }
253
254    public Component getAndRemoveActionPanel() {
255        this.remove(jPanel6);
256        validate();
257        return jPanel6;
258    }
259
260    public boolean collectData() {
261        try {
262            cname_ = cname.getText();
263            taxvalue_ = new BigDecimal(value.getValue(0d).toString());
264            country_ = countries.getComboBox().getSelectedItem().toString();
265            return true;
266        } catch (Exception e) {
267            return false;
268        }
269    }
270
271    public DatabaseObject getDataOwner() {
272        return dataOwner;
273    }
274
275    public void setDataOwner(DatabaseObject object, boolean populateData) {
276        this.dataOwner = (Tax) object;
277        if (populateData) {
278            dataOwner.setPanelData(this);
279            this.exposeData();
280        }
281    }
282
283    public void exposeData() {
284        cname.setText(cname_);
285        value.setText(taxvalue_);
286        countries.setSelectedItem(country_);
287    }
288
289    public void paste(DatabaseObject... dbos) {
290        for (DatabaseObject dbo : dbos) {
291            setDataOwner(dbo, true);
292        }
293    }
294
295    public void showSearchBar(boolean show) {
296        throw new UnsupportedOperationException("Not supported yet.");
297    }
298
299    public void actionAfterSave() {
300        refresh();
301    }
302
303    public void actionAfterCreate() {
304        refresh();
305    }
306
307    public void actionBeforeCreate() {
308    }
309
310    public void actionBeforeSave() {
311    }
312
313    public void mail() {
314        throw new UnsupportedOperationException("Not supported yet.");
315    }
316
317    public void print() {
318        mpv5.utils.export.Export.print(this);
319    }
320}