Dépôt officiel du code source de l'ERP OpenConcerto
Blame | Last modification | View Log | RSS feed
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
*
* The contents of this file are subject to the terms of the GNU General Public License Version 3
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each file.
*/
package org.openconcerto.erp.core.sales.product.element;
import org.openconcerto.sql.model.SQLRow;
import org.openconcerto.ui.JLabelBold;
import org.openconcerto.utils.ExceptionHandler;
import org.openconcerto.utils.Tuple2;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import org.jopencalendar.ui.FixedColumnTable;
public class NouvellesDeclinaisonsFrame extends JFrame {
public NouvellesDeclinaisonsFrame(ReferenceArticleSQLElement element, SQLRow selectedRow) {
JPanel p = new JPanel();
p.setLayout(new BorderLayout());
// Name
JLabel l = new JLabelBold(selectedRow.getString("NOM"));
p.add(l, BorderLayout.NORTH);
// Table
TailleCouleurTableModel model = new TailleCouleurTableModel(element);
FixedColumnTable t = new FixedColumnTable(1, model);
t.getMain().setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
t.getColumn(0).setMinWidth(140);
t.setColumnWidth(0, 150);
for (int i = 1; i < model.getColumnCount(); i++) {
t.getColumn(i).setMinWidth(40);
}
t.getMain().setDefaultRenderer(Boolean.class, new DefaultTableCellRenderer() {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
DefaultTableCellRenderer c = (DefaultTableCellRenderer) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
c.setText("");
Boolean b = (Boolean) value;
if (b) {
c.setBackground(Color.GREEN);
} else {
if (isSelected) {
c.setBackground(Color.GRAY);
} else {
c.setBackground(Color.WHITE);
}
}
return c;
}
});
// t.setDefaultEditor(Boolean., editor);
JScrollPane scroll = new JScrollPane(t);
p.add(scroll);
// Create
final JPanel actions = new JPanel();
actions.setLayout(new FlowLayout(FlowLayout.RIGHT));
JButton createButton = new JButton("Créer les déclinaisons");
actions.add(createButton);
p.add(actions, BorderLayout.SOUTH);
this.setContentPane(p);
createButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final List<Tuple2<SQLRow, SQLRow>> r = model.getSelected();
try {
element.createDeclinaison(selectedRow.getID(), r);
} catch (SQLException e1) {
ExceptionHandler.handle("erreur de création", e1);
}
NouvellesDeclinaisonsFrame.this.dispose();
}
});
}
}