- ported ProcessCtl to WProcessCtl to remove swing dependency for process and report
- modify ReportCtl to call WProcessCtl using reflection
- refactor and cleanup of ProcessModalDialog
- modify WReport to call WProcessCtl instead of ProcessCtl
This commit is contained in:
Heng Sin Low 2009-12-14 03:28:15 +00:00
parent eebe80ec8f
commit 7e698c6883
5 changed files with 186 additions and 33 deletions

View File

@ -33,6 +33,7 @@ import org.compiere.util.ASyncProcess;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.compiere.util.Ini; import org.compiere.util.Ini;
import org.compiere.util.Trx;
/** /**
* Report Controller. * Report Controller.
@ -285,7 +286,26 @@ public class ReportCtl
pi.setPrintPreview( !IsDirectPrint ); pi.setPrintPreview( !IsDirectPrint );
pi.setRecord_ID ( Record_ID ); pi.setRecord_ID ( Record_ID );
// Execute Process // Execute Process
ProcessCtl worker = ProcessCtl.process(parent, WindowNo, pi, null); if (Ini.isClient())
{
ProcessCtl.process(parent, WindowNo, pi, null);
}
else
{
try
{
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (loader == null)
loader = ReportCtl.class.getClassLoader();
Class<?> clazz = loader.loadClass("org.adempiere.webui.apps.WProcessCtl");
Method method = clazz.getDeclaredMethod("process", ASyncProcess.class, Integer.TYPE, ProcessInfo.class, Trx.class);
method.invoke(null, parent, WindowNo, pi, null);
}
catch (Exception e)
{
throw new AdempiereException(e);
}
}
} }
else else
{ {

View File

@ -60,39 +60,27 @@ import org.zkoss.zul.Html;
*/ */
public class ProcessModalDialog extends Window implements EventListener public class ProcessModalDialog extends Window implements EventListener
{ {
/** /**
* *
*/ */
private static final long serialVersionUID = -351486051681812866L; private static final long serialVersionUID = 8828804363347622789L;
private boolean m_autoStart; private boolean m_autoStart;
/** /**
* Dialog to start a process/report
* @param ctx
* @param parent
* @param title
* @param aProcess * @param aProcess
* @param WindowNo * @param WindowNo
* @param AD_Process_ID * @param pi
* @param tableId
* @param recordId
* @param autoStart * @param autoStart
*/ */
public ProcessModalDialog (Window parent, String title, public ProcessModalDialog(ASyncProcess aProcess, int WindowNo, ProcessInfo pi, boolean autoStart)
ASyncProcess aProcess, int WindowNo, int AD_Process_ID,
int tableId, int recordId, boolean autoStart)
{ {
log.info("Process=" + AD_Process_ID );
m_ctx = Env.getCtx(); m_ctx = Env.getCtx();
m_ASyncProcess = aProcess; m_ASyncProcess = aProcess;
m_WindowNo = WindowNo; m_WindowNo = WindowNo;
m_AD_Process_ID = AD_Process_ID; m_pi = pi;
m_tableId = tableId;
m_recordId = recordId;
m_autoStart = autoStart; m_autoStart = autoStart;
log.info("Process=" + pi.getAD_Process_ID());
try try
{ {
initComponents(); initComponents();
@ -102,6 +90,41 @@ public class ProcessModalDialog extends Window implements EventListener
{ {
log.log(Level.SEVERE, "", ex); log.log(Level.SEVERE, "", ex);
} }
}
/**
* Dialog to start a process/report
* @param ctx
* @param aProcess
* @param WindowNo
* @param AD_Process_ID
* @param tableId
* @param recordId
* @param autoStart
*/
public ProcessModalDialog ( ASyncProcess aProcess, int WindowNo, int AD_Process_ID, int tableId, int recordId, boolean autoStart)
{
this(aProcess, WindowNo, new ProcessInfo("", AD_Process_ID, tableId, recordId), autoStart);
}
/**
* Dialog to start a process/report
* @param ctx
* @param parent not used
* @param title not used
* @param aProcess
* @param WindowNo
* @param AD_Process_ID
* @param tableId
* @param recordId
* @param autoStart
* @deprecated
*/
public ProcessModalDialog (Window parent, String title,
ASyncProcess aProcess, int WindowNo, int AD_Process_ID,
int tableId, int recordId, boolean autoStart)
{
this(aProcess, WindowNo, AD_Process_ID, tableId, recordId, autoStart);
} // ProcessDialog } // ProcessDialog
private void initComponents() { private void initComponents() {
@ -137,9 +160,6 @@ public class ProcessModalDialog extends Window implements EventListener
private ASyncProcess m_ASyncProcess; private ASyncProcess m_ASyncProcess;
private int m_WindowNo; private int m_WindowNo;
private Properties m_ctx; private Properties m_ctx;
private int m_tableId;
private int m_recordId;
private int m_AD_Process_ID;
private String m_Name = null; private String m_Name = null;
private StringBuffer m_messageText = new StringBuffer(); private StringBuffer m_messageText = new StringBuffer();
private String m_ShowHelp = null; // Determine if a Help Process Window is shown private String m_ShowHelp = null; // Determine if a Help Process Window is shown
@ -206,7 +226,7 @@ public class ProcessModalDialog extends Window implements EventListener
try try
{ {
PreparedStatement pstmt = DB.prepareStatement(sql, null); PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, m_AD_Process_ID); pstmt.setInt(1, m_pi.getAD_Process_ID());
if (trl) if (trl)
pstmt.setString(2, Env.getAD_Language(m_ctx)); pstmt.setString(2, Env.getAD_Language(m_ctx));
ResultSet rs = pstmt.executeQuery(); ResultSet rs = pstmt.executeQuery();
@ -245,9 +265,9 @@ public class ProcessModalDialog extends Window implements EventListener
// Move from APanel.actionButton // Move from APanel.actionButton
m_pi = new ProcessInfo(m_Name, m_AD_Process_ID, m_tableId, m_recordId);
m_pi.setAD_User_ID (Env.getAD_User_ID(Env.getCtx())); m_pi.setAD_User_ID (Env.getAD_User_ID(Env.getCtx()));
m_pi.setAD_Client_ID(Env.getAD_Client_ID(Env.getCtx())); m_pi.setAD_Client_ID(Env.getAD_Client_ID(Env.getCtx()));
m_pi.setTitle(m_Name);
parameterPanel = new ProcessParameterPanel(m_WindowNo, m_pi); parameterPanel = new ProcessParameterPanel(m_WindowNo, m_pi);
centerPanel.getChildren().clear(); centerPanel.getChildren().clear();
if ( parameterPanel.init() ) { if ( parameterPanel.init() ) {

View File

@ -0,0 +1,118 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.adempiere.webui.apps;
import org.adempiere.webui.component.Window;
import org.compiere.apps.IProcessParameter;
import org.compiere.apps.ProcessCtl;
import org.compiere.model.MPInstance;
import org.compiere.process.ProcessInfo;
import org.compiere.util.ASyncProcess;
import org.compiere.util.CLogger;
import org.compiere.util.Env;
import org.compiere.util.Msg;
import org.compiere.util.Trx;
/**
* Ported from org.compiere.apps.ProcessCtl
* @author hengsin
*
*/
public class WProcessCtl {
/** Logger */
private static CLogger log = CLogger.getCLogger(WProcessCtl.class);
/**
* Process Control
* <code>
* - Get Instance ID
* - Get Parameters
* - execute (lock - start process - unlock)
* </code>
* Creates a ProcessCtl instance, which calls
* lockUI and unlockUI if parent is a ASyncProcess
* <br>
*
* @param aProcess ASyncProcess & Container
* @param WindowNo window no
* @param pi ProcessInfo process info
* @param trx Transaction
*/
public static void process (ASyncProcess aProcess, int WindowNo, ProcessInfo pi, Trx trx)
{
log.fine("WindowNo=" + WindowNo + " - " + pi);
MPInstance instance = null;
try
{
instance = new MPInstance(Env.getCtx(), pi.getAD_Process_ID(), pi.getRecord_ID());
}
catch (Exception e)
{
pi.setSummary (e.getLocalizedMessage());
pi.setError (true);
log.warning(pi.toString());
}
catch (Error e)
{
pi.setSummary (e.getLocalizedMessage());
pi.setError (true);
log.warning(pi.toString());
}
if (!instance.save())
{
pi.setSummary (Msg.getMsg(Env.getCtx(), "ProcessNoInstance"));
pi.setError (true);
}
pi.setAD_PInstance_ID (instance.getAD_PInstance_ID());
// Get Parameters (Dialog)
ProcessModalDialog para = new ProcessModalDialog(aProcess, WindowNo, pi, false);
if (para.isValid())
{
para.setWidth("500px");
para.setVisible(true);
para.setPosition("center");
para.setAttribute(Window.MODE_KEY, Window.MODE_MODAL);
AEnv.showWindow(para);
}
} // execute
/**
* Async Process - Do it all.
* <code>
* - Get Instance ID
* - Get Parameters
* - execute (lock - start process - unlock)
* </code>
* Creates a ProcessCtl instance, which calls
* lockUI and unlockUI if parent is a ASyncProcess
* <br>
* Called from ProcessDialog.actionPerformed
*
* @param parent ASyncProcess & Container
* @param WindowNo window no
* @param paraPanel Process Parameter Panel
* @param pi ProcessInfo process info
* @param trx Transaction
*/
public static void process(ASyncProcess parent, int WindowNo, IProcessParameter parameter, ProcessInfo pi, Trx trx)
{
ProcessCtl.process(parent, WindowNo, parameter, pi, trx);
}
}

View File

@ -22,14 +22,11 @@ import java.util.logging.Level;
import javax.sql.RowSet; import javax.sql.RowSet;
import org.adempiere.webui.component.Listbox;
import org.adempiere.webui.window.FDialog; import org.adempiere.webui.window.FDialog;
import org.compiere.apps.ProcessCtl;
import org.compiere.model.MQuery; import org.compiere.model.MQuery;
import org.compiere.model.MRole; import org.compiere.model.MRole;
import org.compiere.model.MTable; import org.compiere.model.MTable;
import org.compiere.model.PrintInfo; import org.compiere.model.PrintInfo;
import org.compiere.print.AReport;
import org.compiere.print.MPrintFormat; import org.compiere.print.MPrintFormat;
import org.compiere.print.ReportCtl; import org.compiere.print.ReportCtl;
import org.compiere.print.ReportEngine; import org.compiere.print.ReportEngine;
@ -92,13 +89,11 @@ public class WReport implements EventListener {
/** The Query */ /** The Query */
private MQuery m_query; private MQuery m_query;
/** The Popup */
private Listbox m_listbox;
private Menupopup m_popup; private Menupopup m_popup;
/** The Option List */ /** The Option List */
private ArrayList<KeyNamePair> m_list = new ArrayList<KeyNamePair>(); private ArrayList<KeyNamePair> m_list = new ArrayList<KeyNamePair>();
/** Logger */ /** Logger */
private static CLogger log = CLogger.getCLogger(AReport.class); private static CLogger log = CLogger.getCLogger(WReport.class);
/** The parent window for locking/unlocking during process execution */ /** The parent window for locking/unlocking during process execution */
Component parent; Component parent;
/** The parent window number */ /** The parent window number */
@ -213,7 +208,7 @@ public class WReport implements EventListener {
ProcessInfo pi = new ProcessInfo ("", pf.getJasperProcess_ID()); ProcessInfo pi = new ProcessInfo ("", pf.getJasperProcess_ID());
// Execute Process // Execute Process
ProcessCtl worker = ProcessCtl.process(null, WindowNo, pi, null); WProcessCtl.process(null, WindowNo, pi, null);
} }
else else
{ {

View File

@ -376,7 +376,7 @@ public class WPaySelect extends PaySelect
int AD_Proces_ID = 155; // C_PaySelection_CreatePayment int AD_Proces_ID = 155; // C_PaySelection_CreatePayment
// Execute Process // Execute Process
ProcessModalDialog dialog = new ProcessModalDialog(null, form.getFormName(), this, m_WindowNo, ProcessModalDialog dialog = new ProcessModalDialog(this, m_WindowNo,
AD_Proces_ID, X_C_PaySelection.Table_ID, m_ps.getC_PaySelection_ID(), false); AD_Proces_ID, X_C_PaySelection.Table_ID, m_ps.getC_PaySelection_ID(), false);
if (dialog.isValid()) { if (dialog.isValid()) {
try { try {