📄 vbomdrop.java
字号:
/******************************************************************************
* The contents of this file are subject to the Compiere License Version 1.1
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the License at http://www.compiere.org/license.html
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Original Code is Compiere ERP & CRM Smart Business Solution. The Initial
* Developer of the Original Code is Jorg Janke. Portions created by Jorg Janke
* are Copyright (C) 1999-2005 Jorg Janke.
* All parts are Copyright (C) 1999-2005 ComPiere, Inc. All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.apps.form;
import java.awt.*;
import java.awt.event.*;
import java.math.*;
import java.util.*;
import java.util.logging.*;
import javax.swing.*;
import javax.swing.border.*;
import org.compiere.apps.*;
import org.compiere.grid.ed.*;
import org.compiere.model.*;
import org.compiere.swing.*;
import org.compiere.util.*;
/**
* Drop BOM
*
* @author Jorg Janke
* @version $Id: VBOMDrop.java,v 1.16 2005/10/21 15:42:37 jjanke Exp $
*/
public class VBOMDrop extends CPanel
implements FormPanel, ActionListener
{
/**
* Initialize Panel
* @param WindowNo window
* @param frame parent frame
*/
public void init (int WindowNo, FormFrame frame)
{
log.info("");
m_WindowNo = WindowNo;
m_frame = frame;
try
{
// Top Selection Panel
createSelectionPanel(true, true, true);
m_frame.getContentPane().add(selectionPanel, BorderLayout.NORTH);
// Center
createMainPanel();
CScrollPane scroll = new CScrollPane (this);
m_frame.getContentPane().add(scroll, BorderLayout.CENTER);
confirmPanel.addActionListener(this);
// South
m_frame.getContentPane().add(confirmPanel, BorderLayout.SOUTH);
}
catch(Exception e)
{
log.log(Level.SEVERE, "", e);
}
sizeIt();
} // init
/**
* Size Window
*/
private void sizeIt()
{
// Frame
m_frame.pack();
Dimension size = m_frame.getPreferredSize();
size.width = WINDOW_WIDTH;
m_frame.setSize(size);
} // size
/**
* Dispose
*/
public void dispose()
{
if (m_frame != null)
m_frame.dispose();
m_frame = null;
removeAll();
if (selectionPanel != null)
selectionPanel.removeAll();
selectionPanel = null;
if (m_selectionList != null)
m_selectionList.clear();
m_selectionList = null;
if (m_productList != null)
m_productList.clear();
m_productList = null;
if (m_qtyList != null)
m_qtyList.clear();
m_qtyList = null;
if (m_buttonGroups != null)
m_buttonGroups.clear();
m_buttonGroups = null;
} // dispose
/** Window No */
private int m_WindowNo = 0;
/** FormFrame */
private FormFrame m_frame;
/** Product to create BOMs from */
private MProduct m_product;
/** BOM Qty */
private BigDecimal m_qty = Env.ONE;
/** Line Counter */
private int m_bomLine = 0;
/** Logger */
private static CLogger log = CLogger.getCLogger(VBOMDrop.class);
/** List of all selectors */
private ArrayList<JToggleButton> m_selectionList = new ArrayList<JToggleButton>();
/** List of all quantities */
private ArrayList<VNumber> m_qtyList = new ArrayList<VNumber>();
/** List of all products */
private ArrayList<Integer> m_productList = new ArrayList<Integer>();
/** Alternative Group Lists */
private HashMap<String,ButtonGroup> m_buttonGroups = new HashMap<String,ButtonGroup>();
private static final int WINDOW_WIDTH = 600; // width of the window
//
private ConfirmPanel confirmPanel = new ConfirmPanel (true);
private CPanel selectionPanel = new CPanel(new ALayout());
private CComboBox productField;
private VNumber productQty = new VNumber("Qty", true, false, true, DisplayType.Quantity, Msg.translate(Env.getCtx(), "Qty"));
private CComboBox orderField;
private CComboBox invoiceField;
private CComboBox projectField;
/**************************************************************************
* Create Selection Panel
* @param order
* @param invoice
* @param project
*/
private void createSelectionPanel (boolean order, boolean invoice, boolean project)
{
int row = 0;
selectionPanel.setBorder(new TitledBorder(Msg.translate(Env.getCtx(), "Selection")));
productField = new CComboBox(getProducts());
CLabel label = new CLabel(Msg.translate(Env.getCtx(), "M_Product_ID"));
label.setLabelFor(productField);
selectionPanel.add(label, new ALayoutConstraint(row++, 0));
selectionPanel.add(productField);
productField.addActionListener(this);
// Qty
label = new CLabel (productQty.getTitle());
label.setLabelFor(productQty);
selectionPanel.add(label);
selectionPanel.add(productQty);
productQty.setValue(Env.ONE);
productQty.addActionListener(this);
if (order)
{
orderField = new CComboBox(getOrders());
label = new CLabel (Msg.translate(Env.getCtx(), "C_Order_ID"));
label.setLabelFor(orderField);
selectionPanel.add(label, new ALayoutConstraint(row++, 0));
selectionPanel.add(orderField);
orderField.addActionListener(this);
}
if (invoice)
{
invoiceField = new CComboBox(getInvoices());
label = new CLabel (Msg.translate(Env.getCtx(), "C_Invoice_ID"));
label.setLabelFor(invoiceField);
selectionPanel.add(label, new ALayoutConstraint(row++, 0));
selectionPanel.add(invoiceField);
invoiceField.addActionListener(this);
}
if (project)
{
projectField = new CComboBox(getProjects());
label = new CLabel (Msg.translate(Env.getCtx(), "C_Project_ID"));
label.setLabelFor(projectField);
selectionPanel.add(label, new ALayoutConstraint(row++, 0));
selectionPanel.add(projectField);
projectField.addActionListener(this);
}
// Enabled in ActionPerformed
confirmPanel.getOKButton().setEnabled(false);
// Size
Dimension size = selectionPanel.getPreferredSize();
size.width = WINDOW_WIDTH;
selectionPanel.setPreferredSize(size);
} // createSelectionPanel
/**
* Get Array of BOM Products
* @return products
*/
private KeyNamePair[] getProducts()
{
String sql = "SELECT M_Product_ID, Name "
+ "FROM M_Product "
+ "WHERE IsBOM='Y' AND IsVerified='Y' AND IsActive='Y' "
+ "ORDER BY Name";
return DB.getKeyNamePairs(MRole.getDefault().addAccessSQL(
sql, "M_Product", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO), true);
} // getProducts
/**
* Get Array of open Orders
* @return orders
*/
private KeyNamePair[] getOrders()
{
String sql = "SELECT C_Order_ID, DocumentNo || '_' || GrandTotal "
+ "FROM C_Order "
+ "WHERE Processed='N' AND DocStatus='DR' "
+ "ORDER BY DocumentNo";
return DB.getKeyNamePairs(MRole.getDefault().addAccessSQL(
sql, "C_Order", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO), true);
} // getOrders
/**
* Get Array of open non service Projects
* @return orders
*/
private KeyNamePair[] getProjects()
{
String sql = "SELECT C_Project_ID, Name "
+ "FROM C_Project "
+ "WHERE Processed='N' AND IsSummary='N' AND IsActive='Y'"
+ " AND ProjectCategory<>'S' "
+ "ORDER BY Name";
return DB.getKeyNamePairs(MRole.getDefault().addAccessSQL(
sql, "C_Project", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO), true);
} // getProjects
/**
* Get Array of open Invoices
* @return invoices
*/
private KeyNamePair[] getInvoices()
{
String sql = "SELECT C_Invoice_ID, DocumentNo || '_' || GrandTotal "
+ "FROM C_Invoice "
+ "WHERE Processed='N' AND DocStatus='DR' "
+ "ORDER BY DocumentNo";
return DB.getKeyNamePairs(MRole.getDefault().addAccessSQL(
sql, "C_Invoice", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO), true);
} // getInvoices
/**************************************************************************
* Create Main Panel.
* Called when changing Product
*/
private void createMainPanel ()
{
log.config(": " + m_product);
this.removeAll();
this.setPreferredSize(null);
this.invalidate();
this.setBorder(null);
//
m_selectionList.clear();
m_productList.clear();
m_qtyList.clear();
m_buttonGroups.clear();
//
this.setLayout (new ALayout());
String title = Msg.getMsg(Env.getCtx(), "SelectProduct");
if (m_product != null && m_product.get_ID() > 0)
{
title = m_product.getName();
if (m_product.getDescription() != null && m_product.getDescription().length() > 0)
this.setToolTipText(m_product.getDescription());
m_bomLine = 0;
addBOMLines(m_product, m_qty);
}
this.setBorder (new TitledBorder(title));
} // createMainPanel
/**
* Add BOM Lines to this.
* Called recursively
* @param product product
* @param qty quantity
*/
private void addBOMLines (MProduct product, BigDecimal qty)
{
MProductBOM[] bomLines = MProductBOM.getBOMLines(product);
for (int i = 0; i < bomLines.length; i++)
addBOMLine (bomLines[i], qty);
log.fine("#" + bomLines.length);
} // addBOMLines
/**
* Add BOM Line to this.
* Calls addBOMLines if added product is a BOM
* @param line BOM Line
* @param qty quantity
*/
private void addBOMLine (MProductBOM line, BigDecimal qty)
{
log.fine(line.toString());
String bomType = line.getBOMType();
if (bomType == null)
bomType = MProductBOM.BOMTYPE_StandardPart;
//
BigDecimal lineQty = line.getBOMQty().multiply(qty);
MProduct product = line.getProduct();
if (product == null)
return;
if (product.isBOM() && product.isVerified())
addBOMLines (product, lineQty); // recursive
else
addDisplay (line.getM_Product_ID(),
product.getM_Product_ID(), bomType, product.getName(), lineQty);
} // addBOMLine
/**
* Add Line to Display
* @param parentM_Product_ID parent product
* @param M_Product_ID product
* @param bomType bom type
* @param name name
* @param lineQty qty
*/
private void addDisplay (int parentM_Product_ID,
int M_Product_ID, String bomType, String name, BigDecimal lineQty)
{
log.fine("M_Product_ID=" + M_Product_ID + ",Type=" + bomType + ",Name=" + name + ",Qty=" + lineQty);
//
boolean selected = true;
if (MProductBOM.BOMTYPE_StandardPart.equals(bomType))
{
String title = "";
JCheckBox cb = new JCheckBox(title);
cb.setSelected(true);
cb.setEnabled(false);
// cb.addActionListener(this); // will not change
m_selectionList.add(cb);
this.add(cb, new ALayoutConstraint(m_bomLine++, 0));
}
else if (MProductBOM.BOMTYPE_OptionalPart.equals(bomType))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -