[ 1731053 ] Refactoring of ProcessCtl and ServerBean
This commit is contained in:
parent
b2fc7de3c1
commit
2ec286a428
|
@ -0,0 +1,29 @@
|
||||||
|
/******************************************************************************
|
||||||
|
* Product: Adempiere ERP & CRM Smart Business Solution *
|
||||||
|
* Copyright (C) 1999-2006 Adempiere, 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. *
|
||||||
|
*****************************************************************************/
|
||||||
|
package org.compiere.apps;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Low Heng Sin
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public interface IProcessParameter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save Parameter values
|
||||||
|
* @return true if parameters saved
|
||||||
|
*/
|
||||||
|
public boolean saveParameters(); // saveParameters
|
||||||
|
|
||||||
|
}
|
|
@ -24,7 +24,7 @@ import java.sql.*;
|
||||||
import java.util.logging.*;
|
import java.util.logging.*;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
import org.compiere.Adempiere;
|
import org.adempiere.util.ProcessUtil;
|
||||||
import org.compiere.db.*;
|
import org.compiere.db.*;
|
||||||
import org.compiere.interfaces.*;
|
import org.compiere.interfaces.*;
|
||||||
import org.compiere.model.*;
|
import org.compiere.model.*;
|
||||||
|
@ -42,10 +42,10 @@ import org.compiere.wf.*;
|
||||||
* - Added support for having description and parameter in one dialog
|
* - Added support for having description and parameter in one dialog
|
||||||
* - Added support to run db process remotely on server
|
* - Added support to run db process remotely on server
|
||||||
*/
|
*/
|
||||||
public class ProcessCtl extends Thread
|
public class ProcessCtl implements Runnable
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Async Process - Do it all.
|
* Process Control
|
||||||
* <code>
|
* <code>
|
||||||
* - Get Instance ID
|
* - Get Instance ID
|
||||||
* - Get Parameters
|
* - Get Parameters
|
||||||
|
@ -54,8 +54,8 @@ public class ProcessCtl extends Thread
|
||||||
* Creates a ProcessCtl instance, which calls
|
* Creates a ProcessCtl instance, which calls
|
||||||
* lockUI and unlockUI if parent is a ASyncProcess
|
* lockUI and unlockUI if parent is a ASyncProcess
|
||||||
* <br>
|
* <br>
|
||||||
* Called from ProcessCtl.startProcess, APanel.cmd_print,
|
* Called from APanel.cmd_print, APanel.actionButton and
|
||||||
* APanel.actionButton, VPaySelect.cmd_generate
|
* VPaySelect.cmd_generate
|
||||||
*
|
*
|
||||||
* @param parent ASyncProcess & Container
|
* @param parent ASyncProcess & Container
|
||||||
* @param WindowNo window no
|
* @param WindowNo window no
|
||||||
|
@ -110,7 +110,16 @@ public class ProcessCtl extends Thread
|
||||||
|
|
||||||
// execute
|
// execute
|
||||||
ProcessCtl worker = new ProcessCtl(parent, WindowNo, pi, trx);
|
ProcessCtl worker = new ProcessCtl(parent, WindowNo, pi, trx);
|
||||||
worker.start(); // MUST be start!
|
if (parent != null)
|
||||||
|
{
|
||||||
|
//asynchrous
|
||||||
|
worker.start();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//synchrous
|
||||||
|
worker.run();
|
||||||
|
}
|
||||||
return worker;
|
return worker;
|
||||||
} // execute
|
} // execute
|
||||||
|
|
||||||
|
@ -133,7 +142,7 @@ public class ProcessCtl extends Thread
|
||||||
* @param trx Transaction
|
* @param trx Transaction
|
||||||
* @return worker started ProcessCtl instance or null for workflow
|
* @return worker started ProcessCtl instance or null for workflow
|
||||||
*/
|
*/
|
||||||
public static ProcessCtl process(ASyncProcess parent, int WindowNo, ProcessParameterPanel paraPanel, ProcessInfo pi, Trx trx)
|
public static ProcessCtl process(ASyncProcess parent, int WindowNo, IProcessParameter parameter, ProcessInfo pi, Trx trx)
|
||||||
{
|
{
|
||||||
log.fine("WindowNo=" + WindowNo + " - " + pi);
|
log.fine("WindowNo=" + WindowNo + " - " + pi);
|
||||||
|
|
||||||
|
@ -165,7 +174,7 @@ public class ProcessCtl extends Thread
|
||||||
pi.setAD_PInstance_ID (instance.getAD_PInstance_ID());
|
pi.setAD_PInstance_ID (instance.getAD_PInstance_ID());
|
||||||
|
|
||||||
// Get Parameters
|
// Get Parameters
|
||||||
if (!paraPanel.saveParameters())
|
if (!parameter.saveParameters())
|
||||||
{
|
{
|
||||||
pi.setSummary (Msg.getMsg(Env.getCtx(), "ProcessCancelled"));
|
pi.setSummary (Msg.getMsg(Env.getCtx(), "ProcessCancelled"));
|
||||||
pi.setError (true);
|
pi.setError (true);
|
||||||
|
@ -174,7 +183,15 @@ public class ProcessCtl extends Thread
|
||||||
|
|
||||||
// execute
|
// execute
|
||||||
ProcessCtl worker = new ProcessCtl(parent, WindowNo, pi, trx);
|
ProcessCtl worker = new ProcessCtl(parent, WindowNo, pi, trx);
|
||||||
worker.start(); // MUST be start!
|
if (parent != null)
|
||||||
|
{
|
||||||
|
worker.start();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//synchrous
|
||||||
|
worker.run();
|
||||||
|
}
|
||||||
return worker;
|
return worker;
|
||||||
} // execute
|
} // execute
|
||||||
|
|
||||||
|
@ -208,6 +225,14 @@ public class ProcessCtl extends Thread
|
||||||
/** Static Logger */
|
/** Static Logger */
|
||||||
private static CLogger log = CLogger.getCLogger (ProcessCtl.class);
|
private static CLogger log = CLogger.getCLogger (ProcessCtl.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run this process in a new thread
|
||||||
|
*/
|
||||||
|
public void start()
|
||||||
|
{
|
||||||
|
new Thread(this).start();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute Process Instance and Lock UI.
|
* Execute Process Instance and Lock UI.
|
||||||
* Calls lockUI and unlockUI if parent is a ASyncProcess
|
* Calls lockUI and unlockUI if parent is a ASyncProcess
|
||||||
|
@ -392,23 +417,37 @@ public class ProcessCtl extends Thread
|
||||||
private void lock ()
|
private void lock ()
|
||||||
{
|
{
|
||||||
// log.info("...");
|
// log.info("...");
|
||||||
JFrame frame = Env.getFrame((Container)m_parent);
|
//m_parent is null for synchrous execution
|
||||||
if (frame instanceof AWindow)
|
if (m_parent != null)
|
||||||
((AWindow)frame).setBusyTimer(m_pi.getEstSeconds());
|
|
||||||
else
|
|
||||||
m_waiting = new Waiting (frame, Msg.getMsg(Env.getCtx(), "Processing"), false, m_pi.getEstSeconds());
|
|
||||||
SwingUtilities.invokeLater(new Runnable()
|
|
||||||
{
|
{
|
||||||
public void run()
|
if (m_parent instanceof Container)
|
||||||
{
|
{
|
||||||
|
//swing client
|
||||||
|
JFrame frame = Env.getFrame((Container)m_parent);
|
||||||
|
if (frame instanceof AWindow)
|
||||||
|
((AWindow)frame).setBusyTimer(m_pi.getEstSeconds());
|
||||||
|
else
|
||||||
|
m_waiting = new Waiting (frame, Msg.getMsg(Env.getCtx(), "Processing"), false, m_pi.getEstSeconds());
|
||||||
|
SwingUtilities.invokeLater(new Runnable()
|
||||||
|
{
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
log.finer("lock");
|
||||||
|
m_parent.lockUI(m_pi);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (m_waiting != null)
|
||||||
|
{
|
||||||
|
m_waiting.toFront();
|
||||||
|
m_waiting.setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//other client
|
||||||
log.finer("lock");
|
log.finer("lock");
|
||||||
m_parent.lockUI(m_pi);
|
m_parent.lockUI(m_pi);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
if (m_waiting != null)
|
|
||||||
{
|
|
||||||
m_waiting.toFront();
|
|
||||||
m_waiting.setVisible(true);
|
|
||||||
}
|
}
|
||||||
} // lock
|
} // lock
|
||||||
|
|
||||||
|
@ -421,21 +460,33 @@ public class ProcessCtl extends Thread
|
||||||
// log.info("...");
|
// log.info("...");
|
||||||
if (m_pi.isBatch())
|
if (m_pi.isBatch())
|
||||||
m_pi.setIsTimeout(true);
|
m_pi.setIsTimeout(true);
|
||||||
SwingUtilities.invokeLater(new Runnable()
|
if (m_parent != null)
|
||||||
{
|
{
|
||||||
public void run()
|
if (m_parent instanceof Container)
|
||||||
{
|
{
|
||||||
String summary = m_pi.getSummary();
|
//swing client
|
||||||
log.finer("unlock - " + summary);
|
SwingUtilities.invokeLater(new Runnable()
|
||||||
if (summary != null && summary.indexOf('@') != -1)
|
{
|
||||||
m_pi.setSummary(Msg.parseTranslation(Env.getCtx(), summary));
|
public void run()
|
||||||
|
{
|
||||||
|
String summary = m_pi.getSummary();
|
||||||
|
log.finer("unlock - " + summary);
|
||||||
|
if (summary != null && summary.indexOf('@') != -1)
|
||||||
|
m_pi.setSummary(Msg.parseTranslation(Env.getCtx(), summary));
|
||||||
|
m_parent.unlockUI(m_pi);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// Remove Waiting/Processing Indicator
|
||||||
|
if (m_waiting != null)
|
||||||
|
m_waiting.dispose();
|
||||||
|
m_waiting = null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//other client
|
||||||
m_parent.unlockUI(m_pi);
|
m_parent.unlockUI(m_pi);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
// Remove Waiting/Processing Indicator
|
|
||||||
if (m_waiting != null)
|
|
||||||
m_waiting.dispose();
|
|
||||||
m_waiting = null;
|
|
||||||
} // unlock
|
} // unlock
|
||||||
|
|
||||||
|
|
||||||
|
@ -470,12 +521,7 @@ public class ProcessCtl extends Thread
|
||||||
// Run locally
|
// Run locally
|
||||||
if (!started && !m_IsServerProcess)
|
if (!started && !m_IsServerProcess)
|
||||||
{
|
{
|
||||||
MWorkflow wf = MWorkflow.get (Env.getCtx(), AD_Workflow_ID);
|
MWFProcess wfProcess = ProcessUtil.startWorkFlow(Env.getCtx(), m_pi, AD_Workflow_ID);
|
||||||
MWFProcess wfProcess = null;
|
|
||||||
if (m_pi.isBatch())
|
|
||||||
wfProcess = wf.start(m_pi); // may return null
|
|
||||||
else
|
|
||||||
wfProcess = wf.startWait(m_pi); // may return null
|
|
||||||
started = wfProcess != null;
|
started = wfProcess != null;
|
||||||
}
|
}
|
||||||
return started;
|
return started;
|
||||||
|
@ -548,30 +594,7 @@ public class ProcessCtl extends Thread
|
||||||
// Run locally
|
// Run locally
|
||||||
if (!started && (!m_IsServerProcess || clientOnly ))
|
if (!started && (!m_IsServerProcess || clientOnly ))
|
||||||
{
|
{
|
||||||
ProcessCall myObject = null;
|
return ProcessUtil.startJavaProcess(m_pi, m_trx);
|
||||||
try
|
|
||||||
{
|
|
||||||
myObject = (ProcessCall)processClass.newInstance();
|
|
||||||
if (myObject == null)
|
|
||||||
m_pi.setSummary("No Instance for " + m_pi.getClassName(), true);
|
|
||||||
else
|
|
||||||
myObject.startProcess(Env.getCtx(), m_pi, m_trx);
|
|
||||||
if (m_trx != null)
|
|
||||||
{
|
|
||||||
m_trx.commit(true);
|
|
||||||
m_trx.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
if (m_trx != null)
|
|
||||||
{
|
|
||||||
m_trx.rollback();
|
|
||||||
m_trx.close();
|
|
||||||
}
|
|
||||||
m_pi.setSummary("Error starting Class " + m_pi.getClassName(), true);
|
|
||||||
log.log(Level.SEVERE, m_pi.getClassName(), e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return !m_pi.isError();
|
return !m_pi.isError();
|
||||||
} // startProcess
|
} // startProcess
|
||||||
|
@ -637,32 +660,7 @@ public class ProcessCtl extends Thread
|
||||||
//try locally
|
//try locally
|
||||||
if (!started)
|
if (!started)
|
||||||
{
|
{
|
||||||
String sql = "{call " + ProcedureName + "(?)}";
|
return ProcessUtil.startDatabaseProcedure(m_pi, ProcedureName, m_trx);
|
||||||
try
|
|
||||||
{
|
|
||||||
//hengsin, add trx support, updateable support.
|
|
||||||
CallableStatement cstmt = DB.prepareCall(sql, ResultSet.CONCUR_UPDATABLE, trxName);
|
|
||||||
cstmt.setInt(1, m_pi.getAD_PInstance_ID());
|
|
||||||
cstmt.executeUpdate();
|
|
||||||
cstmt.close();
|
|
||||||
if (m_trx != null && m_trx.isActive())
|
|
||||||
{
|
|
||||||
m_trx.commit(true);
|
|
||||||
m_trx.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
log.log(Level.SEVERE, sql, e);
|
|
||||||
if (m_trx != null && m_trx.isActive())
|
|
||||||
{
|
|
||||||
m_trx.rollback();
|
|
||||||
m_trx.close();
|
|
||||||
}
|
|
||||||
m_pi.setSummary (Msg.getMsg(Env.getCtx(), "ProcessRunError") + " " + e.getLocalizedMessage());
|
|
||||||
m_pi.setError (true);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// log.fine(Log.l4_Data, "ProcessCtl.startProcess - done");
|
// log.fine(Log.l4_Data, "ProcessCtl.startProcess - done");
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -52,7 +52,7 @@ import org.compiere.util.Env;
|
||||||
* @version 2006-12-01
|
* @version 2006-12-01
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class ProcessParameterPanel extends CPanel implements VetoableChangeListener {
|
public class ProcessParameterPanel extends CPanel implements VetoableChangeListener, IProcessParameter {
|
||||||
/**
|
/**
|
||||||
* Dynamic generated Parameter panel.
|
* Dynamic generated Parameter panel.
|
||||||
* @param WindowNo window
|
* @param WindowNo window
|
||||||
|
@ -306,9 +306,8 @@ public class ProcessParameterPanel extends CPanel implements VetoableChangeListe
|
||||||
Env.setContext(Env.getCtx(), m_WindowNo, evt.getPropertyName(), value);
|
Env.setContext(Env.getCtx(), m_WindowNo, evt.getPropertyName(), value);
|
||||||
} // vetoableChange
|
} // vetoableChange
|
||||||
|
|
||||||
/**
|
/* (non-Javadoc)
|
||||||
* Save Parameter values
|
* @see org.compiere.apps.ProcessParameters#saveParameters()
|
||||||
* @return true if parameters saved
|
|
||||||
*/
|
*/
|
||||||
public boolean saveParameters()
|
public boolean saveParameters()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue