Can I develop Enabler apps in Java using Eclipse?

Home > FAQ > Can I develop Enabler Apps in Java using Eclipse?

With our new Enabler V4 software - a 100% Java API is now available, allowing clients on non-Windows platforms.

For Enabler V3 and earlier versions - the answer is, "Yes you can". But the solution is Windows ONLY:
It requires the use of an ActiveX COM bridge to work. There are many options for this available some are listed below some are free and some may not do everything

We have tried COM plug-in for Eclipse. We found this worked well with our ActiveX controls and wasn't too hard to use. The rest of this document and example code were prepared using the COM plug-in for Eclipse.

Using the COM plug-in for Eclipse

This is easy to install and comes with samples, check out their website for more on the samples.

Adding ActiveX Controls to a Java Eclipse Solution

The plug-in works by generating two packages for each ActiveX/COM component. Each package must be created separately, each within a separate project. Once you have generated the packages required, you can add them all to your application project (or a separate assembly if you prefer).

The steps required to create the packages are:

  1. Install the COM plugin in Eclipse. Use the "Help" menu and select "Software update".
  2. Create a new project selecting a COM project in the project wizard
  3. After entering a project name you will be prompted to select the type library. The relevant components for Enabler are:
    • ActiveX controls - EnbPumpX2 and EnbSessionX2) these are Registered COM Components.
    • Pump Server (PSRVR) is a Type Library. This is in the Enabler install folder (C:\Enabler\).
  4. Once you have selected the COM component you need to select a generator. Notes:
    • We found the SWTtoCOM generator was suited to the GUI needs of the COM object.
    • We do not recommend using the COM4J generator - because it did not generate the full COM implementation.
  5. Name the package and then click next. On the next page there are some configuration options for the generator. Set "Generate dispatch ids as constants" to YES. This is required in order to call methods on the controls (see below)
  6. Click "Finish" and the package will be generated.
  7. Repeat steps 2 - 6 for all the COM components needed. Then drag and drop the created packages all into the src folder of your main project (or just pick one of the created ones)

Now there should be a project with all the COM components needed. Methods can be used to create an instance of EnbSessionX2 and EnbPumpX2 with GUI components

Eclipse Package Explorer shows created packages

Creating a Session and making it invisible


  EnbSessionX2Composite SessionComposite = new EnbSessionX2Composite(shell, SWT.NONE);
  Session = SessionComposite.getEnbSessionX2Automation();
  SessionComposite.oleShow();
  SessionComposite.setVisible(false);
  

Creating a Pump and assigning variables

  
  EnbPumpX2Composite PumpComposite = new EnbPumpX2Composite(shell, SWT.NONE);
  Pump = PumpComposite.getEnbPumpX2Automation();
  PumpComposite.oleShow();
			
  Pump.setSession(Session);
  Pump.setNumber(int Number);

Unfortunately the generated package does not have very good support for the Enabler API objects (e.g. Delivery, Hose, Grade, and Tank). Some methods return IAutomationObjects and you can't directly cast these to the wrapper object class.

Due to this limitation, members of those objects must accessed via an IAutomationObject using the "getProperty", "setProperty", or "invoke" methods. These methods require the dispatch ID of the object member you want to access. These can be found in the class called I(name_of_object) in the package called (component_name) for example IDelivery contains the dispatch IDs for Delivery and is in (package name).psrvrlib. The help document has example code that shows how to do this.

An example for Pump returning a Delivery and then using Delivery to return the Delivery Type


  Private IAutomationObject Delivery;
  Private Variant DeliveryType;
  
  Delivery = Pump.getCurrentDelivery();
  
  DeliveryType = Delivery.getProperty(IDelivery.DISPID_FUNC_GET_TYPE);
  
  DeliveryType.getInt();

Notes

The Java sample code is provided as a guide only.

GetSummary

We have found that the GetSummary methods do not work correctly through the bridge. However the data returned by these functions is available using the Delivery, Hose and Grade objects.

Sample Code

If you want to use Eclipse and Java to develop your Enabler application we suggest you download our Eclipse Java pumpdemo sample. The sample code is provided to show how you can dynamically create the Pump controls, get delivery details, call methods, and implement event handlers.

EnbOptX

If you are using Enabler V3.0 or later, the EnbOPTX control is also available. You will need to generate this control if you plan to use the OPT interface.

Control Versions

This sample application was created using the Enabler V3.0 ActiveX controls. If you are using an older version of Enabler your ActiveX control may not have some of the methods used in the sample code. For example .QuickAuthorise() and .QuickSaleSelect().

Troubleshooting

Symptom Solution
IAutomation Object causes error when trying to use a method This may be because you are using the wrong method to call that method. Check the type of method you are calling
For example
IDelivery.DISPID_FUNC_GET_TYPE is a GET method
therefore getProperty will be used
IDelivery.DISPID_FUNC_SET_TYPE is a SET method
therefore setProperty will be used
IDelivery.DISPID_FUNC_INV_GETLOCK is an INV method
therefore invoke will be used
Pump shows as not installed This will happen if the session and number haven't been assigned to the pump correctly

 Pump[i].setSession(Session);
 Pump[i].setNumber(int Number);