PageRenderTime 164ms CodeModel.GetById 81ms app.highlight 18ms RepoModel.GetById 62ms app.codeStats 0ms

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

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 214 lines | 154 code | 26 blank | 34 comment | 13 complexity | 40c4a9b626a8cc6763e8d198bc8736ba MD5 | raw file
  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 */
 17package mpv5.ui.dialogs.subcomponents;
 18
 19import java.awt.event.ActionEvent;
 20import java.awt.event.ActionListener;
 21import java.awt.event.KeyEvent;
 22import java.awt.event.KeyListener;
 23import java.math.BigDecimal;
 24import javax.swing.JTable;
 25import mpv5.db.common.Context;
 26import mpv5.db.common.DatabaseObject;
 27import mpv5.db.objects.Product;
 28import mpv5.db.objects.SubItem;
 29import mpv5.db.objects.User;
 30import mpv5.globals.Messages;
 31import mpv5.logging.Log;
 32import mpv5.utils.models.MPTableModel;
 33
 34public class ItemTextAreaDialog extends javax.swing.JDialog implements KeyListener, DatabaseObejctReceiver {
 35
 36    private JTable parentTable;
 37    private mpv5.db.objects.Product product;
 38
 39    /** Creates new form ItemTextAreaDialog */
 40    public ItemTextAreaDialog(java.awt.Frame parent, boolean modal) {
 41        super(parent, modal);
 42        setResizable(false);
 43        setUndecorated(true);
 44        initComponents();
 45        textArea.addKeyListener(this);
 46//        okButton.setToolTipText("ctrl+Enter");
 47        cancelButton.setToolTipText("Esc");
 48        labeledCombobox1.setContext(Context.getProduct());
 49        labeledCombobox1.setSearchOnEnterEnabled(true);;
 50        labeledCombobox1.setReceiver(this);
 51        labeledCombobox1.setToolTipText(Messages.SEARCHABLE.toString());
 52
 53        labeledSpinner1.setValue(1);
 54    }
 55
 56    @Override
 57    public void setVisible(boolean visible) {
 58        super.setVisible(visible);
 59        if(visible)textArea.grabFocus();
 60    }
 61
 62    /** This method is called from within the constructor to
 63     * initialize the form.
 64     * WARNING: Do NOT modify this code. The content of this method is
 65     * always regenerated by the Form Editor.
 66     */
 67    @SuppressWarnings("unchecked")
 68    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
 69    private void initComponents() {
 70
 71        jScrollPane1 = new javax.swing.JScrollPane();
 72        textArea = new javax.swing.JTextArea();
 73        okButton = new javax.swing.JButton();
 74        cancelButton = new javax.swing.JButton();
 75        labeledCombobox1 = new mpv5.ui.beans.LabeledCombobox();
 76        labeledSpinner1 = new mpv5.ui.beans.LabeledSpinner();
 77
 78        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
 79        setName("Form"); // NOI18N
 80
 81        jScrollPane1.setName("jScrollPane1"); // NOI18N
 82
 83        textArea.setColumns(20);
 84        textArea.setRows(5);
 85        textArea.setName("textArea"); // NOI18N
 86        jScrollPane1.setViewportView(textArea);
 87
 88        java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle(); // NOI18N
 89        okButton.setText(bundle.getString("okButton")); // NOI18N
 90        okButton.setName("okButton"); // NOI18N
 91        okButton.addActionListener(new java.awt.event.ActionListener() {
 92            public void actionPerformed(java.awt.event.ActionEvent evt) {
 93                okButtonActionPerformed(evt);
 94            }
 95        });
 96
 97        cancelButton.setText(bundle.getString("cancelButton")); // NOI18N
 98        cancelButton.setActionCommand("CANCEL"); // NOI18N
 99        cancelButton.setName("cancelButton"); // NOI18N
100
101        labeledCombobox1.set_Label(bundle.getString("ItemTextAreaDialog.labeledCombobox1._Label")); // NOI18N
102        labeledCombobox1.setName("labeledCombobox1"); // NOI18N
103
104        labeledSpinner1.set_Label(bundle.getString("ItemTextAreaDialog.labeledSpinner1._Label")); // NOI18N
105        labeledSpinner1.setName("labeledSpinner1"); // NOI18N
106
107        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
108        getContentPane().setLayout(layout);
109        layout.setHorizontalGroup(
110            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
111            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
112                .addComponent(labeledSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
113                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 86, Short.MAX_VALUE)
114                .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
115                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
116                .addComponent(cancelButton)
117                .addGap(11, 11, 11))
118            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 421, Short.MAX_VALUE)
119            .addComponent(labeledCombobox1, javax.swing.GroupLayout.DEFAULT_SIZE, 421, Short.MAX_VALUE)
120        );
121        layout.setVerticalGroup(
122            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
123            .addGroup(layout.createSequentialGroup()
124                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
125                .addGap(0, 0, 0)
126                .addComponent(labeledCombobox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
127                .addGap(3, 3, 3)
128                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
129                    .addComponent(okButton)
130                    .addComponent(cancelButton)
131                    .addComponent(labeledSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
132                .addContainerGap())
133        );
134
135        pack();
136    }// </editor-fold>//GEN-END:initComponents
137
138    private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
139        setRow();
140//        Log.Debug(this, evt);
141    }//GEN-LAST:event_okButtonActionPerformed
142    // Variables declaration - do not modify//GEN-BEGIN:variables
143    public javax.swing.JButton cancelButton;
144    private javax.swing.JScrollPane jScrollPane1;
145    private mpv5.ui.beans.LabeledCombobox labeledCombobox1;
146    private mpv5.ui.beans.LabeledSpinner labeledSpinner1;
147    public javax.swing.JButton okButton;
148    public javax.swing.JTextArea textArea;
149    // End of variables declaration//GEN-END:variables
150
151    public void keyTyped(KeyEvent e) {
152    }
153
154    public void keyPressed(KeyEvent e) {
155        if (e.isControlDown() && e.getKeyCode() == e.VK_ENTER) {
156            ActionListener[] listeners = okButton.getActionListeners();
157            ActionEvent actionEvent = new ActionEvent(okButton, ActionEvent.ACTION_PERFORMED, okButton.getActionCommand());
158            for (int i = 0; i < listeners.length; i++) {
159                listeners[i].actionPerformed(actionEvent);
160            }
161            setRow();
162        } else if (e.getKeyCode() == e.VK_ESCAPE) {
163            ActionListener[] listeners = cancelButton.getActionListeners();
164            ActionEvent actionEvent = new ActionEvent(cancelButton, ActionEvent.ACTION_PERFORMED, cancelButton.getActionCommand());
165            for (int i = 0; i < listeners.length; i++) {
166                listeners[i].actionPerformed(actionEvent);
167            }
168        }
169    }
170
171    public void keyReleased(KeyEvent e) {
172    }
173
174    @Override
175    public void receive(DatabaseObject obj) {
176        if (obj.getContext().equals(Context.getProduct())) {
177            this.product = (Product) obj;
178            textArea.setText(product.__getCname());
179        }
180    }
181
182    private synchronized void setRow() {
183        SubItem p;
184        MPTableModel m = (MPTableModel) getParentTable().getModel();
185        if (product == null) {
186            p = SubItem.getFromModel(m, getParentTable().getSelectedRow());
187        } else {
188            p = new SubItem(product);
189//            p.setQuantityvalue(new BigDecimal(labeledSpinner1.get_Value().toString()));
190            p.setExternalvalue(product.findPriceFor(p.__getCountvalue().doubleValue()));
191        }
192        p.setDescription(textArea.getText());
193        p.setQuantityvalue(new BigDecimal(labeledSpinner1.get_Value().toString()));
194        
195        m.setRowAt(p.getRowData(getParentTable().getSelectedRow()), getParentTable().getSelectedRow(), 1, 14);
196        labeledCombobox1.setSelectedIndex(-1);
197        product = null;
198        setVisible(false);
199    }
200
201    /**
202     * @return the parentTable
203     */
204    public JTable getParentTable() {
205        return parentTable;
206    }
207
208    /**
209     * @param parentTable the parentTable to set
210     */
211    public void setParentTable(JTable parentTable) {
212        this.parentTable = parentTable;
213    }
214}