FR [ 2391012 ] Invoke AD_Form from button
- Port swing implementation to zk
This commit is contained in:
parent
1598f782e8
commit
7a6db0484c
|
|
@ -26,6 +26,7 @@ import org.adempiere.webui.exception.ApplicationException;
|
||||||
import org.adempiere.webui.session.SessionManager;
|
import org.adempiere.webui.session.SessionManager;
|
||||||
import org.adempiere.webui.util.ADClassNameMap;
|
import org.adempiere.webui.util.ADClassNameMap;
|
||||||
import org.compiere.model.MForm;
|
import org.compiere.model.MForm;
|
||||||
|
import org.compiere.process.ProcessInfo;
|
||||||
import org.compiere.util.CLogger;
|
import org.compiere.util.CLogger;
|
||||||
import org.compiere.util.Env;
|
import org.compiere.util.Env;
|
||||||
import org.zkoss.zk.ui.event.Event;
|
import org.zkoss.zk.ui.event.Event;
|
||||||
|
|
@ -34,7 +35,7 @@ import org.zkoss.zk.ui.event.EventListener;
|
||||||
/**
|
/**
|
||||||
* Adempiere Web UI custom form.
|
* Adempiere Web UI custom form.
|
||||||
* The form is abstract, so specific types of custom form must be implemented
|
* The form is abstract, so specific types of custom form must be implemented
|
||||||
*
|
*
|
||||||
* @author Andrew Kimball
|
* @author Andrew Kimball
|
||||||
*/
|
*/
|
||||||
public abstract class ADForm extends Window implements EventListener
|
public abstract class ADForm extends Window implements EventListener
|
||||||
|
|
@ -49,63 +50,66 @@ public abstract class ADForm extends Window implements EventListener
|
||||||
{
|
{
|
||||||
logger = CLogger.getCLogger(ADForm.class);
|
logger = CLogger.getCLogger(ADForm.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The unique identifier of the form type */
|
/** The unique identifier of the form type */
|
||||||
private int m_adFormId;
|
private int m_adFormId;
|
||||||
/** The identifying number of the window in which the form is housed */
|
/** The identifying number of the window in which the form is housed */
|
||||||
protected int m_WindowNo;
|
protected int m_WindowNo;
|
||||||
|
|
||||||
|
|
||||||
private String m_name;
|
private String m_name;
|
||||||
|
|
||||||
|
|
||||||
|
private ProcessInfo m_pi;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param ctx the context into which the form is being placed
|
* @param ctx the context into which the form is being placed
|
||||||
* @param adFormId the Adempiere form identifier
|
* @param adFormId the Adempiere form identifier
|
||||||
*/
|
*/
|
||||||
protected ADForm()
|
protected ADForm()
|
||||||
{
|
{
|
||||||
m_WindowNo = SessionManager.getAppDesktop().registerWindow(this);
|
m_WindowNo = SessionManager.getAppDesktop().registerWindow(this);
|
||||||
|
|
||||||
this.setWidth("100%");
|
this.setWidth("100%");
|
||||||
this.setHeight("95%");
|
this.setHeight("95%");
|
||||||
this.setStyle("position:absolute");
|
this.setStyle("position:absolute");
|
||||||
this.setContentSclass("adform-content");
|
this.setContentSclass("adform-content");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int getWindowNo()
|
protected int getWindowNo()
|
||||||
{
|
{
|
||||||
return m_WindowNo;
|
return m_WindowNo;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int getAdFormId()
|
protected int getAdFormId()
|
||||||
{
|
{
|
||||||
return m_adFormId;
|
return m_adFormId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialise the form
|
* Initialise the form
|
||||||
*
|
*
|
||||||
* @param adFormId the Adempiere form identifier
|
* @param adFormId the Adempiere form identifier
|
||||||
* @param name the name of the Adempiere form
|
* @param name the name of the Adempiere form
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected void init(int adFormId, String name)
|
protected void init(int adFormId, String name)
|
||||||
{
|
{
|
||||||
if(adFormId <= 0)
|
if(adFormId <= 0)
|
||||||
{
|
{
|
||||||
throw new IllegalArgumentException("Form Id is invalid");
|
throw new IllegalArgumentException("Form Id is invalid");
|
||||||
}
|
}
|
||||||
|
|
||||||
m_adFormId = adFormId;
|
m_adFormId = adFormId;
|
||||||
//window title
|
//window title
|
||||||
setTitle(name);
|
setTitle(name);
|
||||||
m_name = name;
|
m_name = name;
|
||||||
|
|
||||||
initForm();
|
initForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract protected void initForm();
|
abstract protected void initForm();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -114,19 +118,19 @@ public abstract class ADForm extends Window implements EventListener
|
||||||
public String getFormName() {
|
public String getFormName() {
|
||||||
return m_name;
|
return m_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert the rich client class name for a form to its web UI equivalent
|
* Convert the rich client class name for a form to its web UI equivalent
|
||||||
*
|
*
|
||||||
* @param originalName The full class path to convert
|
* @param originalName The full class path to convert
|
||||||
* @return the converted class name
|
* @return the converted class name
|
||||||
*/
|
*/
|
||||||
private static String translateFormClassName(String originalName)
|
private static String translateFormClassName(String originalName)
|
||||||
{
|
{
|
||||||
String modifiedName;
|
String modifiedName;
|
||||||
/* match any field containing the string ".compiere."
|
/* match any field containing the string ".compiere."
|
||||||
* Usually of the form "org.compiere.apps.form.<classname>".
|
* Usually of the form "org.compiere.apps.form.<classname>".
|
||||||
* Although there are special cases which also need handling
|
* Although there are special cases which also need handling
|
||||||
*/
|
*/
|
||||||
final String regex = "(.*)\\.compiere\\.(.*\\.)V(\\w*)$";
|
final String regex = "(.*)\\.compiere\\.(.*\\.)V(\\w*)$";
|
||||||
//final String regex = "(.*)\\.compiere\\.(.*\\.)V(\\w*)$";
|
//final String regex = "(.*)\\.compiere\\.(.*\\.)V(\\w*)$";
|
||||||
|
|
@ -143,31 +147,31 @@ public abstract class ADForm extends Window implements EventListener
|
||||||
Pattern pattern = Pattern.compile(regex);
|
Pattern pattern = Pattern.compile(regex);
|
||||||
Matcher matcher = pattern.matcher(originalName);
|
Matcher matcher = pattern.matcher(originalName);
|
||||||
int group = 1;
|
int group = 1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If no match is found throw an exception stating that the form
|
* If no match is found throw an exception stating that the form
|
||||||
* has not been implemented in the webUI
|
* has not been implemented in the webUI
|
||||||
*/
|
*/
|
||||||
if (matcher.find()== false)
|
if (matcher.find()== false)
|
||||||
{
|
{
|
||||||
return originalName;
|
return originalName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* reconstruct the name using the captured groups and the replacement strings
|
* reconstruct the name using the captured groups and the replacement strings
|
||||||
*/
|
*/
|
||||||
modifiedName = matcher.group(group++)
|
modifiedName = matcher.group(group++)
|
||||||
+ replacementPackage
|
+ replacementPackage
|
||||||
+ matcher.group(group++)
|
+ matcher.group(group++)
|
||||||
+ replacementPrefix
|
+ replacementPrefix
|
||||||
+ matcher.group(group++);
|
+ matcher.group(group++);
|
||||||
|
|
||||||
return modifiedName;
|
return modifiedName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new form corresponding to the specified identifier
|
* Create a new form corresponding to the specified identifier
|
||||||
*
|
*
|
||||||
* @param adFormID The unique identifier for the form type
|
* @param adFormID The unique identifier for the form type
|
||||||
* @return The created form
|
* @return The created form
|
||||||
*/
|
*/
|
||||||
|
|
@ -179,22 +183,22 @@ public abstract class ADForm extends Window implements EventListener
|
||||||
MForm mform = new MForm(Env.getCtx(), adFormID, null);
|
MForm mform = new MForm(Env.getCtx(), adFormID, null);
|
||||||
String richClassName = mform.getClassname();
|
String richClassName = mform.getClassname();
|
||||||
String name = mform.get_Translation(MForm.COLUMNNAME_Name);
|
String name = mform.get_Translation(MForm.COLUMNNAME_Name);
|
||||||
|
|
||||||
if (mform.get_ID() == 0 || richClassName == null)
|
if (mform.get_ID() == 0 || richClassName == null)
|
||||||
{
|
{
|
||||||
throw new ApplicationException("There is no form associated with the specified selection");
|
throw new ApplicationException("There is no form associated with the specified selection");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
logger.info("AD_Form_ID=" + adFormID + " - Class=" + richClassName);
|
logger.info("AD_Form_ID=" + adFormID + " - Class=" + richClassName);
|
||||||
|
|
||||||
//static lookup
|
//static lookup
|
||||||
webClassName = ADClassNameMap.get(richClassName);
|
webClassName = ADClassNameMap.get(richClassName);
|
||||||
//fallback to dynamic translation
|
//fallback to dynamic translation
|
||||||
if (webClassName == null || webClassName.trim().length() == 0)
|
if (webClassName == null || webClassName.trim().length() == 0)
|
||||||
webClassName = translateFormClassName(richClassName);
|
webClassName = translateFormClassName(richClassName);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Create instance w/o parameters
|
// Create instance w/o parameters
|
||||||
|
|
@ -202,11 +206,11 @@ public abstract class ADForm extends Window implements EventListener
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
throw new ApplicationException("The selected web user interface custom form '" +
|
throw new ApplicationException("The selected web user interface custom form '" +
|
||||||
webClassName +
|
webClassName +
|
||||||
"' is not accessible.", e);
|
"' is not accessible.", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (obj instanceof ADForm)
|
if (obj instanceof ADForm)
|
||||||
|
|
@ -217,26 +221,41 @@ public abstract class ADForm extends Window implements EventListener
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new ApplicationException("The web user interface custom form '" +
|
throw new ApplicationException("The web user interface custom form '" +
|
||||||
webClassName +
|
webClassName +
|
||||||
"' cannot be displayed in the web user interface.");
|
"' cannot be displayed in the web user interface.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
logger.log(Level.SEVERE, "Class=" + webClassName + ", AD_Form_ID=" + adFormID, ex);
|
logger.log(Level.SEVERE, "Class=" + webClassName + ", AD_Form_ID=" + adFormID, ex);
|
||||||
throw new ApplicationException("The web user interface custom form '" +
|
throw new ApplicationException("The web user interface custom form '" +
|
||||||
webClassName +
|
webClassName +
|
||||||
"' failed to initialise:" + ex);
|
"' failed to initialise:" + ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // openForm
|
} // openForm
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public void onEvent(Event arg0) throws Exception
|
public void onEvent(Event arg0) throws Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param pi
|
||||||
|
*/
|
||||||
|
public void setProcessInfo(ProcessInfo pi) {
|
||||||
|
m_pi = pi;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return ProcessInfo
|
||||||
|
*/
|
||||||
|
public ProcessInfo getProcessInfo()
|
||||||
|
{
|
||||||
|
return m_pi;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue