package de.abas.examples.eventhandler;

import java.util.Date;

import de.abas.eks.jfop.annotation.Stateful;
import de.abas.erp.api.gui.ButtonSet;
import de.abas.erp.api.gui.TextBox;
import de.abas.erp.axi.event.EventException;
import de.abas.erp.axi2.EventHandlerRunner;
import de.abas.erp.axi2.annotation.EventHandler;
import de.abas.erp.axi2.annotation.FieldEventHandler;
import de.abas.erp.axi2.annotation.ScreenEventHandler;
import de.abas.erp.axi2.type.FieldEventType;
import de.abas.erp.axi2.type.ScreenEventType;
import de.abas.erp.common.type.enums.EnumDialogBox;
import de.abas.erp.db.DbContext;
import de.abas.erp.db.schema.customer.CustomerEditor;
import de.abas.erp.jfop.rt.api.annotation.RunFopWith;

@EventHandler(head = CustomerEditor.class)
@RunFopWith(EventHandlerRunner.class)
@Stateful
public class StatefulCustomerEventHandler {
	
	private String emailAddr;

	@ScreenEventHandler(type = ScreenEventType.ENTER)
	public void screenEnter(CustomerEditor head) throws EventException {
		emailAddr = head.getEmailAddr();
	}
	
	@FieldEventHandler(field = "telexAddr", type = FieldEventType.EXIT)
	public void emailAddrValidation(DbContext ctx, CustomerEditor head) throws EventException {
		String emailAddress = head.getEmailAddr();
		if (!this.emailAddr.equals(emailAddress)) {
			addNote(ctx, head, emailAddress);
		}
	}

	private void addNote(DbContext ctx, CustomerEditor head, String emailAddress) {
		if (noteWanted(ctx, emailAddress)) {
			head.setComments(String.format("%s - email address updated from %s to %s", new Date(), this.emailAddr,
					emailAddress));
		}
	}

	private boolean noteWanted(DbContext ctx, String emailAddress) {
		EnumDialogBox boxResult = new TextBox(ctx, "Note", "Do you want to add a note?")
			.setButtons(ButtonSet.YES_NO)
			.show();
		if (boxResult.equals(EnumDialogBox.Yes)) {
			return true;
		}
		return false;
	}

}

@@ -956,36 +956,40 @@
 (CustomerEditor 
-head
+customer
 ) throws EventEx
@@ -1012,20 +1012,24 @@
 lAddr = 
-head
+customer
 .getEmai
@@ -1174,20 +1174,24 @@
 rEditor 
-head
+customer
 ) throws
@@ -1232,20 +1232,24 @@
 dress = 
-head
+customer
 .getEmai
@@ -1319,20 +1319,24 @@
 te(ctx, 
-head
+customer
 , emailA
@@ -1404,20 +1404,24 @@
 rEditor 
-head
+customer
 , String
@@ -1479,20 +1479,24 @@
 )) %7B%0A%09%09%09
-head
+customer
 .setComm
@@ -1589,14 +1589,9 @@
 ddr,
-%0A%09%09%09%09%09
+ 
 emai

Rename 'head' to 'customer'