The X-Meta engine is written in Java, and the execution model ultimately executes Java programs. Java programs can be invoked through Java Action. Java Ation is the bridge between the model and Java.
In addition, JavaAction is recommended for action models with performance requirements.
It is recommended to write code in your own Java project. In addition, Java code can also be written directly in the Java Action model.
Only a Java static method with a fixed ActionContext parameter can be invoked. Calling this method does not instantiate an instance of the class to which the method belongs.
Objects are instantiated when non-static Java methods are executed, and annotations can be used at this time. The following example is given.
package xworker.ide; import org.eclipse.swt.browser.Browser; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; import org.xmeta.ActionContext; import org.xmeta.Thing; import org.xmeta.World; import org.xmeta.annotation.ActionClass; import org.xmeta.annotation.ActionField; import org.xmeta.annotation.ActionParams; @ActionClass(creator="newInstance") public class TestJavaActionAnnotation { @ActionField(name="shell") Shell shellAbc; @ActionField Browser browser; @ActionParams(names="urlText") public void urlTextSelection(Text urlText, ActionContext actionContext) { browser.setUrl(urlText.getText()); } public void okSelection(ActionContext actionContext) { System.out.println("okButton session "); } public void cancelSelection() { System.out.println("cancelButton session "); shellAbc.dispose(); } public static Object newInstance(ActionContext actionContext) { return new TestJavaActionAnnotation(); } public static void main(String[] args) { try { World world = World.getInstance(); world.init("./xworker/"); Thing thing = World.getInstance().getThing("_local.test.core.actions.javaaction.TestAnnotation"); thing.doAction("run"); }catch(Exception e) { e.printStackTrace(); } } }
The test code of the model.
<?xml version="1.0" encoding="utf-8"?> <Shell name="shell" descriptors="xworker.swt.widgets.Shell" text="测试Annotation" width="800" height="600" label="TestAnnotation"> <GridLayout name="shellGridLayout"></GridLayout> <Text name="urlText" BORDER="true"> <GridData name="GridData" style="FILL_HORIZONTAL"></GridData> <Listeners> <Listener type="DefaultSelection"> <JavaAction name="okSelection" outerClassName="xworker.ide.TestJavaActionAnnotation" methodName="urlTextSelection"></JavaAction> </Listener> </Listeners> </Text> <Browser name="browser" _xmeta_id_="browsre"> <GridData name="browserGridData" style="FILL_BOTH"></GridData> </Browser> <Composite name="buttonComposite" _xmeta_id_="1264"> <GridData name="buttonCompositeGridData" _xmeta_id_="1265" style="FILL_HORIZONTAL" horizontalAlignment="END"></GridData> <RowLayout name="buttonCompositeRowLayout" _xmeta_id_="1266"></RowLayout> <Button name="okButton" _xmeta_id_="1267" text="Ok"> <RowData name="RowData" _xmeta_id_="1268" width="80"></RowData> <Listeners _xmeta_id_="1269"> <Listener name="okButtonSelection" _xmeta_id_="1270"> <JavaAction name="okSelection" outerClassName="xworker.ide.TestJavaActionAnnotation" methodName="okSelection"></JavaAction> </Listener> </Listeners> </Button> <Button name="cancelButton" _xmeta_id_="1271" text="Cancel"> <RowData name="RowData" _xmeta_id_="1272" width="80"></RowData> <Listeners _xmeta_id_="1273"> <Listener name="cancelButtonSelection" _xmeta_id_="1274"> <JavaAction name="okSelection" outerClassName="xworker.ide.TestJavaActionAnnotation" methodName="cancelSelection"></JavaAction> </Listener> </Listeners> </Button> </Composite> </Shell>
Copyright © 2007-2019 XWorker.org 版权所有 沪ICP备08000575号