Xoetrope

 Wiki : GroovySupport

HomePage :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register
Most recent edit on 2008-02-17 12:34:15 by LuanO

Additions:
The page field is set when the page is created. If the .groovy file is modified it is reloaded before any of its methods are invoked. As part of the procecss the properties/fields belonging to the page are rebound to the new GroovyObject.

Deletions:
If the .groovy file is modified it is reloaded before any of its methods are invoked. As part of the procecss the properties/fields belonging to the page are rebound to the new GroovyObject.



Edited on 2008-02-17 12:33:12 by LuanO

Additions:
import net.xoetrope.swing.XLabel;
XLabel counterLbl;
int count
counterLbl = page.findComponent( "counterLbl" );
println "counterLbl set"
public void pageActivated()
count
Try changing this at runtime
counterLbl.setText( "This pages has been activated and displayed " + count + " times" )




Edited on 2008-02-17 12:20:16 by LuanO

Additions:
If the .groovy file is modified it is reloaded before any of its methods are invoked. As part of the procecss the properties/fields belonging to the page are rebound to the new GroovyObject.
A sample Groovy application can be found at http://xui.svn.sourceforge.net/viewvc/xui/xui/branches/xui40/samples/features/Groovy/GroovyPageTest/




Oldest known version of this page was edited on 2008-02-17 09:34:12 by LuanO []
Page view:
XUI 4.0

Groovy Support


XUI 4.0 adds extended support for scripting, and with it the entire page can be implemented as a script. Previously only attributes could be evaluated as scripts, but the new support simplifies this and makes it more transparent.

To use the new support the appropriate builder must first be added to the project.

NumBuilderClasses=1
BuilderClass0=net.xoetrope.optional.scripts.groovy.GroovyBuilder


Once the builder has been loaded XUI will search fro .groovy files to implement the page class, just as it would search for a .class file if the page was implemented as Java. The page builder will also check if the script has been modified since the last load, and if it has the script will be reparsed. Reloading the script means that you can easily change the behavior of a running application. Thus the page can be declared as normal

<?xml version="1.0" encoding="UTF-8"?>
<XPage class="xui.groovy.Welcome.groovy">
	<Components>
	    <Button name="nextBtn" x="100" y="100" w="100" h="20" content="Next"/>
	</Components>
	<Events>
	  <Event target="nextBtn" method="next" type="ActionHandler"/>
	</Events>
</XPage>


note that the class attribute of the page now points to a Groovy file. The Groovy is then as follows:

package xui.groovy;

import net.xoetrope.xui.XPage;

public class Welcome
{
  XPage page;

  public Welcome()
  {
  }
  
  public void pageCreated()
  {
	println "pageCreated invoked"
  }
  
  public void next()
  {
	println "next invoked once again..."
	page.showPage( "MiddlePage" );
  }
}
Page was generated in 0.8001 seconds