Adempiere RAD Form

What is RAD Form.

RAD Form is a new module for Adempiere that I decided to develop becouse I had to do some customizations for customers that require dialog forms to perform user data input, wizards and other stuff.
Develop a form in Adempiere means to write a java class that become two if your customer use both swing and ZK user interface.

The RAD Form allow to define dialog forms in a similar way as you define the windows. Forms are rendered at run time for both the u.i. web ZK and desktop Java Swing.

Installation

Downloads those files

After download
A) Import the maticaFRM.zip with ‘PackIn – import a package’

Login Adempiere with the user System and role Sytem Administrator
From the menu open Application Dictionary > Application Packaging > PackIn – Import a package

Selezione_175
1) Select File as Package Source Type
2) Select the downloaded file maticaFRM.zip
3) Select a directory used by the import procedure to unzip the package
4) Click Packin to start the import

B) copy maticaFRM.jar in $ADEMPIERE_HOME/packages/maticaFRM/lib (create the folders maticaFRM/lib first)
C) copy maticazkFRM.jar in $ADEMPIERE_HOME/zkpackages/maticazkFRM/lib (create the folders maticazkFRM/lib first)
D) Change dir to $ADEMPIERE_HOME and execute RUN_setup.sh

Get Source Code

Source code is available at:
http://sourceforge.net/p/admat3form/code-0/5/tree/trunk/

How To create a new Form

After install the package login as System Administrator role and go to Application Dictionary -> Form

Select IsRAD in order to activate the new tabs in which configure the aspects of the form

Selezione_176

From tab ‘MAT3_Form’ (I’ll translate these next) follow the screenshot to create a simple form
Selezione_177
In MAT3_Form other than set the name, write ‘org.matica.form.MAT3TestBusinessLogic’ in the field ‘Business Logi class’

Skip Tab MAT3_Form_Trl and go to tab MAT3_FormContainer in which insert the containers of controls.
Selezione_178
1) Select Panel as type
2) Set the position of the panel

Go to tab MAT3_FormField
Selezione_181
Selezione_180
1) Set the Name of field (and the ‘Reference’)
2) Set the DB Colum Name (important as it used in the busness logic class)
3) Set the position of field

Now come back to the MAT3_Form tab and click the Preview button to watch the dialog form created.

How to use the form

After defining the new Form you can use it like the others Adempiere Form, like putting it into the menu or open it through a button of a window

Form can be programmed through by a classe which extentds MAT_I_BusinessLogic
Here an example


package org.matica.form;

import org.matica.form.listener.MAT_ButtonEvent;
import org.matica.form.listener.MAT_FieldChangeEvent;
import org.matica.form.listener.MAT_I_BusinessLogic;
import org.matica.form.listener.MAT_I_Listener;

public class MAT3TestBusinessLogic extends MAT_I_BusinessLogic {

	@Override
	public void onWindowOpened() {
		System.out.println(MAT3TestBusinessLogic.class.getName() + "-> Window Opened");

	}

	@Override
	public void onWindowClosed() {
		System.out.println(MAT3TestBusinessLogic.class.getName() + "-> Window Closed");
	}

	@Override
	public void onButton(MAT_ButtonEvent e) {
		System.out.println(MAT3TestBusinessLogic.class.getName() + "-> onButton: " + e.getButtonName() + " " + e );
	}

	@Override
	public void onFieldChange(MAT_FieldChangeEvent e) {
		System.out.println(MAT3TestBusinessLogic.class.getName() + "-> onFieldChange " + e.getFieldName() + " " + e);
	}

	@Override
	public void onConfirmOK() {
		System.out.println(MAT3TestBusinessLogic.class.getName() + "-> onConfirmOk");
	}

	@Override
	public void onConfirmCancel() {
		System.out.println(MAT3TestBusinessLogic.class.getName() + "-> onConfirmCancel");

	}

}

and this is the abstract class MAT_I_BusinessLogic


package org.matica.form.listener;

public abstract class MAT_I_BusinessLogic
{

	protected MAT_I_Listener m_lstowner = null;

	public abstract void onWindowOpened();

	public abstract void onWindowClosed();

	public abstract void onButton(MAT_ButtonEvent e);

	public abstract void onFieldChange(MAT_FieldChangeEvent e);	

	public abstract void onConfirmOK();

	public abstract void onConfirmCancel();

	public void setListenerOwner(MAT_I_Listener lst)
	{
		this.m_lstowner = lst;
	}
}

The member m_lstowner exposes methods to interact and manipulate the dialog.
Here a working one


package org.compiere.process;

import java.sql.Timestamp;

import org.compiere.model.MTXROffer;
import org.compiere.model.X_TXR_Offer;
import org.matica.form.listener.MAT_ButtonEvent;
import org.matica.form.listener.MAT_FieldChangeEvent;
import org.matica.form.listener.MAT_I_BusinessLogic;
import org.compiere.util.TimeUtil;
import org.compiere.util.Trx;

public class TX_OfferSelectAction extends MAT_I_BusinessLogic {

	private MTXROffer m_offer = null;
	private String m_newStatus = "";

	@Override
	public void onWindowOpened() {

		if (this.m_lstowner.getProcessInfo() != null){
			int id = this.m_lstowner.getProcessInfo().getRecord_ID();

			m_offer = new MTXROffer(this.m_lstowner.getCtx(), id, this.m_lstowner.getTrxName());

			//Imposta titolo dialog
			this.m_lstowner.setFrameTitle("Offer: " + m_offer.get_Value("DocumentNo"));
			//resize
			if (this.m_lstowner.isWebui()){
				this.m_lstowner.setFrameWidth(650);
				this.m_lstowner.setFrameHeight(450);
			}else{

			}

			//Imposta i valori del campo doc status e ricarica i dati nella combo
			this.m_lstowner.setFieldValue("TXR_DocStatus", m_offer.getTXR_DocStatus());
			this.m_lstowner.getField("TXR_DocAction").refreshLookup();

			//Nasconde il pannello degli errori
			this.m_lstowner.setPanelVisible("PError", false);
			this.m_lstowner.setFieldValue("errorMsg", "");

			//Nasconde pannello delle Fatture
			this.m_lstowner.setPanelVisible("PFatture", false);

		}

	}

	@Override
	public void onWindowClosed() {
		// TODO Auto-generated method stub

	}

	@Override
	public void onButton(MAT_ButtonEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onFieldChange(MAT_FieldChangeEvent e) {
		this.m_lstowner.setPanelVisible("PError", false);
		this.m_lstowner.setFieldValue("errorMsg", "");

		if (e.getFieldName().equals("TXR_DocStatus") == true){
			this.m_lstowner.getField("TXR_DocAction").refreshLookup();
			this.m_lstowner.setPanelVisible("P2", true);
		}

		if (e.getFieldName().equals("TXR_DocAction") == true)
		{
			m_newStatus = (String)e.getNewValue();
			if (m_newStatus.equals("IN") == false ){
				this.m_lstowner.setPanelVisible("PFatture", false);
			}else{
				this.m_lstowner.setPanelVisible("PFatture", true);
			}
		}

	}

	@Override
	public void onConfirmCancel() {

		this.m_lstowner.disposeFrame();
	}

	@Override
	public void onConfirmOK() {

		String errmsg = validateFields();

		try{

			if (errmsg.isEmpty())
			{
				if (this.m_lstowner.getFieldValue("TXR_DocAction").equals("IN"))
				{
					String fattura = (String)this.m_lstowner.getFieldValue("fattura1");
					if (fattura != null && fattura!=null )
					{
						Timestamp data = (Timestamp)this.m_lstowner.getFieldValue("del1");
						m_offer.addInvoiceRef(fattura, data, "");
					}
					fattura = (String)this.m_lstowner.getFieldValue("fattura2");
					if (fattura != null && fattura.isEmpty()==false )
					{
						Timestamp data = (Timestamp)this.m_lstowner.getFieldValue("del2");
						m_offer.addInvoiceRef(fattura, data, "");
					}
				}

				saveOfferStatus();
				this.m_lstowner.disposeFrame();

			}else{
				this.m_lstowner.setPanelVisible("PError", true);
				this.m_lstowner.setFieldValue("errorMsg", errmsg);
			}
		}catch(Exception e){
			e.printStackTrace();
			Trx trx = Trx.get(m_offer.get_TrxName(), false);
			trx.rollback();
			this.m_lstowner.setPanelVisible("PError", true);
			this.m_lstowner.setFieldValue("errorMsg", "Errore registrazione dati consulta log di sistema");			

		}

	}

	/*------------------------------------------------------------
	 * PRIVATE
	 * ------------------------------------------------------------
	 */

	private String validateFields()
	{
		if (m_newStatus.isEmpty()){
			return "Indicare l'azione da eseguire !!!";
		}
		if (this.m_lstowner.getFieldValue("TXR_DocAction").equals("IN"))
		{

			String fattura1 = (String)this.m_lstowner.getFieldValue("fattura1");
			String fattura2 = (String)this.m_lstowner.getFieldValue("fattura2");

			Timestamp data1 = (Timestamp)this.m_lstowner.getFieldValue("del1");
			Timestamp data2 = (Timestamp)this.m_lstowner.getFieldValue("del2");

			if (fattura1==null & fattura2==null )
			{
				return "Indicare almeno una fattura !!!";
			}

			if (fattura1!=null & data1==null)
			{
				return "Indicare la data della fattura";
			}

			if (fattura2!=null & data2==null)
			{
				return "Indicare la data della fattura";
			}

		}

		return "";

	}

	private boolean saveOfferStatus()
	{

		Timestamp today = new Timestamp( TimeUtil.getToday().getTimeInMillis()) ;
		int userid = Integer.parseInt(this.m_lstowner.getCtx().getProperty("#AD_User_ID"));

		if (m_newStatus.equals(X_TXR_Offer.TXR_DOCSTATUS_Accepted)){
			m_offer.setTXR_DateAccept(today);
			m_offer.setTXR_AcceptBy_ID(userid);
		}else if (m_newStatus.equals(X_TXR_Offer.TXR_DOCSTATUS_Closed)){
			m_offer.setTXR_DateClosed(today);
			m_offer.setTXR_ClosedBy_ID(userid);
		}else if (m_newStatus.equals(X_TXR_Offer.TXR_DOCSTATUS_Invoiced)){
			m_offer.setTXR_DateInvoiced(today);
			m_offer.setTXR_InvoicedBy_ID(userid);
		}else if (m_newStatus.equals(X_TXR_Offer.TXR_DOCSTATUS_Aborted)){
			m_offer.setTXR_DateVoided(today);
			m_offer.setTXR_VoidedBy_ID(userid);
		}		

		String note = (String)this.m_lstowner.getFieldValue("Note");
		m_offer.setTXR_DocStatus(m_newStatus,userid,note);

		return m_offer.save(this.m_lstowner.getTrxName());

	}

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s