⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vbutton.java

📁 Java写的ERP系统
💻 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  Business Solution
 * The Initial Developer of the Original Code is Jorg Janke  and ComPiere, Inc.
 * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
 * created by ComPiere are Copyright (C) ComPiere, Inc.;   All Rights Reserved.
 * Contributor(s): ______________________________________.
 *****************************************************************************/
package org.compiere.grid.ed;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.sql.*;
import java.beans.*;

import org.compiere.util.*;
import org.compiere.apps.*;
import org.compiere.plaf.*;
import org.compiere.swing.*;

/**
 *  General Button.
 *  <pre>
 *  Special Buttons:
 *      Payment,
 *      Processing,
 *      CreateFrom,
 *      Record_ID       - Zoom
 *  </pre>
 *  Maintains all values for display in m_values
 *  @see APanel.actionButton for process start
 *
 * 	@author 	Jorg Janke
 * 	@version 	$Id: VButton.java,v 1.16 2003/02/14 06:44:14 jjanke Exp $
 */
public final class VButton extends CButton
	implements VEditor
{
	/**
	 *	Constructor
	 *  @param columnName
	 *  @param mandatory
	 *  @param isReadOnly
	 *  @param isUpdateable
	 *  @param text
	 *  @param description
	 *  @param help
	 *  @param AD_Process_ID
	 */
	public VButton (String columnName, boolean mandatory, boolean isReadOnly, boolean isUpdateable,
		String text, String description, String help, int AD_Process_ID)
	{
		super (text);
		super.setActionCommand(columnName);
		m_columnName = columnName;
		//
		setMandatory (mandatory);
		if (isReadOnly || !isUpdateable)
			setReadWrite(false);
		else
			setReadWrite(true);

		//	Special Buttons
		if (columnName.equals("PaymentRule"))
		{
			readReference(195);
			this.setForeground(Color.blue);
			setIcon(Env.getImageIcon("Payment16.gif"));    //  29*14
		}
		else if (columnName.equals("DocAction"))
		{
			readReference(135);
			this.setForeground(Color.blue);
			setIcon(Env.getImageIcon("Process16.gif"));    //  16*16
		}
		else if (columnName.equals("CreateFrom"))
		{
			setIcon(Env.getImageIcon("Copy16.gif"));       //  16*16
		}
		else if (columnName.equals("Record_ID"))
		{
			setIcon(Env.getImageIcon("Zoom16.gif"));       //  16*16
			this.setText(Msg.getMsg(Env.getCtx(), "ZoomDocument"));
		}
		else if (columnName.equals("Posted"))
		{
			readReference(234);
			this.setForeground(Color.magenta);
			setIcon(Env.getImageIcon("InfoAccount16.gif"));    //  16*16
		}

		//	Deescription & Help
		m_description = description;
		if (description == null || description.length() == 0)
			m_description = "";
		else
			setToolTipText(m_description);
		//
		m_help = help;
		if (help == null)
			m_help = "";
		m_AD_Process_ID = AD_Process_ID;
	}	//	VButton

	/**
	 *  Dispose
	 */
	public void dispose()
	{
		m_actionListener = null;
		if (m_values != null)
			m_values.clear();
		m_values = null;
	}   //  dispose

	private String			m_columnName;
	private boolean			m_mandatory;
	private Object			m_value;
	private ActionListener	m_actionListener;
	/** List of Key/Name        */
	private HashMap 		m_values = null;
	/** Description as ToolTip  */
	private	String			m_description = "";
	private String			m_help;
	private int				m_AD_Process_ID;

	/**
	 *	Set Value
	 *  @param value
	 */
	public void setValue(Object value)
	{
		m_value = value;
		//  No display for Record_ID
		if (m_values == null || m_columnName.equals("Record_ID"))
			return;
		//
		String name = (String)m_values.get(value);
		setText (name != null ? name : "");
	}	//	setValue

	/**
	 *  Property Change Listener
	 *  @param evt
	 */
	public void propertyChange (PropertyChangeEvent evt)
	{
		if (evt.getPropertyName().equals(org.compiere.model.MField.PROPERTY))
			setValue(evt.getNewValue());
	}   //  propertyChange

	/**
	 *	Return Value
	 *  @return value
	 */
	public Object getValue()
	{
		return m_value;
	}	//	getValue

	/**
	 *  Return Display Value
	 *  @return String value
	 */
	public String getDisplay()
	{
		return m_value.toString();
	}   //  getDisplay

	/**
	 *	Set Mandatory	- NOP
	 *  @param mandatory
	 */
	public void setMandatory (boolean mandatory)
	{
		m_mandatory = mandatory;
	}	//	setMandatory

	/**
	 *	Mandatory?
	 *  @return true if mandatory
	 */
	public boolean isMandatory()
	{
		return m_mandatory;
	}	//	isMandatory

	/**
	 *	Set Background - NOP
	 *  @param error
	 */
	public void setBackground(boolean error)
	{
	}	//	setBackground

	/**
	 *	Get ColumnName
	 *  @return column name
	 */
	public String getColumnName()
	{
		return m_columnName;
	}	//	getColumnName

	/**
	 *	Get Description
	 *  @return description string
	 */
	public String getDescription()
	{
		return m_description;
	}	//	getDescription

	/**
	 *	Get Help
	 *  @return help string
	 */
	public String getHelp()
	{
		return m_help;
	}	//	getHelp

	/**
	 *	Get AD_Process_ID
	 *  @return AD_Process_ID or 0
	 */
	public int getProcess_ID()
	{
		return m_AD_Process_ID;
	}	//	getProcess_ID

	/**
	 *	Add ActionListener
	 *  @param actionListener
	 */
	public void addActionListener(ActionListener actionListener)
	{
		m_actionListener = actionListener;
		super.addActionListener(actionListener);
	}	//	addActionListener

	/**
	 *	String representation
	 *  @return String representation
	 */
	public String toString()
	{
		StringBuffer sb = new StringBuffer ("VButton[");
		sb.append(m_columnName);
		sb.append("=").append(m_value).append("]");
		return sb.toString();
	}	//	toString

	/**
	 *	Fill m_Values with Ref_List values
	 *  @param AD_Reference_ID
	 */
	private void readReference( int AD_Reference_ID)
	{
		m_values = new HashMap();
		String SQL;
		if (Env.isBaseLanguage(Env.getCtx(), "AD_Ref_List"))
			SQL = "SELECT Value, Name FROM AD_Ref_List WHERE AD_Reference_ID=?";
		else
			SQL = "SELECT l.Value, t.Name FROM AD_Ref_List l, AD_Ref_List_Trl t "
				+ "WHERE l.AD_Ref_List_ID=t.AD_Ref_List_ID"
				+ " AND t.AD_Language='" + Env.getAD_Language(Env.getCtx()) + "'"
				+ " AND l.AD_Reference_ID=?";

		try
		{
			PreparedStatement pstmt = DB.prepareStatement(SQL);
			pstmt.setInt(1, AD_Reference_ID);
			ResultSet rs = pstmt.executeQuery();
			while (rs.next())
			{
				String value = rs.getString(1);
				String name = rs.getString(2);
				m_values.put(value, name);
			}
			rs.close();
			pstmt.close();
		}
		catch (SQLException e)
		{
			Log.error("VButton.readReference", e);
		}
	}	//	readReference

	/**
	 *	Return value/name
	 *  @return HashMap with Value/Names
	 */
	public HashMap getValues()
	{
		return m_values;
	}	//	getValues

	/**
	 *  Set Field/WindowNo for ValuePreference (NOP)
	 *  @param mField
	 */
	public void setField (org.compiere.model.MField mField)
	{
	}   //  setField

}	//	VButton

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -