/* * Copyright (C) 2014 GG-Net GmbH - Oliver Günther * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package eu.ggnet.dwoss.misc.saleschannel; import eu.ggnet.dwoss.stock.entity.Stock; import java.awt.event.ActionEvent; import java.util.ArrayList; import java.util.List; import javax.swing.*; import eu.ggnet.dwoss.stock.StockAgent; import static eu.ggnet.saft.core.Client.lookup; // TODO: Ok,Canel Button richtig einbinden. // Return Values public class SalesChannelManagerDialog extends javax.swing.JDialog { private boolean ok = false; private SalesChannelTableModel model; public SalesChannelManagerDialog(java.awt.Window parent) { super(parent, DEFAULT_MODALITY_TYPE); initComponents(); salesChanelTable.setAutoCreateColumnsFromModel(true); salesChanelTable.setAutoCreateRowSorter(true); List<Stock> stocks = new ArrayList<>(lookup(StockAgent.class).findAll(Stock.class)); stocks.add(null); salesChanelTable.setDefaultEditor(Stock.class, new StockTableEditor(stocks.toArray())); salesChanelTable.setDefaultRenderer(Stock.class, new StockTableCellRenderer()); salesChanelTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); } public void setModel(SalesChannelTableModel model) { this.model = model; salesChanelTable.setModel(model); for (int i = 0; i < model.getColumnCount(); i++) { salesChanelTable.getColumnModel().getColumn(i).setPreferredWidth(model.getPreferredWidth(i)); } } public SalesChannelTableModel getModel() { return model; } public boolean isOk() { return ok; } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jScrollPane1 = new javax.swing.JScrollPane(); salesChanelTable = new javax.swing.JTable(); cancelButton = new javax.swing.JButton(); okButton = new javax.swing.JButton(); autoSelectChannelButton = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle("Verkaufskanalmanager"); salesChanelTable.setModel(new javax.swing.table.DefaultTableModel( new Object [][] { {null, null, null, null}, {null, null, null, null}, {null, null, null, null}, {null, null, null, null} }, new String [] { "Title 1", "Title 2", "Title 3", "Title 4" } )); jScrollPane1.setViewportView(salesChanelTable); cancelButton.setText("Abbrechen"); cancelButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cancelButtonActionPerformed(evt); } }); okButton.setText("Ok"); okButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { okButtonActionPerformed(evt); } }); autoSelectChannelButton.setText("Verkaufskanal automatisch aus Lager wählen"); autoSelectChannelButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { autoSelectChannelButtonActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 670, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addComponent(autoSelectChannelButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 320, Short.MAX_VALUE) .addComponent(okButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(cancelButton))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap() .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 435, Short.MAX_VALUE) .addGap(9, 9, 9) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(cancelButton) .addComponent(okButton) .addComponent(autoSelectChannelButton)) .addContainerGap()) ); pack(); }// </editor-fold>//GEN-END:initComponents private void okButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed this.ok = true; this.setVisible(false); }//GEN-LAST:event_okButtonActionPerformed private void cancelButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed this.setVisible(false); }//GEN-LAST:event_cancelButtonActionPerformed private void autoSelectChannelButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_autoSelectChannelButtonActionPerformed model.autoSelectChannel(); }//GEN-LAST:event_autoSelectChannelButtonActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton autoSelectChannelButton; private javax.swing.JButton cancelButton; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JButton okButton; private javax.swing.JTable salesChanelTable; // End of variables declaration//GEN-END:variables }