PageRenderTime 146ms CodeModel.GetById 60ms app.highlight 43ms RepoModel.GetById 40ms app.codeStats 0ms

/src/mpv5/ui/panels/ProductPanelContactSub.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 250 lines | 193 code | 31 blank | 26 comment | 10 complexity | bd67fbb970cf1f300909cb69755ef522 MD5 | raw file
  1/*
  2 * To change this template, choose Tools | Templates
  3 * and open the template in the editor.
  4 */
  5
  6/*
  7 * ProductPanelContactSub.java
  8 *
  9 * Created on 01.03.2010, 15:57:49
 10 */
 11package mpv5.ui.panels;
 12
 13import java.awt.Container;
 14import java.awt.event.ActionEvent;
 15import java.awt.event.ActionListener;
 16import javax.swing.ButtonGroup;
 17import javax.swing.SwingUtilities;
 18import mpv5.db.common.Context;
 19import mpv5.db.common.DatabaseObject;
 20import mpv5.db.common.NodataFoundException;
 21import mpv5.db.objects.Contact;
 22import mpv5.logging.Log;
 23import mpv5.utils.models.MPComboBoxModelItem;
 24
 25/**
 26 *
 27 * @author anti
 28 */
 29public class ProductPanelContactSub extends javax.swing.JPanel {
 30
 31    public static ButtonGroup group = new ButtonGroup();
 32    private final Contact contact;
 33
 34    /** Creates new form ProductPanelContactSub
 35     * @param c
 36     * @param defaults
 37     */
 38    public ProductPanelContactSub(Contact c, final boolean defaults) {
 39        initComponents();
 40
 41        group.add(jRadioButton1);
 42        contactname.setSearchEnabled(true);
 43        contactname.setEditable(true);
 44        contactname.setContext(Context.getSupplier());
 45        contactname.getComboBox().addActionListener(new ActionListener() {
 46
 47            @Override
 48            public void actionPerformed(ActionEvent e) {
 49                final MPComboBoxModelItem item = contactname.getSelectedItem();
 50                if (item != null && item.isValid()) {
 51                    Runnable runnable = new Runnable() {
 52
 53                        @Override
 54                        public void run() {
 55                            try {
 56                                Contact dbo = (Contact) DatabaseObject.getObject(Context.getContact(), Integer.valueOf(item.getId()));
 57                                contactcity.setText(dbo.__getCity());
 58                                contactcompany.setText(dbo.__getCompany());
 59                                contactid.setText(dbo.__getCNumber());
 60                                if (defaults) {
 61                                    jRadioButton1.setSelected(true);
 62                                }
 63                            } catch (NodataFoundException ex) {
 64                            }
 65                        }
 66                    };
 67                    SwingUtilities.invokeLater(runnable);
 68                }
 69            }
 70        });
 71
 72        if (c != null && c.isExisting()) {
 73            try {
 74                Contact owner = c;
 75                contactname.setModel(owner);
 76                contactcity.setText(owner.__getCity());
 77                contactcompany.setText(owner.__getCompany());
 78                contactid.setText(String.valueOf(owner.__getCNumber()));
 79            } catch (Exception ex) {
 80                Log.Debug(ex);
 81            }
 82        } else {
 83            contactname.setModel(new Object[0][0]);
 84            contactcity.setText("");
 85            contactcompany.setText("");
 86            contactid.setText(String.valueOf(""));
 87        }
 88
 89        this.contact = c;
 90    }
 91
 92    /** This method is called from within the constructor to
 93     * initialize the form.
 94     * WARNING: Do NOT modify this code. The content of this method is
 95     * always regenerated by the Form Editor.
 96     */
 97    @SuppressWarnings("unchecked")
 98    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
 99    private void initComponents() {
100
101        jPanel6 = new javax.swing.JPanel();
102        contactid = new javax.swing.JTextField();
103        contactcity = new javax.swing.JTextField();
104        contactcompany = new javax.swing.JTextField();
105        contactname = new mpv5.ui.beans.LabeledCombobox();
106        jRadioButton1 = new javax.swing.JRadioButton();
107        jButton1 = new javax.swing.JButton();
108        jButton2 = new javax.swing.JButton();
109
110        setName("Form"); // NOI18N
111
112        jPanel6.setBackground(new java.awt.Color(230, 223, 223));
113        jPanel6.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(204, 204, 204), 1, true));
114        jPanel6.setForeground(new java.awt.Color(204, 204, 204));
115        jPanel6.setName("jPanel6"); // NOI18N
116
117        contactid.setEditable(false);
118        java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle(); // NOI18N
119        contactid.setText(bundle.getString("ProductPanel.contactid.text")); // NOI18N
120        contactid.setName("contactid"); // NOI18N
121
122        contactcity.setEditable(false);
123        contactcity.setText(bundle.getString("ProductPanel.contactcity.text")); // NOI18N
124        contactcity.setName("contactcity"); // NOI18N
125
126        contactcompany.setEditable(false);
127        contactcompany.setText(bundle.getString("ProductPanel.contactcompany.text")); // NOI18N
128        contactcompany.setName("contactcompany"); // NOI18N
129
130        contactname.set_Label(bundle.getString("ProductPanel.contactname._Label")); // NOI18N
131        contactname.setName("contactname"); // NOI18N
132
133        jRadioButton1.setText(bundle.getString("ProductPanelContactSub.jRadioButton1.text")); // NOI18N
134        jRadioButton1.setName("jRadioButton1"); // NOI18N
135        jRadioButton1.setOpaque(false);
136
137        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mpv5/resources/images/16/add.png"))); // NOI18N
138        jButton1.setText(bundle.getString("ProductPanelContactSub.jButton1.text")); // NOI18N
139        jButton1.setMargin(new java.awt.Insets(1, 1, 1, 1));
140        jButton1.setName("jButton1"); // NOI18N
141        jButton1.addActionListener(new java.awt.event.ActionListener() {
142            public void actionPerformed(java.awt.event.ActionEvent evt) {
143                jButton1ActionPerformed(evt);
144            }
145        });
146
147        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mpv5/resources/images/16/remove.png"))); // NOI18N
148        jButton2.setText(bundle.getString("ProductPanelContactSub.jButton2.text")); // NOI18N
149        jButton2.setMargin(new java.awt.Insets(1, 1, 1, 1));
150        jButton2.setName("jButton2"); // NOI18N
151        jButton2.addActionListener(new java.awt.event.ActionListener() {
152            public void actionPerformed(java.awt.event.ActionEvent evt) {
153                jButton2ActionPerformed(evt);
154            }
155        });
156
157        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
158        jPanel6.setLayout(jPanel6Layout);
159        jPanel6Layout.setHorizontalGroup(
160            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
161            .addGroup(jPanel6Layout.createSequentialGroup()
162                .addContainerGap()
163                .addComponent(contactname, javax.swing.GroupLayout.PREFERRED_SIZE, 239, javax.swing.GroupLayout.PREFERRED_SIZE)
164                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
165                .addComponent(contactcity, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)
166                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
167                .addComponent(contactcompany, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)
168                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
169                .addComponent(contactid, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)
170                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
171                .addComponent(jRadioButton1)
172                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
173                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
174                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
175                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
176                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
177        );
178        jPanel6Layout.setVerticalGroup(
179            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
180            .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
181                .addComponent(contactcity, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
182                .addComponent(contactcompany, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
183                .addComponent(contactid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
184                .addComponent(jRadioButton1)
185                .addComponent(contactname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
186                .addComponent(jButton1)
187                .addComponent(jButton2))
188        );
189
190        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
191        this.setLayout(layout);
192        layout.setHorizontalGroup(
193            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
194            .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
195        );
196        layout.setVerticalGroup(
197            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
198            .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
199        );
200    }// </editor-fold>//GEN-END:initComponents
201
202    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
203        getParent().add(new ProductPanelContactSub(null, false));
204        getParent().validate();
205        getParent().getParent().validate();
206    }//GEN-LAST:event_jButton1ActionPerformed
207
208    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
209        Container p = getParent();
210        getParent().remove(this);
211        if(isDefault()){
212        if(p.getComponentCount()>0) {
213                ((ProductPanelContactSub) p.getComponent(0)).setDefault(true);
214            }
215        }
216        p.validate();
217        p.getParent().validate();
218    }//GEN-LAST:event_jButton2ActionPerformed
219
220    public boolean isDefault() {
221        return jRadioButton1.isSelected();
222    }
223
224    public void setDefault(boolean def){
225        jRadioButton1.setSelected(def);
226    }
227
228    public Contact getContact() {
229
230        try {
231            //main supplier here
232            int suppliersids_ = Integer.valueOf(contactname.getSelectedItem().getId());
233            return (Contact) DatabaseObject.getObject(Context.getContact(), suppliersids_);
234        } catch (Exception numberFormatException) {
235            return null;
236        }
237    }
238    // Variables declaration - do not modify//GEN-BEGIN:variables
239    private javax.swing.JTextField contactcity;
240    private javax.swing.JTextField contactcompany;
241    private javax.swing.JTextField contactid;
242    private mpv5.ui.beans.LabeledCombobox contactname;
243    private javax.swing.JButton jButton1;
244    private javax.swing.JButton jButton2;
245    private javax.swing.JPanel jPanel6;
246    private javax.swing.JRadioButton jRadioButton1;
247    // End of variables declaration//GEN-END:variables
248
249 
250}