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.util.ADClassNameMap;
|
||||
import org.compiere.model.MForm;
|
||||
import org.compiere.process.ProcessInfo;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.Env;
|
||||
import org.zkoss.zk.ui.event.Event;
|
||||
|
@ -34,7 +35,7 @@ import org.zkoss.zk.ui.event.EventListener;
|
|||
/**
|
||||
* Adempiere Web UI custom form.
|
||||
* The form is abstract, so specific types of custom form must be implemented
|
||||
*
|
||||
*
|
||||
* @author Andrew Kimball
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/** The unique identifier of the form type */
|
||||
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;
|
||||
|
||||
|
||||
private String m_name;
|
||||
|
||||
|
||||
|
||||
private ProcessInfo m_pi;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
*
|
||||
* @param ctx the context into which the form is being placed
|
||||
* @param adFormId the Adempiere form identifier
|
||||
*/
|
||||
protected ADForm()
|
||||
{
|
||||
m_WindowNo = SessionManager.getAppDesktop().registerWindow(this);
|
||||
|
||||
|
||||
this.setWidth("100%");
|
||||
this.setHeight("95%");
|
||||
this.setStyle("position:absolute");
|
||||
this.setContentSclass("adform-content");
|
||||
}
|
||||
|
||||
|
||||
protected int getWindowNo()
|
||||
{
|
||||
return m_WindowNo;
|
||||
}
|
||||
|
||||
|
||||
protected int getAdFormId()
|
||||
{
|
||||
return m_adFormId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initialise the form
|
||||
*
|
||||
* @param adFormId the Adempiere form identifier
|
||||
* Initialise the form
|
||||
*
|
||||
* @param adFormId the Adempiere form identifier
|
||||
* @param name the name of the Adempiere form
|
||||
*/
|
||||
|
||||
|
||||
protected void init(int adFormId, String name)
|
||||
{
|
||||
if(adFormId <= 0)
|
||||
{
|
||||
throw new IllegalArgumentException("Form Id is invalid");
|
||||
}
|
||||
|
||||
|
||||
m_adFormId = adFormId;
|
||||
//window title
|
||||
setTitle(name);
|
||||
m_name = name;
|
||||
|
||||
|
||||
initForm();
|
||||
}
|
||||
|
||||
|
||||
abstract protected void initForm();
|
||||
|
||||
/**
|
||||
|
@ -114,19 +118,19 @@ public abstract class ADForm extends Window implements EventListener
|
|||
public String getFormName() {
|
||||
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
|
||||
* @return the converted class name
|
||||
*/
|
||||
private static String translateFormClassName(String originalName)
|
||||
{
|
||||
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>".
|
||||
* 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*)$";
|
||||
|
@ -143,31 +147,31 @@ public abstract class ADForm extends Window implements EventListener
|
|||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(originalName);
|
||||
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
|
||||
*/
|
||||
*/
|
||||
if (matcher.find()== false)
|
||||
{
|
||||
return originalName;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* reconstruct the name using the captured groups and the replacement strings
|
||||
*/
|
||||
modifiedName = matcher.group(group++)
|
||||
+ replacementPackage
|
||||
+ matcher.group(group++)
|
||||
+ replacementPrefix
|
||||
modifiedName = matcher.group(group++)
|
||||
+ replacementPackage
|
||||
+ matcher.group(group++)
|
||||
+ replacementPrefix
|
||||
+ matcher.group(group++);
|
||||
|
||||
|
||||
return modifiedName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new form corresponding to the specified identifier
|
||||
*
|
||||
*
|
||||
* @param adFormID The unique identifier for the form type
|
||||
* @return The created form
|
||||
*/
|
||||
|
@ -179,22 +183,22 @@ public abstract class ADForm extends Window implements EventListener
|
|||
MForm mform = new MForm(Env.getCtx(), adFormID, null);
|
||||
String richClassName = mform.getClassname();
|
||||
String name = mform.get_Translation(MForm.COLUMNNAME_Name);
|
||||
|
||||
|
||||
if (mform.get_ID() == 0 || richClassName == null)
|
||||
{
|
||||
throw new ApplicationException("There is no form associated with the specified selection");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
logger.info("AD_Form_ID=" + adFormID + " - Class=" + richClassName);
|
||||
|
||||
|
||||
//static lookup
|
||||
webClassName = ADClassNameMap.get(richClassName);
|
||||
//fallback to dynamic translation
|
||||
if (webClassName == null || webClassName.trim().length() == 0)
|
||||
webClassName = translateFormClassName(richClassName);
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
// Create instance w/o parameters
|
||||
|
@ -202,11 +206,11 @@ public abstract class ADForm extends Window implements EventListener
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ApplicationException("The selected web user interface custom form '" +
|
||||
webClassName +
|
||||
throw new ApplicationException("The selected web user interface custom form '" +
|
||||
webClassName +
|
||||
"' is not accessible.", e);
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
if (obj instanceof ADForm)
|
||||
|
@ -217,26 +221,41 @@ public abstract class ADForm extends Window implements EventListener
|
|||
}
|
||||
else
|
||||
{
|
||||
throw new ApplicationException("The web user interface custom form '" +
|
||||
webClassName +
|
||||
throw new ApplicationException("The web user interface custom form '" +
|
||||
webClassName +
|
||||
"' cannot be displayed in the web user interface.");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.log(Level.SEVERE, "Class=" + webClassName + ", AD_Form_ID=" + adFormID, ex);
|
||||
throw new ApplicationException("The web user interface custom form '" +
|
||||
webClassName +
|
||||
throw new ApplicationException("The web user interface custom form '" +
|
||||
webClassName +
|
||||
"' failed to initialise:" + ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // 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