@VEEvent

When you write a Rich UI widget that uses the targetWidget property (or when you write an external-type widget), you can declare event types that are not otherwise defined. In this way, you can let the business developer think more clearly about defining a sequence of tasks. Also, the developer can assign an event handler at the Events view.

The next example shows use of a customized button (MyButton), which uses the property @VEEvent. If you try out the example in your workspace, note that the EGL developer can now use the EGL editor for the following purposes: to create a button of type MyButton and to assign event handlers for the newly defined events (onPreClick and onPostClick).

Here is a handler that accesses a button of type MyButton:
package pkg;

import com.ibm.egl.rui.widgets.Button; 

handler MyHandler type RUIhandler {initialUI = [ someButton ]}
		
	  someButton MyButton{text = "fresh", 
	                      onPreClick ::= respondToPreClick, 
	                      onClick ::= respondToClick, 
	                      onPostClick ::= respondToPostClick};
		
   function respondToPreClick(e Event in)
      sysLib.writeStdout("in pre"); 
   end
	
   function respondToClick(e Event in) 
      sysLib.writeStdout("in click");
   end
	
   function respondToPostClick(e Event in) 
      sysLib.writeStdout("in post");
   end	
		
end
Here is the definition of MyButton:
package pkg;

import com.ibm.egl.rui.widgets.Button;
handler MyButton type RUIWidget {

   targetWidget = internalButton, 
   @VEWidget{ 
		   category = "New EGL Widgets",
		   template = "pkg.myButton{ text=\"myButton\" }"}
   }
	
   text string {@EGLProperty{setMethod = setText, 
                             getMethod = getText}, 
                @VEProperty{}};

   internalButton Button{onClick ::= respondToClick};

   onPreClick EventHandler[] {@VEEvent{}};
   onClick EventHandler[] {@VEEvent{}}; 
   onPostClick EventHandler[] {@VEEvent{}};	

   private function setText(text String in)
		   internalButton.text = text;
   end

   private function getText() returns (String)
		   return ( internalButton.text );
   end
   
   private function respondToClick(e Event in)

      preSize int = onPreClick.getSize();
      clickSize int = onClick.getSize();
      postSize int = onPostClick.getSize();	 
   
      for (i int from 1 to preSize by 1)
	        OnPreClick[i](e);
      end
	   
      for (i int from 1 to clickSize by 1)
	        OnClick[i](e);		  	
      end
	   
      for (i int from 1 to postSize by 1)
         OnPostClick[i](e);		
      end
   end
end

Changes to @VEEvent are available to a file in the EGL editor only if you refresh the palette and the file. To refresh the palette, click the Refresh palette tool on the Design surface, as noted in “Using the tools on the Design surface.” To refresh the file, click the Refresh web page tool on the Preview tab, as noted in “Running a web application in the EGL editor.”


Feedback