📄 infopattribute.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.search;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
import java.util.logging.*;
import javax.swing.*;
import java.math.*;
import org.compiere.apps.*;
import org.compiere.grid.ed.*;
import org.compiere.model.*;
import org.compiere.swing.*;
import org.compiere.util.*;
/**
* Search by Product Attribute.
*
* @author Jorg Janke
* @version $Id: InfoPAttribute.java,v 1.17 2005/11/14 02:10:58 jjanke Exp $
*/
public class InfoPAttribute extends CDialog
{
/**
* Constructor.
* Called from InfoProduct,cmd_InfoPAttribute
* @param parent
*/
public InfoPAttribute (JDialog parent)
{
super (parent, Msg.getMsg(Env.getCtx(), "InfoPAttribute"), true);
try
{
jbInit();
dynInit();
}
catch (Exception e)
{
log.log(Level.SEVERE, "InfoPAttribute", e);
}
AEnv.showCenterWindow(parent, this);
} // InfoPAttribute
/** Resulting Query */
private String m_query = "";
/** Product Attribure Editors */
private ArrayList<Component> m_productEditors = new ArrayList<Component>();
private ArrayList<Component> m_productEditorsTo = new ArrayList<Component>();
/** Instance Attribute Editors */
private ArrayList<Component> m_instanceEditors = new ArrayList<Component>();
private ArrayList<Component> m_instanceEditorsTo = new ArrayList<Component>();
/** Logger */
private static CLogger log = CLogger.getCLogger(InfoPAttribute.class);
private CPanel mainPanel = new CPanel();
private BorderLayout mainLayout = new BorderLayout();
private CPanel centerPanel = new CPanel();
private ConfirmPanel confirmPanel = new ConfirmPanel(true);
//
private CLabel serNoLabel = new CLabel(Msg.translate(Env.getCtx(), "SerNo"));
private VString serNoField = new VString("SerNo", false, false, true, 10, 20, null, null);
private CLabel lotLabel = new CLabel(Msg.translate(Env.getCtx(), "Lot"));
private VString lotField = new VString("Lot", false, false, true, 10, 20, null, null);
private VComboBox guaranteeDateSelection = null;
private VDate guaranteeDateField = new VDate ("GuaranteeDate", false, false, true, DisplayType.Date, Msg.translate(Env.getCtx(), "GuaranteeDate"));
private CLabel lotLabel2 = new CLabel(Msg.translate(Env.getCtx(), "M_Lot_ID"));
private VComboBox lotSelection = null;
//
/**
* Static Init
* @throws Exception
*/
private void jbInit() throws Exception
{
this.getContentPane().add(mainPanel, BorderLayout.CENTER);
mainPanel.setLayout(mainLayout);
mainPanel.add(centerPanel, BorderLayout.CENTER);
centerPanel.setLayout(new ALayout());
// ConfirmPanel
confirmPanel.addActionListener(this);
mainPanel.add(confirmPanel, BorderLayout.SOUTH);
} // jbInit
/**
* Dynamic Init of the Center Panel
*/
private void dynInit()
{
int row = addAttributes();
//
String s = Msg.translate(Env.getCtx(), "GuaranteeDate");
guaranteeDateSelection = new VComboBox (new Object[]
{s + " <", s + " =", s + " >"});
// guaranteeDateSelection.setPreferredSize();
initLotSelection();
// Fixed Instance Selection Fields
centerPanel.add(serNoLabel, new ALayoutConstraint(row++, 0));
centerPanel.add(serNoField, null);
centerPanel.add(lotLabel, new ALayoutConstraint(row++, 0));
centerPanel.add(lotField, null);
centerPanel.add(lotLabel2, new ALayoutConstraint(row++, 0));
centerPanel.add(lotSelection, null);
centerPanel.add(guaranteeDateSelection, new ALayoutConstraint(row++, 0));
centerPanel.add(guaranteeDateField, null);
//
Dimension d = centerPanel.getPreferredSize();
d.width = 400;
centerPanel.setPreferredSize(d);
} // dynInit
/**
* Add Attributes
* @return rows
*/
private int addAttributes()
{
int row = 0;
PreparedStatement pstmt = null;
String sql = MRole.getDefault().addAccessSQL(
"SELECT M_Attribute_ID, Name, Description, AttributeValueType, IsInstanceAttribute "
+ "FROM M_Attribute "
+ "WHERE IsActive='Y' "
+ "ORDER BY IsInstanceAttribute, Name",
"M_Attribute", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
try
{
pstmt = DB.prepareStatement(sql, null);
ResultSet rs = pstmt.executeQuery();
boolean instanceLine = false;
while (rs.next())
{
int attribute_ID = rs.getInt(1);
String name = rs.getString(2);
String description = rs.getString(3);
String attributeValueType = rs.getString(4);
boolean isInstanceAttribute = "Y".equals(rs.getString(5));
// Instance switch
if (!instanceLine && isInstanceAttribute)
{
CPanel group = new CPanel();
group.setBorder(new VLine(Msg.translate(Env.getCtx(), "IsInstanceAttribute")));
group.add(Box.createVerticalStrut(VLine.SPACE));
centerPanel.add(group, new ALayoutConstraint(row++, 0));
instanceLine = true;
}
//
CLabel label = new CLabel(name);
if (description != null && description.length() > 0)
label.setToolTipText(description);
centerPanel.add(label, new ALayoutConstraint(row++, 0));
Component field = null;
if (MAttribute.ATTRIBUTEVALUETYPE_List.equals(attributeValueType))
field = new VComboBox(getAttributeList(attribute_ID));
else if (MAttribute.ATTRIBUTEVALUETYPE_Number.equals(attributeValueType))
field = new VNumber(name, false, false, true, DisplayType.Number, name);
else
field = new VString(name, false, false, true, 10, 40, null, null);
label.setLabelFor(field);
centerPanel.add(field, null);
//
field.setName(String.valueOf(attribute_ID));
if (isInstanceAttribute)
m_instanceEditors.add(field);
else
m_productEditors.add(field);
// To (numbers)
Component fieldTo = null;
if (MAttribute.ATTRIBUTEVALUETYPE_Number.equals(attributeValueType))
{
fieldTo = new VNumber(name, false, false, true, DisplayType.Number, name);
centerPanel.add(new CLabel("-"), null);
centerPanel.add(fieldTo, null);
}
if (isInstanceAttribute)
m_instanceEditorsTo.add(fieldTo);
else
m_productEditorsTo.add(fieldTo);
}
rs.close();
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
}
try
{
if (pstmt != null)
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
}
return row;
} // addProductAttributes
/**
* Get Attribute List
* @param M_Attribute_ID attribure
* @return array
*/
private KeyNamePair[] getAttributeList(int M_Attribute_ID)
{
ArrayList<KeyNamePair> list = new ArrayList<KeyNamePair>();
list.add(new KeyNamePair(-1, ""));
PreparedStatement pstmt = null;
String sql = MRole.getDefault().addAccessSQL(
"SELECT M_AttributeValue_ID, Value, Name "
+ "FROM M_AttributeValue "
+ "WHERE M_Attribute_ID=? "
+ "ORDER BY 2",
"M_AttributeValue", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
try
{
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, M_Attribute_ID);
ResultSet rs = pstmt.executeQuery();
while (rs.next())
list.add(new KeyNamePair(rs.getInt(1), rs.getString(3)));
rs.close();
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
}
try
{
if (pstmt != null)
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
}
KeyNamePair[] retValue = new KeyNamePair[list.size()];
list.toArray(retValue);
return retValue;
} // getAttributeList
/**
* Initialize Lot Selection
*/
private void initLotSelection()
{
ArrayList<KeyNamePair> list = new ArrayList<KeyNamePair>();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -