📄 vdocaction.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 java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
import java.util.*;
import org.compiere.util.*;
import org.compiere.model.*;
import org.compiere.apps.*;
import org.compiere.plaf.*;
import org.compiere.swing.*;
/**
* Displays valid Document Action Options based on context
*
* @author Jorg Janke
* @version $Id: VDocAction.java,v 1.6 2002/08/23 04:03:22 jjanke Exp $
*/
public class VDocAction extends JDialog implements ActionListener
{
/**
* Constructor
* started from APanel
* @param WindowNo
* @param mTab
* @param button
*/
public VDocAction(int WindowNo, MTab mTab, VButton button)
{
super((JFrame)Env.getWindow(WindowNo), Msg.translate(Env.getCtx(), "DocAction"), true);
Log.trace(Log.l3_Util, "VDocAction");
m_mTab = mTab;
//
try
{
jbInit();
}
catch(Exception ex)
{
Log.error("VDocAction", ex);
}
// dynamic init preparation
m_AD_Table_ID = Env.getContextAsInt(Env.getCtx(), WindowNo, "BaseTable_ID");
if (s_value == null)
readReference();
//
dynInit();
//
AEnv.positionCenterWindow(Env.getWindow(WindowNo), this);
} // VDocAction
//
private int m_AD_Table_ID;
private boolean m_OKpressed = false;
private MTab m_mTab;
//
private static String[] s_value = null;
private static String[] s_name;
private static String[] s_description;
//
private CPanel mainPanel = new CPanel();
private BorderLayout mainLayout = new BorderLayout();
private CPanel northPanel = new CPanel();
private CComboBox actionCombo = new CComboBox();
private JLabel actionLabel = new JLabel();
private JScrollPane centerPane = new JScrollPane();
private JTextArea message = new JTextArea();
private FlowLayout northLayout = new FlowLayout();
private ConfirmPanel confirmPanel = new ConfirmPanel(true);
/**
* Static Init
* @throws Exception
*/
void jbInit() throws Exception
{
CompiereColor.setBackground(this);
mainPanel.setLayout(mainLayout);
actionLabel.setText(Msg.translate(Env.getCtx(), "DocAction"));
actionCombo.addActionListener(this);
message.setLineWrap(true);
message.setPreferredSize(new Dimension(350, 35));
message.setWrapStyleWord(true);
message.setBackground(CompierePLAF.getFieldBackground_Inactive());
message.setEditable(false);
northPanel.setLayout(northLayout);
northLayout.setAlignment(FlowLayout.RIGHT);
getContentPane().add(mainPanel);
mainPanel.add(northPanel, BorderLayout.NORTH);
northPanel.add(actionLabel, null);
northPanel.add(actionCombo, null);
mainPanel.add(centerPane, BorderLayout.CENTER);
centerPane.getViewport().add(message, null);
//
mainPanel.add(confirmPanel, BorderLayout.SOUTH);
confirmPanel.addActionListener(this);
} // jbInit
/**
* Dynamic Init - determine valid DocActions based on DocStatus for the different documents.
* <pre>
* DocStatus (131)
?? Unknown
AP * Approved
CH Changed
CL * Closed
CO * Completed
DR Drafted
IN Inactive
NA Not Approved
PE Posting Error
PO * Posted
PR * Printed
RE Reversed
TE Transfer Error
TR * Transferred
VO * Voided
XX Being Processed
*
* DocAction (135)
-- <None>
AP * Approve
CL * Close
CO * Complete
PO * Post
PR * Print
RA Reverse - Accrual
RC Reverse - Correction
RE RE-activate
RJ Reject
TR * Transfer
VO * Void
XL Unlock
* </pre>
*/
private void dynInit()
{
String DocStatus = (String)m_mTab.getValue("DocStatus");
String DocAction = (String)m_mTab.getValue("DocAction");
String Processing = (String)m_mTab.getValue("Processing");
if (DocStatus == null)
{
message.setText("*** ERROR ***");
return;
}
Log.trace(Log.l5_DData, "DocStatus=" + DocStatus + ", DocAction=" + DocAction
+ ", Processing=" + Processing + ", AD_Table_ID=" + m_AD_Table_ID);
String[] options = new String[s_value.length];
int index = 0;
//
/*******************
* General Actions
*/
// Locked
if (Processing != null && Processing.equals("Y"))
{
options[index++] = "XL"; // Unlock
}
// Approval required .. NA
else if (DocStatus.equals("NA"))
{
options[index++] = "AP"; // Approve -> IP
options[index++] = "RJ"; // Reject -> NA
options[index++] = "VO"; // Void -> VO
}
// Draft .. DR
else if (DocStatus.equals("DR"))
{
options[index++] = "CO"; // Complete -> CO
options[index++] = "VO"; // Void -> VO
}
// In Process .. IP
else if (DocStatus.equals("IP"))
{
options[index++] = "CO"; // Complete -> CO
options[index++] = "VO"; // Void -> VO
}
// Complete .. CO
else if (DocStatus.equals("CO"))
{
options[index++] = "CL"; // Close -> CL
}
// Closed, Voided, REversed .. CL/VO/RE
else if (DocStatus.equals("CL") || DocStatus.equals("VO") || DocStatus.equals("RE"))
return;
/********************
* Order
*/
if (m_AD_Table_ID == 259)
{
// Draft .. DR
if (DocStatus.equals("DR"))
options[index++] = "PR";// Process -> IP
// Complete .. CO
else if (DocStatus.equals("CO"))
options[index++] = "RE";// REactivate -> RE
}
/********************
* Invoice
*/
else if (m_AD_Table_ID == 318)
{
// Complete .. CO
if (DocStatus.equals("CO"))
options[index++] = "RC";// RevCorrect -> RC
}
/********************
* Payment
*/
else if (m_AD_Table_ID == 335)
{
// Complete .. CO
if (DocStatus.equals("CO"))
options[index++] = "RC";// RevCorrect -> RC
}
/**
* Fill actionCombo
*/
for (int i = 0; i < index; i++)
{
// Serach for option and add it
boolean added = false;
for (int j = 0; j < s_value.length && !added; j++)
if (options[i].equals(s_value[j]))
{
actionCombo.addItem(s_name[j]);
added = true;
}
}
// setDefault
if (DocAction.equals("--")) // If None, suggest closing
DocAction = "CL";
String defaultV = "";
for (int i = 0; i < s_value.length && defaultV.equals(""); i++)
if (DocAction.equals(s_value[i]))
defaultV = s_name[i];
if (!defaultV.equals(""))
actionCombo.setSelectedItem(defaultV);
} // dynInit
/**
* Number of options available (to decide to display it)
* @return item count
*/
public int getNumberOfOptions()
{
return actionCombo.getItemCount();
} // getNumberOfOptions
/**
* Should the process be started?
* @return OK pressed
*/
public boolean getStartProcess()
{
return m_OKpressed;
} // getStartProcess
/**
* Fill Vector with DocAction Ref_List(135) values
*/
private void readReference()
{
String SQL;
if (Env.isBaseLanguage(Env.getCtx(), "AD_Ref_List"))
SQL = "SELECT Value, Name, Description FROM AD_Ref_List "
+ "WHERE AD_Reference_ID=135 ORDER BY Name";
else
SQL = "SELECT l.Value, t.Name, t.Description "
+ "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=135 ORDER BY t.Name";
ArrayList v_value = new ArrayList();
ArrayList v_name = new ArrayList();
ArrayList v_description = new ArrayList();
try
{
PreparedStatement pstmt = DB.prepareStatement(SQL);
ResultSet rs = pstmt.executeQuery();
while (rs.next())
{
String value = rs.getString(1);
String name = rs.getString(2);
String description = rs.getString(3);
if (description == null)
description = "";
//
v_value.add(value);
v_name.add(name);
v_description.add(description);
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
Log.error("VDocAction.readReference", e);
}
// convert to arrays
int size = v_value.size();
s_value = new String[size];
s_name = new String[size];
s_description = new String[size];
for (int i = 0; i < size; i++)
{
s_value[i] = (String)v_value.get(i);
s_name[i] = (String)v_name.get(i);
s_description[i] = (String)v_description.get(i);
}
} // readReference
/**
* ActionListener
* @param e
*/
public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand().equals(ConfirmPanel.A_OK))
{
if (save())
{
dispose();
m_OKpressed = true;
}
}
else if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL))
dispose();
else if (e.getSource() != actionCombo)
return;
/**
* ActionCombo: display the description for the selection
*/
int index = getSelectedIndex();
// Display descriprion
if (index != -1)
message.setText(s_description[index]);
} // actionPerformed
/**
* Get index of selected choice
* @return index or -a
*/
private int getSelectedIndex()
{
int index = -1;
// get Selection
String sel = (String)actionCombo.getSelectedItem();
if (sel == null)
return index;
// find it in vector
for (int i = 0; i < s_name.length && index == -1; i++)
if (sel.equals(s_name[i]))
index = i;
//
return index;
} // getSelectedIndex
/**
* Save to Database
* @return true if saved to Tab
*/
private boolean save()
{
int index = getSelectedIndex();
if (index == -1)
return false;
// Save Selection
m_mTab.setValue("DocAction", s_value[index]);
return true;
} // save
} // VDocAction
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -