Dépôt officiel du code source de l'ERP OpenConcerto
Rev 156 | Blame | Compare with Previous | 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.supplychain.stock.action;
import org.openconcerto.erp.action.CreateIListFrameAbstractAction;
import org.openconcerto.erp.config.ComptaPropsConfiguration;
import org.openconcerto.erp.core.common.ui.IListFilterDatePanel;
import org.openconcerto.erp.core.supplychain.stock.element.MouvementStockSQLElement;
import org.openconcerto.sql.element.SQLElement;
import org.openconcerto.sql.model.SQLRowAccessor;
import org.openconcerto.sql.model.SQLSelect;
import org.openconcerto.sql.model.Where;
import org.openconcerto.sql.view.IListFrame;
import org.openconcerto.sql.view.list.SQLTableModelSource;
import org.openconcerto.ui.DefaultGridBagConstraints;
import org.openconcerto.utils.cc.ITransformer;
import java.awt.GridBagConstraints;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.AbstractAction;
import javax.swing.JPopupMenu;
import javax.swing.JTable;
public class ListeDesMouvementsStockAction extends CreateIListFrameAbstractAction<MouvementStockSQLElement> {
private final SQLRowAccessor rowArtFilter;
public ListeDesMouvementsStockAction(final ComptaPropsConfiguration conf) {
this(conf, null);
}
public ListeDesMouvementsStockAction(final ComptaPropsConfiguration conf, SQLRowAccessor rowArticleFilter) {
super(conf, MouvementStockSQLElement.class);
this.rowArtFilter = rowArticleFilter;
}
protected SQLTableModelSource createTableSource() {
SQLTableModelSource source = this.getElem().createTableSource();
if (this.rowArtFilter != null && !this.rowArtFilter.isUndefined()) {
source.getReq().setSelectTransf(new ITransformer<SQLSelect, SQLSelect>() {
@Override
public SQLSelect transformChecked(SQLSelect input) {
input.setWhere(new Where(input.getTable("MOUVEMENT_STOCK").getField("ID_ARTICLE"), "=", ListeDesMouvementsStockAction.this.rowArtFilter.getID()));
return input;
}
});
}
return source;
}
@Override
protected void initFrame(IListFrame frame) {
super.initFrame(frame);
if (this.rowArtFilter != null && !this.rowArtFilter.isUndefined()) {
frame.setTextTitle("Mouvements de stocks, article " + this.rowArtFilter.getString("CODE") + " " + this.rowArtFilter.getString("NOM"));
}
final SQLElement element = getElem();
JTable table = frame.getPanel().getListe().getJTable();
table.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON3) {
JPopupMenu menuDroit = new JPopupMenu();
menuDroit.add(new AbstractAction("Voir la source") {
public void actionPerformed(ActionEvent e) {
MouvementStockSQLElement.showSource(frame.getPanel().getListe().getSelectedId());
}
});
menuDroit.show(e.getComponent(), e.getPoint().x, e.getPoint().y);
}
}
});
// Date panel
IListFilterDatePanel datePanel = new IListFilterDatePanel(frame.getPanel().getListe(), element.getTable().getField("DATE"), IListFilterDatePanel.getDefaultMap());
GridBagConstraints c = new DefaultGridBagConstraints();
c.gridwidth = GridBagConstraints.REMAINDER;
c.fill = GridBagConstraints.NONE;
c.weightx = 0;
c.gridy++;
c.gridy++;
c.anchor = GridBagConstraints.CENTER;
datePanel.setFilterOnDefault();
frame.getPanel().add(datePanel, c);
}
}