Tag: java

Dynamically loading Images at Runtime

Dynamically loading Images at Runtime

To load images into your application at runtime, start with a placeholder in an Image component. Dynamically loaded images do not require an Image Definition in the Image Definitions Folder, but instead require that you instantiate a RuntimeImageDefinition in your Java code. You can use the UICreateEvent to access your Panel and its Image component, and use the Image component’s setImage method to assign the image that you are accessing by URL or API.

For details on accessing Panels and UI Components in Java code see the UI Annotations section.

(IMG)

Sample Java code for setting an Image Definition dynamically and loading an image at runtime
Customization of selectors in Java

Customization of selectors in Java

When iizi doesn’t provide a predefined function that is suitable, you can write Java code to return a boolean.

To do so, create a class implementing the interface com.iizix.api.ISelectorExpression. If you click on the editor link create a new Java class, a wizard will help you to create the class.

Example expression:

{ Java: "myapp.MySelector" }

Sample of such a Java Expression:

From the envProps, you can reach mostly everything. These environment properties come from the end-user device. You can also grab an instance of the AppSessionGyroor ClientSessionGyroas shown above to access e.g. client or application states for more advanced expressions

Available APIs in iiziGo

Available APIs in iiziGo

The many methods exposed by the iizi Platform API are available to you through Eclipse’s Java code completion. The iizi Core and Plugin Libraries are not visible in the iiziExplorer, but only in the Eclipse Java Perspective. For the complete iizi Platform Java API Specification see the iizi Java API reference at https://support.iizi.co.

You can also access the JavaDoc from your local installation, generally using port 2800 using the link http://localhost:2800/ and selecting the JavaDoc link on the displayed page.

Attaching Methods to VirtualSpace events

Attaching Methods to VirtualSpace events

A Java method and its annotation are automatically created when adding a method to the VirtualSpace event in the VirtualSpace Property Editor. In this example, we will attach a method to the OnVSFocus First assign a vsGroup to the ‘state and focus’ property of a Panel. With the vsGroup selected in the VirtualSpace Editor, the Property Editor displays the ‘Connectors’ section in which you can choose from the following events: OnVSCreate, OnVSDestroy, OnVSFocus, OnVSChange, and OnVSState. By clicking the more “…” button to the right of the OnVSFocus property, you can create a new Java method – with the correct annotation – that will be called every time your Panel gains focus or loses focus.

Below is a simple Java method created through the Property Editor to react to the OnVSFocus event. The method tests the property isFocusGained in which the iizi API method setScreenOrientation is called. For the inverse case, when focus is lost, the unlockScreenOrientation method in called. Notice that the main VirtualSpace itself is referenced in the Java class, and that the client session is accessed by a reference to the iizi Client Gyro.

Creating Java methods on VirtualSpace events in the properties view of the VirtualSpace editor
Attaching methods to VirtualSpace entities

Attaching methods to VirtualSpace entities

You can attach a Java method to react to any changes in a VirtualSpace entity’s instance value, as well as any changes to its state, by specifying a method name for OnVSChange. To listen to focus changes, use OnVSFocus. The method name specified must be present in the class that is attached to the VirtualSpace. You chose the method name, but your custom method must have the respective Java Method Signatures:

The method name editor has a more “…” button that drops down a menu to help you to create a new method, to select an existing method, or to define or fix the method annotation with the correct componentPath.

VirtualSpace Actions and Java methods

VirtualSpace Actions and Java methods

UI components with click action events, typically buttons or menu items, have a VS Action property listed under ‘Action’ in the Property Editor. For common interactions between components and Java methods, create a vsAction in your VirtualSpace and connect the vsAction to your Java method.

Creating a vsAction on a UI component through the component’s properties view

With the vsAction selected in the VirtualSpace Editor, search the Property Editor for the ‘Connectors’ section; here, in the value field of the OnVSAction property, click the more “…” menu and select a Java method or create a new method.

Create or assign a Java method to a vsAction in the properties view of the VirtualSpace editor
Java class and method connections

Java class and method connections

There is a tutorial video just down below.

Your Java code can be connected to the VirtualSpace through a Java class that uses the iizi Annotations for Java shown above.

Creating annotations for a class is automatic when you create a class through the Java Class property in the Property Editor. The iizi Annotation is created with the class. With this automated approach, iiziGo has already created a back reference for the VirtualSpace participant.

Creation of a new Java class for a VirtualSpace

Creating annotations for a method is also automatic when you create a method through the properties of a VirtualSpace entity in the VirtualSpace Editor. In the example below, the method will be connected to the OnVSChange property of a vsGroup. The iizi Annotation is created with the method, and the method is created with the correct Java Method Signature. With this automated approach, iiziGo has already created a back reference for the VirtualSpace participant. It is recommended to use Ctrl-shift-S, Save All, frequently, as you make major changes to your Panels, Text tables and VirtualSpace entities. This will enable iiziGo to update the many references needed to maintain live connections between your source code, Panels and VirtualSpace.

(IMG)

Creating Methods through the properties view of the VirtualSpace editor
What does it mean?

What does it mean?

If your web application includes Java code from a previous project or has been partially developed in another IDE, you can paste your Java code and folder structure into iiziGo after creating a new iizi Quickstart project. During deployment for distribution, all directories and libraries are packed into your iiziApp.

Having started with Quickstart, a main Java class is created for you in the src package. This has been named with your iizi project’s name, and contains the minimal iizi Annotations necessary for integrating your Java code into your iiziApp; you can connect your Java project through this class. At present – version 1.0 – only one Java class can serve as the annotated entry point for a VirtualSpace or a UI Panel.

A Java class annotation and three annotated Java methods

All references to iizi elements are made using a reference path name in the following format: “module:/path/name”. Java code is updated and changed using Eclipse refactoring mechanisms whenever required.

Your Java classes can be annotated to a VirtualSpace directly while your Java methods will have annotations to VirtualSpace entities. In the iizi Platform you do not normally add the ‘listeners’ that are common in UI programming; instead, you connect a method to the place requiring the specific functionality.

Data-oriented components

Data-oriented components

Upon creation of components that require data connections, you will be guided to connect the component to an existing VirtualSpace, and to create a vsField, vsTable or vsAction entity for that VirtualSpace.

Name your VirtualSpace entities as you would variables and fields in Java code (for e.g. vsMyAction); a “vs” prefix will help keep your application organized and make VirtualSpace entities easily distinguishable from Java fields and UI Component names.

Field Actors

Field Actors

The Field Actors are used for three purposes: conversion to a Value from a native value, conversion from a Valueto a native value, and validation. They are written in a Java class and are intended to be re-used in many parts of the application as required. The native value is the value used for the conversion, generally String or KString, but supports any JavaObject. The validation is done on the Value itself (i.e. has already passed the conversion stage to aValue).

The VSFieldEventparameter has access methods to what you need to perform the task, and is also used to set a validation message for conversion or validation failures.

The actor is an instance method of a name of your choice, annotated by @OnVSField in the class that is attached to the namespace, or it can be a static class located in Java libraries (Jar files) or other Java projects annotated with @OnVSFieldStatic.

Example of namespace class instance:

package mypkg;

import com.iizix.api.vs.OnVSField;
import com.iizix.api.vs.VSFieldEvent;
import com.iizix.api.vs.VSFieldEvent.Category;
import com.iizix.api.vs.VSFieldEvent.Op;
import com.iizix.api.vs.VirtualSpace;
import com.iizix.text.KString;

/**
 * JavaDoc shown in tooltips when hovering mouse over the class reference.
 */
@VirtualSpace(ref = "FirstProject:/vs/start")
public class StartNameSpaceListener {

    /**
     * This JavaDoc is shown in when hovering mouse over a method reference.
     * 
     * @param event
     *            The VS Field event.
     */
    @OnVSField(name = "fld", descr = "MyFieldActor ABC 123", ops = { Op.VALIDATE },
               source = { String.class })
    public void onField(VSFieldEvent event) {
        Object value = event.getConvertedValue();
        if (value instanceof String) {
            // Do your validation.
            String s = (String) value;
            if (s.equals("123")) {
                event.setMessage(
                        KString.newPlainKString("123 is not a valid value"),
                        Category.WARNING);
            }
        }
    }
}

In the context menu of the field actors, select New Field Actor, then the dialog box will list all available methods from the namespace attached class, and those that would match that are on the project’s classpath (including static methods in libraries and other projects):

When you select a method in the list, its description taken from the descr = "string"of the method annotation. When you close the dialog box, the tooltip of the field actor could look like:

Social media & sharing icons powered by UltimatelySocial

By continuing to use the site, you agree to the use of cookies. More information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close