Post-Conversion

To run the sample application please go to Gitpod, and look for the README.md with instructions on how to use it.

In case you want to review the source code of the migrated application, you can find it here: HelloWorld sample code. Also, the migrated code can be downloaded from PBMAPJavaHelloWorld.

Migrated Code Overview

This section explains in detail the following topics:

  1. How does the migrated code look like?

  2. Which changes were made over the existing code?

  3. What are the helpers delivered by Mobilize for?

How does the migrated code look like?

Before moving to explain the output code, first let's take a look at the PowerBuilder sample code:

forward
global type w_sample from window
end type
type dw_1 from datawindow within w_sample
end type
type sle_1 from singlelineedit within w_sample
end type
type st_1 from statictext within w_sample
end type
type cb_1 from commandbutton within w_sample
end type
end forward

global type w_sample from window
integer width = 1266
integer height = 844
boolean titlebar = true
string title = "Untitled"
boolean controlmenu = true
boolean minbox = true
boolean maxbox = true
boolean resizable = true
long backcolor = 67108864
string icon = "AppIcon!"
boolean center = true
dw_1 dw_1
sle_1 sle_1
st_1 st_1
cb_1 cb_1
end type
global w_sample w_sample

on w_sample.create
this.dw_1=create dw_1
this.sle_1=create sle_1
this.st_1=create st_1
this.cb_1=create cb_1
this.Control[]={this.dw_1,&
this.sle_1,&
this.st_1,&
this.cb_1}
end on

on w_sample.destroy
destroy(this.dw_1)
destroy(this.sle_1)
destroy(this.st_1)
destroy(this.cb_1)
end on

type dw_1 from datawindow within w_sample
integer x = 73
integer y = 256
integer width = 1070
integer height = 420
integer taborder = 20
string title = "none"
string dataobject = "d_sample_list"
boolean livescroll = true
borderstyle borderstyle = stylelowered!
end type

type sle_1 from singlelineedit within w_sample
integer x = 471
integer y = 80
integer width = 320
integer height = 112
integer taborder = 10
integer textsize = -10
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
long textcolor = 33554432
borderstyle borderstyle = stylelowered!
end type

type st_1 from statictext within w_sample
integer x = 96
integer y = 80
integer width = 320
integer height = 112
integer textsize = -10
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
long textcolor = 33554432
long backcolor = 67108864
string text = "Test Dw"
boolean focusrectangle = false
end type

type cb_1 from commandbutton within w_sample
integer x = 827
integer y = 80
integer width = 320
integer height = 112
integer taborder = 10
integer textsize = -10
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
string text = "Add"
end type

event clicked;int li_row
if sle_1.text <> "" then
  li_row = dw_1.insertrow( 0)
  dw_1.setitem( li_row, 1, sle_1.text)
end if
end event

The converted code from the one above will consist of two parts:

  • The Backend code containing the Java files and the helpers .war to emulate the PowerBuilder functionality.

  • The Frontend code with the angular project for the web application.

As the image shown below:

The generated Frontend files are added in the automatically created folder sampleSite-angular, which contains an angular project template and all these converted files.

The structure of this sampleSite-angular folder is as follows:

  • sampleSite-angular

    • src

      • app

        • components

          • sample

            • w_sample

              • w_sample.component.ts

              • w_sample.component.css

              • w_sample.component.html

            • d_sample_list

              • d_sample_list.component.ts

              • d_sample_list.component.css

              • d_sample_list.component.html

            • index.ts

        • app.component.css: stylesheet file used by the app.component

        • app.component.html: html file associated with the app.component

        • app.component.ts: startup angular component of the migrated application

        • app.component.spec.ts: this is the file to include the frontend unit tests

        • app.module.ts: this module includes all the sub-modules of all the application. e.g. You have two projects (pbt): project1.pbt and project2.pbt. This will yield two sub-modules: project1.module.ts and project2.module.ts

        • app-routing.module.ts: this file handles the application routing

        • root.component.ts: required file to define the root component of the application, where all other components will reside

        • sample.module.ts: this module includes all the components of the sample pbt.

      • index.html: this is the page that launches the angular startup component: app.component

      • styles.css

    • package.json: json file that contains the list of JavaScript packages required by the application.

Now let's take a look at these generated components. We will start with the HTML file:

Every control declared in the w_sample file will have its corresponding HTML tag; for example, the sample application has a Command Button control, so the HTML has this:

The HTML tag wm-command-button is Mobilize's corresponding Command Button angular component. Mobilize provides a series of angular components which you can use in the future when adding new controls to an existing screen.

Following with these components review, we have the CSS file that matches with the previously reviewed HTML tag:

.sample_w_sample .w_sample {
    width: 279px;
    height: 211px;
    background-color: ButtonFace;
}
.sample_w_sample .dw_1 {
    position: absolute;
    left: 5.77%;
    top: 30.33%;
    width: 84.52%;
    height: 49.76%;
    border-style: solid;
}
.sample_w_sample .sle_1 {
    position: absolute;
    left: 37.2%;
    top: 9.48%;
    width: 25.28%;
    height: 13.27%;
    font-weight: normal;
    font-family: Tahoma;
    color: WindowText;
    border-style: solid;
}
.sample_w_sample .st_1 {
    position: absolute;
    left: 7.58%;
    top: 9.48%;
    width: 25.28%;
    height: 13.27%;
    font-weight: normal;
    font-family: Tahoma;
    color: WindowText;
    background-color: ButtonFace;
}
.sample_w_sample .cb_1 {
    position: absolute;
    left: 65.32%;
    top: 9.48%;
    width: 25.28%;
    height: 13.27%;
    font-weight: normal;
    font-family: Tahoma;
}

Every control declared in the w_sample file will have its corresponding CSS properties. For example, properties like facename, width, and height from the Command Button control are mapped into the CSS file like this:

.sample_w_sample .cb_1 {
    position: absolute;
    left: 65.32%;
    top: 9.48%;
    width: 25.28%;
    height: 13.27%;
    font-weight: normal;
    font-family: Tahoma;
}

Finally, the typescript file consists of an angular component class declaration like the one below, for the window class.

import { Component, ChangeDetectorRef, Renderer2, ElementRef, ViewEncapsulation} from "@angular/core";
import { BaseControlComponent, LengthConverter} from "@mobilize/powercomponents";
import { dataTransfer} from "@mobilize/base-components";
@Component({
   selector : 'sample-w_sample',
   templateUrl : './w_sample.component.html',
   styleUrls : ['./w_sample.component.scss'],
   encapsulation : ViewEncapsulation.None
})
@dataTransfer(['mobsample_sample_w_sample'])
export class w_sampleComponent extends BaseControlComponent {
   constructor (changeDetector : ChangeDetectorRef,render2 : Renderer2,elem : ElementRef,lengthConverter : LengthConverter) {
      super(changeDetector,render2,elem,lengthConverter);
   }
}

Every window, for example w_sample, should have an Angular Component for the form to be displayed in the browser. This component defines three metadata properties:

  • selector — the component's CSS element selector. This selector tells Angular to create and insert an instance of the component where it finds the tag in a HTML template (e.g 'sample-w_sample')

  • templateUrl — the location of the component's template file. (e.g './w_sample.component.html')

  • styleUrls — the location of the component's private CSS styles. (e.g './w_sample.component.scss')

Which changes were made over the existing code?

Let’s have a look at the converted code found in w_sample.java and Iw_sample.java files.

//Iw_sample.java
package com.sample.sample.sample;

import com.mobilize.jwebmap.models.WindowModel;

public interface Iw_sample extends WindowModel
{
  w_sample.dw_1 getDw_1();
  void setDw_1(w_sample.dw_1 value);
  w_sample.sle_1 getSle_1();
  void setSle_1(w_sample.sle_1 value);
  w_sample.st_1 getSt_1();
  void setSt_1(w_sample.st_1 value);
  w_sample.cb_1 getCb_1();
  void setCb_1(w_sample.cb_1 value);
  void doConstructor();
  void doWMInit();
}

//w_sample.java
package com.sample.sample.sample;

import org.springframework.beans.factory.annotation.Configurable;
import com.mobilize.jwebmap.aop.annotations.WebMAPStateManagement;
import com.sample.sample.sample.Iw_sample;
import com.sample.datamanagers.sample.sample.d_sample_list.d_sample_list;
import static com.mobilize.jwebmap.datatypes.ShortHelper.shortOf;
import static com.mobilize.jwebmap.conditionals.ConditionalsHelper.isTrue;
import static com.mobilize.jwebmap.conditionals.ComparisonHelper.notEq;
import static com.mobilize.jwebmap.datatypes.IntegerHelper.integerOf;

@Configurable
@WebMAPStateManagement
public class w_sample extends com.mobilize.jwebmap.models.WindowModelImpl implements Iw_sample
{
  public dw_1 dw_1;
  public dw_1 getDw_1() {
    return this.dw_1;
  }
  public void setDw_1(dw_1 value) {
    this.dw_1 = value;
  }
  public class dw_1 extends com.mobilize.jwebmap.datamanager.DataManagerControl
  {
    public dw_1(){}
    public void doWMInit() {
      super.doWMInit();
      this.setX(shortOf(16));
      this.setY(shortOf(64));
      this.setWidth(shortOf(235));
      this.setHeight(shortOf(105));
      this.setTabOrder(shortOf(20));
      this.setTitle(getLocalizedText("none"));
      this.setDataManager(new d_sample_list());
    }
  }
  public sle_1 sle_1;
  public sle_1 getSle_1() {
    return this.sle_1;
  }
  public void setSle_1(sle_1 value) {
    this.sle_1 = value;
  }
  public class sle_1 extends com.mobilize.jwebmap.models.TextModel
  {
    public sle_1(){}
    public void doWMInit() {
      super.doWMInit();
      this.setX(shortOf(104));
      this.setY(shortOf(20));
      this.setWidth(shortOf(70));
      this.setHeight(shortOf(28));
      this.setTabOrder(shortOf(10));
    }
  }
  public st_1 st_1;
  public st_1 getSt_1() {
    return this.st_1;
  }
  public void setSt_1(st_1 value) {
    this.st_1 = value;
  }
  public class st_1 extends com.mobilize.jwebmap.models.LabelModel
  {
    public st_1(){}
    public void doWMInit() {
      super.doWMInit();
      this.setX(shortOf(21));
      this.setY(shortOf(20));
      this.setWidth(shortOf(70));
      this.setHeight(shortOf(28));
      this.setText(getLocalizedText("Test Dw"));
    }
  }
  public cb_1 cb_1;
  public cb_1 getCb_1() {
    return this.cb_1;
  }
  public void setCb_1(cb_1 value) {
    this.cb_1 = value;
  }
  public class cb_1 extends com.mobilize.jwebmap.models.ButtonModel
  {
    public cb_1(){}
    public Integer clicked() {
      Short li_row = 0;
      if (isTrue(notEq(getSle_1().getText(), ""))){
          li_row = shortOf(getDw_1().insertRow(0));
          getDw_1().setItem(integerOf(li_row), shortOf(1), getSle_1().getText(), "String");
        }
      return 0;
    }
    public void doWMInit() {
      super.doWMInit();
      this.setX(shortOf(182));
      this.setY(shortOf(20));
      this.setWidth(shortOf(70));
      this.setHeight(shortOf(28));
      this.setTabOrder(shortOf(10));
      this.setText(getLocalizedText("Add"));
      this.addToEventList("bnclicked", true);
      this.addToEventMapper("bnclicked", "clicked");
    }
  }
  @Override
  public void doConstructor() {
    this.constructor();
    this.dw_1.doConstructor();
    this.sle_1.doConstructor();
    this.st_1.doConstructor();
    this.cb_1.doConstructor();
  }
  public w_sample(){
    super ();
  }
  public void doWMInit() {
    super.doWMInit();
    this.dw_1 = new dw_1();
    this.dw_1.setName("dw_1");
    this.setSle_1(new sle_1());
    this.sle_1.setName("sle_1");
    this.setSt_1(new st_1());
    this.st_1.setName("st_1");
    this.setCb_1(new cb_1());
    this.cb_1.setName("cb_1");
    this.setTargetName("sample");
    this.setLibName("sample");
    this.setSimpleName("w_sample");
    this.setName("mobsample_sample_w_sample");
    this.setWidth(shortOf(279));
    this.setHeight(shortOf(211));
    this.setTitleBar(true);
    this.setTitle(getLocalizedText("Untitled"));
    this.setControlMenu(true);
    this.setMinBox(true);
    this.setMaxBox(true);
  }
}

The most relevant changes made to the input code by WebMap framework are:

  • Class declarations: WebMap adds @Configurable and @WebMAPStateManagement annotations upon the class declaration.

    @Configurable
    @WebMAPStateManagement
    public class w_sample extends com.mobilize.jwebmap.models.WindowModelImpl implements Iw_sample
    {
    }
  • Variable declarations: WebMap adds a getter and setter for the variable declaration. For example, Get and Set methods for sle_1 PowerBuilder Single Line Edit component.

      public sle_1 sle_1;
      public sle_1 getSle_1() {
          return this.sle_1;
      }
      public void setSle_1(sle_1 value) {
          this.sle_1 = value;
      }
  • doWMInit method declaration: WebMap adds doWMInit to the w_sample.java. This method initializes the component and sets each component property values.

        public void doWMInit() {
            super.doWMInit();
            this.dw_1 = new dw_1();
            this.dw_1.setName("dw_1");
            this.setSle_1(new sle_1());
            this.sle_1.setName("sle_1");
            this.setSt_1(new st_1());
            this.st_1.setName("st_1");
            this.setCb_1(new cb_1());
            this.cb_1.setName("cb_1");
            this.setTargetName("sample");
            this.setLibName("sample");
            this.setSimpleName("w_sample");
            this.setName("mobsample_sample_w_sample");
            this.setWidth(shortOf(279));
            this.setHeight(shortOf(211));
            this.setTitleBar(true);
            this.setTitle(getLocalizedText("Untitled"));
            this.setControlMenu(true);
            this.setMinBox(true);
            this.setMaxBox(true);
        }
  • Type Mappings: WebMap converts the types of the source code to the corresponding type in the new Web Application. For example, datawindow dw_1 has been mapped to com.mobilize.jwebmap.datamanager.DataManagerControl, and cb_1 Command Button to com.mobilize.jwebmap.models.ButtonModel.

      public class dw_1 extends com.mobilize.jwebmap.datamanager.DataManagerControl
      {
      }
    
      public class cb_1 extends com.mobilize.jwebmap.models.ButtonModel
      {
      }
  • Internal component classes: WebMap adds an internal class for each component of the window, for example, st_1 internal class added to w_sample.java

    public class st_1 extends com.mobilize.jwebmap.models.LabelModel
    {
    }

All these attributes added by Mobilize let Mobilize's Weaving mechanism know it has to inject some code in compilation time to allow the proper execution of web applications.

What are the helpers delivered by Mobilize for?

The helpers delivered by Mobilize are a set of utilities whose function is to emulate PowerBuilder functionality into Java together with the FrontEnd WebMap part of the application. These helpers are divided into two projects:

Backend helpers

Backend Helpers project contains:

  • The core of your migrator

  • Serialization mechanism

  • Interceptors (AOP)

  • View Models

  • Events and Methods of Windows and Data Windows.

Those libraries represent the core of the PowerBuilder application in the “Java platform”. Also, some libraries providing the link and the control between the data and the Frontend user interface are also found here. Some of those libraries are:

  • Datamanager: a Java Plain Old Java Objects (POJO) implementing PowerBuilder Datawindow object. It provides services such as paged data retrieving and other data operations like insert, delete, update and read.

  • Jasper Reports: a dynamic component that represents a PowerBuilder Datawindow printing view, displayed as a PDF format.

  • Database access: this main component handles data persistence and encapsulates the client business logic in different database engines like Oracle and Sybase. This sub layer will provide services to get access to the persistent mechanism. It will be implemented using Spring JDBC, and it will include a Connection Pooling mechanism in order to improve the application's performance.

  • State management: due to its nature, a PowerBuilder application works under a state-full model. However, a Web application does not work like this. In order to preserve behavior a set of Java classes and some Spring Framework features such as Aspect Oriented Programming (AOP) will provide the Application layer with a state management mechanism.

These helpers are delivered as a war file, so the previous information intends to explain what is contain in them.

Frontend helpers

Backend

Building Backend

In this section, we will explain how to build the backend code, so you can later run the application in your default browser. This section applies if you have the JavaHelpers code or the JavaHelpers jar file.

Converted Code Prerequisites

First of all, in order to compile and execute PBJava migrated application, you need the following software installed in your computer:

Building the Backend code

Add environment variables

To be able to run the migrated project, you must add the following variables to the operating system:

  • oms_dir: any directory where you want to start the file system for your application.

  • JAVA_HOME: Java base installation directory. (prerequisite)

  • CATALINA_HOME: Tomcat installation base directory. (prerequisite)

For Windows Users

  1. Press the Windows key and type "environment".

  2. Choose the "Edit the system environment variables" option.

  3. On System Properties window, press "Environment Variables" button

  4. Now, on Environment Variables window, add a new entry for every variable mentioned above.

For Linux Users

  1. Open a command prompt window (ctrl + alt + T) and type the following command.

    sudo -H gedit /etc/environment
  2. Type your password

  3. Edit the text file just opened and add the variables typing: JAVA_HOME=java installation path

  4. Save the file

  5. Logout and login again

Setting up the Java project

  1. Look for the helpers code or helpers.jar previously acquired from Mobilize.

  2. Look for the template of WebMAP properties previously acquired from Mobilize, and save it in the created folder SampleConf

  3. Look for the connection.properties file previously acquired from Mobilize, and save it in the created folder SampleConf

  4. Open Spring Tool Suite

  5. Create a new workspace

  6. Configure JAVA JDK. Go to Window -> Preferences -> Java -> Installed JREs -> Add -> Choose Java installation JDK folder

  7. In the Package Explorer, right click and select the Import option.

    1. In the dialog, select Maven, Existing Maven Projects and then Next

  8. Select the Java Helpers pom.xml previously downloaded and click OK and then Finish

  9. Repeat step 6 for the Sample project and add both ReferenceApplication and Target pom.xml

  10. Select the Project Menu, make sure Clean all projects checkbox is selected and press Clean button

  11. Right click on ws project on Package Explorer and select Maven -> Update Project -> Select All -> OK Button

  12. Configure the Application Property files

Configure Application and Connection Property files

  1. Click on Run menu

  2. Select Debug Configuration

  3. Right Click on Apache Tomcat option on the left pane -> New

  4. Select the Classpath tab

  5. Click on User Entries

  6. Click on Advanced...

  7. Click on Add External Folder -> press OK button

  8. Select the folder SampleConf (created on above step)

  9. Click Apply

ReferenceApplication project

This is the web project where the HTML generated files and the Object State Interceptor are placed. This is the project you have to run to see the web application on your browser.

Target project

This is the migrated code, all the java files, windows and data-windows, generated after the migration are here.

connection.properties file

The connection.properties file is used to specify the database connection configuration. Java Helpers use JDBC API and JDBC drivers to connect and execute queries to the database.

Example of a Sybase configuration:

connection.url=jdbc:jtds:sybase://:/
connection.username=username
connection.password=password
connection.driver-class-name=net.sourceforge.jtds.jdbc.Driver

webmap.properties file

This file contains configuration entries used by the helpers to run the desired application. In this file you can specify the path for the images that you want to display, language (affect for example decimal places separator according to region), etc.

The line application.appstart=com.sample.sample.sample.sample indicates the module that you want to run.

# Configuration file
enableUpperCaseResponse=true
allowMultipleOpenWindows=true
usRegionDateFormat=true
images.path=images
application.trimSpaces=true
application.MaximizeMDI=true
locale=en-us
application.downloadXls=true
application.appstart=com.sample.sample.sample.sample
# WindowModel Serialization Custom properties  
serialize.WindowModel.minBox=true
serialize.WindowModel.maxBox=true
serialize.WindowModel.windowType=true
serialize.WindowModel.windowState=true
serialize.WindowModel.titleBar=true
serialize.WindowModel.controlMenu=true
serialize.WindowModel.toolbarVisible=true
# TextModel Serialization Custom properties  
serialize.TextModel.background=true
serialize.TextModel.password=true
# Datamanager Serialization Custom properties  
serialize.DataManager.columnHeader=true
serialize.DataManager.header=true
serialize.DataManager.summary=true
serialize.DataManager.footer=true
serialize.DataManager.title=true
serialize.DataManager.trailer=true
serialize.DataManager.detail=true
# Band Serialization Properties
# SQLProvider supported provider values OraSqlDataProvider or SybaseSqlDataProvider
application.SqlDataProvider=SybaseSqlDataProvider

Adding Tomcat Server

  1. Go to the bottom of the Package Explorer left pane

  2. Right click on Servers

  3. Go to New

  4. Click on Server option

  5. Expand Apache option

  6. Select Tomcat v9.0 Server and click Next

  7. On Tomcat installation directory click Browse

  8. Find your Tomcat folder installation

  9. Click Finish

Running the code

Compile the Project

  1. Select the Project menu and check the Build Automatically option. This option will build the entire project automatically when a change to any file is detected

  2. For a manual build, in each imported project, right + click, select on Run As sub-menu and select Maven build

  3. In goals, type "clean install" and press Run.

Setup the Server

  1. right + click on the Tomcat server and select Open

  2. In Timeouts, change the start to 400 ms for the desired time

  3. Save the changes

  4. Select the ws project, right + click and select the sub-menu Run As… and then Run On Server

  5. Open a web browser and browse http://localhost:8080

  6. Right click on ws project

  7. Select Properties

  8. Scroll down and choose Web project Settings

  9. Modify Context root field, changing current value (in this case "ws") to "/"

  10. Click on Apply button and then OK (this will change the server context)

Modifying/Extending Backend

In this section we will explain how to modify the migrated code with a practical example. For this exercise, you will add a button on the Backend which opens a second window showing the text "Hello World".

Modifying Backend

First, let's expand the size of the w_sample window, to include the new ButtonModel component.

  1. Go to method doWMInit in w_sample.java

  2. Modify setHeight property to 400:

    this.setHeight(shortOf(500));
  3. On w_sample.java add a new ButtonModel component cb_2

      public cb_2 cb_2;
      public cb_2 getCb_2() {
        return this.cb_2;
      }
      public void setCb_2(cb_2 value) {
        this.cb_2 = value;
      }
      public class cb_2 extends com.mobilize.jwebmap.models.ButtonModel
      {
        public cb_2(){}
    
        public void doWMInit() {
          super.doWMInit();
          this.setX(shortOf(182));
          this.setY(shortOf(180));
          this.setWidth(shortOf(70));
          this.setHeight(shortOf(28));
          this.setTabOrder(shortOf(10));
          this.setText(getLocalizedText("Open"));
          this.addToEventList("bnclicked", true);
          this.addToEventMapper("bnclicked", "clicked");
        }
      }
  4. On method doConstructor add the following line to initializes the new component

    this.cb_2.doConstructor();
  5. On method doWMInit initialize and set the name of the new component cb_2

    this.setCb_2(new cb_2());
    this.cb_2.setName("cb_2");
  6. On interface Iw_sample.java, add a get and set method for cb_2

      w_sample.cb_2 getCb_2();
      void setCb_2(w_sample.cb_2 value);
  7. Finally, add or register the new window on the entry point of the application, sample.java. On method getWindowClassNames(), add the following line before return statement:

    windows.put("w_window1", "com.sample.sample.sample.w_window1");

Extending Backend

After expanding the size of the w_sample window, let's add a new window to the project, like this:

  1. On package com.sample.sample.sample add a new java class called w_window1, extending from com.mobilize.jwebmap.models.WindowModelImpl, implementing Iw_window1

    package com.sample.sample.sample;
    
    import static com.mobilize.jwebmap.datatypes.ShortHelper.shortOf;
    import org.springframework.beans.factory.annotation.Configurable;
    import com.mobilize.jwebmap.aop.annotations.WebMAPStateManagement;
    
    @Configurable
    @WebMAPStateManagement
    public class w_window1 extends com.mobilize.jwebmap.models.WindowModelImpl implements Iw_window1 {
    
    }
  2. Add a StaticTextModel component to w_window1

    public st_1 st_1;
    public st_1 getSt_1() {
      return this.st_1;
    }
    public void setSt_1(st_1 value) {
      this.st_1 = value;
    }
    public class st_1 extends com.mobilize.jwebmap.models.LabelModel
    {
      public st_1(){}
      public void doWMInit() {
        super.doWMInit();
        this.setX(shortOf(21));
        this.setY(shortOf(20));
        this.setWidth(shortOf(70));
        this.setHeight(shortOf(28));
        this.setText(getLocalizedText("Hello World"));
      }
    }
  3. Add w_window1 constructor

    public w_window1(){
      super ();
    }
  4. Add the doWMInit and doConstructor method as follows:

    @Override
    public void doConstructor() {
        this.constructor();
        this.st_1.doConstructor();
    }
    
    public void doWMInit() {
        super.doWMInit();
        this.setSt_1(new st_1());
        this.st_1.setName("st_1");
        this.st_1.setText("Hello World");
        this.setTargetName("sample");
        this.setLibName("sample");
        this.setSimpleName("w_window1");
        this.setName("mobsample_sample_w_window1");
        this.setWidth(shortOf(279));
        this.setHeight(shortOf(211));
        this.setTitleBar(true);
        this.setTitle(getLocalizedText("Window 1"));
        this.setControlMenu(true);
        this.setMinBox(true);
        this.setMaxBox(true);
    }
  5. Add clicked event to cb_2 internal class on w_sample.java:

      public class cb_2 extends com.mobilize.jwebmap.models.ButtonModel
      {
        public cb_2(){}
        public Integer clicked() {
          return 0;
        }
        public void doWMInit() {
          super.doWMInit();
          this.setX(shortOf(182));
          this.setY(shortOf(180));
          this.setWidth(shortOf(70));
          this.setHeight(shortOf(28));
          this.setTabOrder(shortOf(10));
          this.setText(getLocalizedText("Open"));
          this.addToEventList("bnclicked", true);
          this.addToEventMapper("bnclicked", "clicked");
        }
      }
  6. Add code to clicked event to open the new window. First add the ViewManager property, which manages all about displaying and closing windows.

    @Autowired
    @JsonIgnore
    private ViewManager _viewMng;
    
    @JsonIgnore
    @WebMAPIgnoreStateManagement
    public ViewManager getViewManager() {
        return _viewMng;
    }
  7. Now go to clicked event on cb_2 and add the following code:

    getViewManager().showWindow(new WebMapAtomicReference(new w_window1()), w_window1.class);
    public Integer clicked() {
        getViewManager().showWindow(new WebMapAtomicReference(new w_window1()), w_window1.class);
        return 0;
    }
  8. On package com.sample.sample.sample add a new java interface called Iw_window1, extending from WindowModel

    package com.sample.sample.sample;
    
    import com.mobilize.jwebmap.models.WindowModel;
    
    public interface Iw_window1 extends WindowModel {
        void doConstructor();
        void doWMInit();
    }
  9. Add a st_1 get and set to include the component to the new interface

        w_window1.st_1 getSt_1();
        void setSt_1(w_window1.st_1 value);
  10. Now, let's take a look to the final class and interface just added:

    //Iw_window1
    package com.sample.sample.sample;
    
    import com.mobilize.jwebmap.models.WindowModel;
    
    public interface Iw_window1 extends WindowModel {
        void doConstructor();
    
        void doWMInit();
    
        w_window1.st_1 getSt_1();
    
        void setSt_1(w_window1.st_1 value);
    }
    //w_window1
    package com.sample.sample.sample;
    
    import static com.mobilize.jwebmap.datatypes.ShortHelper.shortOf;
    import org.springframework.beans.factory.annotation.Configurable;
    import com.mobilize.jwebmap.aop.annotations.WebMAPStateManagement;
    
    @Configurable
    @WebMAPStateManagement
    public class w_window1 extends com.mobilize.jwebmap.models.WindowModelImpl implements Iw_window1 {
    
        public st_1 st_1;
    
        public st_1 getSt_1() {
            return this.st_1;
        }
    
        public void setSt_1(st_1 value) {
            this.st_1 = value;
        }
    
        public class st_1 extends com.mobilize.jwebmap.models.LabelModel {
            public st_1() {
            }
    
            public void doWMInit() {
                super.doWMInit();
                this.setX(shortOf(21));
                this.setY(shortOf(20));
                this.setWidth(shortOf(70));
                this.setHeight(shortOf(28));
                this.setText(getLocalizedText("Hello World"));
            }
        }
    
        @Override
        public void doConstructor() {
            this.constructor();
            this.st_1.doConstructor();
        }
    
        public w_window1() {
            super();
        }
    
        public void doWMInit() {
            super.doWMInit();
            this.setSt_1(new st_1());
            this.st_1.setName("st_1");
            this.st_1.setText("Hello World");
            this.setTargetName("sample");
            this.setLibName("sample");
            this.setSimpleName("w_window1");
            this.setName("mobsample_sample_w_window1");
            this.setWidth(shortOf(279));
            this.setHeight(shortOf(211));
            this.setTitleBar(true);
            this.setTitle(getLocalizedText("Window 1"));
            this.setControlMenu(true);
            this.setMinBox(true);
            this.setMaxBox(true);
        }
    }
    ``
    

Frontend

Building Frontend

In this section, we will explain how to build the Frontend code, so you can later run the application in your default browser.

Converted Code Prerequisites

In order to compile and execute the FrontEnd WebMap migrated part of the application, you need the following software installed in your computer:

  • Angular Client Framework. To install open a command prompt and run the following command npm install -g @angular/cli

As the previous examples, we are using the following sample migrated code.

Building the Frontend code

  1. Install the Angular CLI, if you haven't already done so.

    npm install -g @angular/cli
  2. Install yarn, if you haven't already done so.

    npm install -g yarn
  3. Update the npm configuration's registry key by following the next setup guide. This is required to resolve Mobilize's packages.

  1. Go to productcatalogSite\productcatalogSite-angular folder

  2. Open a Command Prompt from that folder

  3. Start recovering the node modules by executing this command:

    yarn install
  4. Once the packages are successfully recovered, you can build the code.

  5. Run the following command for development environment

    npm run build

    The --prod flag is optional, and it is used to produce optimized binaries on production mode.

    ng build --prod
  6. The content of the output folder named wwwroot must be copied to ReferenceApplication\src\main\webapp

Modifying/Extending Frontend

In this section we will explain how to modify and extend the migrated code with a practical example. For this exercise, you will add a button on the FrontEnd which opens a second window showing the text "Hello World".

Modifying the FrontEnd

To add elements in an Angular component previously created, you need to add the new element using the corresponding selector. In this case, the selector for a button is wm-command-button, so, in order to add the button cb_2 to w_sample, you need to:

  1. Add the following line after cb_1

  2. Check the resulting code looks like the one below:

  3. Add the corresponding style section for this button in w_sample.component.scss.

    .sample_w_sample .cb_2 {
        position: absolute;
        left: 71.82%;
        top: 9.48%;
        width: 24.28%;
        height: 13.27%;
        font-weight: normal;
        font-family: Tahoma;
    }

Extending the FrontEnd

To add new components, you need to create 3 files in a folder with the same name of the component. This new folder will be added under the Frontend project and it will contain the following files:

  1. component.html

  2. component.scss

  3. component.ts

For the previous window1 example, we are going to create the 3 files like this:

TS file: w_window1.component.ts

import { Component, ChangeDetectorRef, Renderer2, ElementRef, ViewEncapsulation} from "@angular/core";
import { BaseControlComponent, LengthConverter} from "@mobilize/powercomponents";
import { dataTransfer} from "@mobilize/base-components";
@Component({
   selector : 'sample-w_window1',
   templateUrl : './w_window1.component.html',
   styleUrls : ['./w_window1.component.scss'],
   encapsulation : ViewEncapsulation.None
})
@dataTransfer(['mobsample_sample_w_window1'])
export class w_window1Component extends BaseControlComponent {
   constructor (changeDetector : ChangeDetectorRef,render2 : Renderer2,elem : ElementRef,lengthConverter : LengthConverter) {
      super(changeDetector,render2,elem,lengthConverter);
   }
}

Pay attention to the dataTransfer property since it must be the same as the name set in the doWMinit of the window.

this.setName("mobsample_sample_w_window1");

SCSS file: w_window1.component.scss

If necessary, you can add the CSS properties for each component here. For the w_window1 in the example, this is the resulting CSS sheet:

.sample_w_window1 .w_window1 {
    width: 279px;
    height: 211px;
    background-color: ButtonFace;
}


.sample_w_window1 .st_1 {
    position: absolute;
    left: 7.58%;
    top: 9.48%;
    width: 25.28%;
    height: 13.27%;
    font-weight: normal;
    font-family: Tahoma;
    color: WindowText;
    background-color: ButtonFace;
}

HTML file: w_window1.component.html

The third and final file created for the component, is a HTML that looks like this:

Some important aspects to consider here are:

  • Validate if the model exists at the beginning of the component

  • Assign the corresponding model for each control. For Example:

    wm-window --> [model]="model"\
    st_1      --> [model]="model.st_1"\

After extending and building both backend and frontend, the final result will look something like this:

Debugging

In this section we will show you how to debug the migrated Backend code on Spring Tools and how to use the main debugging features. This section applies if you have the JavaHelpers code or the JavaHelpers jar file.

Once the Backend and Frontend of the sample code are compiled, you need to:

  1. Select Window -> Show View -> Servers.

  2. Right Click on server in the Servers panel

  3. Select Restart in Debug or Debug options.

  4. Add breakpoints in your code,

  5. Right Click on application

  6. Select Debug As -> Debug on Server

  7. Finally, you'll see your app running on a browser.

Changing to Debug Perspective

In order to improve the view when debugging, you can change the debug perspective as shown in the following image.

Use conditional breakpoint

Conditional breakpoints allow threads to stop at a targeted line when a condition it's true. To add a conditional breakpoint, follow these steps:

  1. Right Click the breakpoint and select Breakpoint Properties.

  2. Tick the conditional checkbox under Breakpoint properties.

  3. Put the condition as per your requirement in the text area.

  4. Click on Ok.

Drop to frame

This feature allows you to choose any frame in the call stack during the debugging, and to set the JVM to start again from the selected level in order to rerun a part of your application. To do this, you have to:

  1. Select the stack from where you want to start.

  2. Click on the Drop to Frame button in the toolbar of the bug window.

Adding additional information to be logged

By default, logging is set for production environment. In order to get more log information, you can open the logback.groovy file located in ws/src/main/resources and change some of the following properties to true:

//Jasper logger disabled
logger("net.sf.jasperreports", ERROR, ["CONSOLE"], false)
logger("org.apache.commons.beanutils", ERROR, ["CONSOLE"], false)
logger("org.apache.commons.digester", ERROR, ["CONSOLE"], false)
logger("org.apache.commons.javaflow.bytecode", ERROR, ["CONSOLE"], false)

logger("ch.qos.logback", ERROR, ["CONSOLE"], false)
logger("org.springframework", ERROR, ["FILE", "CONSOLE"], false)
logger("com.mobilize", ERROR, ["FILE", "CONSOLE"], true)
root(ALL, ["FILE", "CONSOLE"])

Trace loading classes

This option is used to print information class loads and unloads. This feature is useful to investigate class leak or old classes (not) getting collected. To enable this feature you have to:

  1. Select Run -> Run Configurations in the left panel

  2. Select Apache Tomcat

  3. Look for Arguments tab

  4. Add -XX:+TraceClassLoading or -XX:+TraceClassUnloading in VM arguments.

Last updated