Create a Foundation Project

Create a new Foundation Project called busentity3 using a plugin. For this how to we will be using Eclipse and Oracle.

Select the Oracle 10g Database Type and modify the Database URL for your database. Leave the default FParent and FChild entities, we will be creating new ones for the project. Then create new Run profiles for define and clientserver and test that the default application can be defined and run.

For more information on how to do this see the Getting Started with Eclipse How To

Create a New Event Class

Select the common.events package and then select File -> New -> Class.

Name: FSampleEvent (The F is important since it tells Foundation that this is a Foundation business entity).

Superclass: com.foundation.common.FEvent

Check Constructors from Superclass.

Check Inherited abstract methods.

Set the Label, Hint and Icon for the Event

Have the getLabel() method return the text that should go with the icon for the event.

public String getLabel() {
return “Print”;
}

Have the getHint() method return the text for the pop up hint.

public String getHint() {
return “Print out this page”;
}

Add a getIcon() method that will return the Printer icon. You might need to add an import to com.foundation.client.*

public Icon getIcon() {
return FIconsManager.iconPrint;
}

Enable the Event Class

The isEnabled method must return true for a specific case or the button will never be enabled. In this case there must be an object in the business entity for the button to show up.

public boolean isEnabled(IFObject iFObject) {
if (iFObject == null) return false;

FObject fObject = getSelectedFObject(iFObject);

if (fObject == null) return false;

return true;
}

Register the Event with the Class that will Call it

Add getFEventSupported() method to the FParent business entity to add the FSampleEvent to the button bar.

// @see IFObject#getFEventsSupported
public FEventList getFEventsSupported() throws RemoteException {
return new FEventList ( FSampleEvent.class );
}

 

Define and Run the Project

There will now be a printer icon on the button bar of the Parent Maintenance screen whenever a new or existing record is being displayed.

Processing the Event

The next step is to have the Panel process the event.

Create a Custom FormPanel

In order to process the event, a custom FormPanel must be used. A FParentFormPanel class should have been created in the client package. This now needs to be registered with the FParent class as the default FormPanel.

In FParent Comment out the defineFFormPanel() method and add a getFFormPanel() method.

public FFormPanel getFFormPanel(IFConfigurer iFConfigurer) throws Exception {
super.getFFormPanel(iFConfigurer);
return new FParentFormPanel(iFConfigurer);
}

Process the Event

In the process() method of FParentFormPanel add an else if statement for the FSampleEvent. This will open up a message box and return.

public void process(FEvent fEvent) throws Exception {
if (fEvent instanceof FParentEvents) {
IFService iFService = (IFService)FManagerDirectory.getIFManager(FService.class);
FIdentifier fSessionId = FClient.instance().getFSessionId();
FParent fParent = getFObject();
iFService.method1(fSessionId, fParent);
}
else if (fEvent instanceof FSampleEvent) {
FParent fParent = (FParent) getFObject();
int option = JOptionPane.showConfirmDialog(this,
“Do you want to print ” + fParent + ” ?”,
“Print”, JOptionPane.YES_NO_OPTION);
if (option != JOptionPane.YES_OPTION)
return;
}
else {
super.process(fEvent);
}
}

The get() method will return an instance of the current business entity that is being displayed.

Define and Run the Project

Now when a record is displayed the print button will display a message box.

Source Code

This project can be downloaded here. Unzip it into a directory and import it into Eclipse.

Help

For any additional support email support@foundationdms.com