Create a Foundation Project

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

Select the SQLServer 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

Creating a Business Association

Create two new Classes

Select the common.classes package and then select File -> New -> Class. Name the new class FSample1. (The F is important since it tells Foundation that this is a Foundation business entity). Check Constructors from Superclass.

Do the same for FSample2.

Configure Each Class as an Independent Business Entity

Follow in instructions in How to Create a Business Entity and setup both FSample1 and FSample2 as business entities in their own right.

FSample1:

package com.foundation.busentity2.common.classes;

import java.rmi.RemoteException;

import com.foundation.client.FFormPanel;
import com.foundation.client.FTablePanel;
import com.foundation.common.classes.FThing;
import com.foundation.common.domains.FString;

public final class FSample1 extends FThing<FSample1> {

public FString fParentName = new FString() {
public String getLabel() { return “Parent Name”; }
public String getHint() { return “The name of the sample”; }
};

public FSample1() throws RemoteException {
super();
// TODO Auto-generated constructor stub
}

// @see FObject#defineFFormPanel
public void defineFFormPanel(FFormPanel<FSample1> fFormPanel) throws Exception {
super.defineFFormPanel(fFormPanel);
fFormPanel.addFControls(FSample1.class);
}

//@see FObject#defineFListPanel

public void defineFListPanel(FTablePanel<FSample1> fTablePanel) throws Exception {

super.defineFListPanel(fTablePanel);

fTablePanel.addFColumns(FSample1.class);

}

// @see FObject#getInitAry

protected Object[][] getInitAry() throws RemoteException {

return new Object[][] {

{ fCode, fDescription, fParentName },

{ “parent1”, “parent1”, “one” },

{ “parent2”, “parent2”, “two” },

{ “parent3”, “parent3”, “three” },

};

}

}

FSample2:

package com.foundation.busentity2.common.classes;

import java.rmi.RemoteException;

import com.foundation.client.FFormPanel;
import com.foundation.client.FTablePanel;
import com.foundation.common.classes.FThing;
import com.foundation.common.domains.FString;

public final class FSample2 extends FThing<FSample2> {

public FString fChildName = new FString() {
public String getLabel() { return “Child Name”; }
public String getHint() { return “The name of the sample”; }
};

public FSample2() throws RemoteException {
super();
// TODO Auto-generated constructor stub
}

// @see FObject#defineFFormPanel
public void defineFFormPanel(FFormPanel<FSample2> fFormPanel) throws Exception {
super.defineFFormPanel(fFormPanel);
fFormPanel.addFControls(FSample2.class);
}

//@see FObject#defineFListPanel

public void defineFListPanel(FTablePanel<FSample2> fTablePanel) throws Exception {

super.defineFListPanel(fTablePanel);

fTablePanel.addFColumns(FSample2.class);

}

// @see FObject#getInitAry

protected Object[][] getInitAry() throws RemoteException {

return new Object[][] {

{ fCode, fDescription, fChildName },

{ “child1”, “child1”, “one” },

{ “child2”, “child2”, “two” },

{ “child3”, “child3”, “three” },

};

}

}

Add them both to the MenuBar class:

FMenu fMenuTables = new FMenu(“~Tables”, “Tables within the system”);
addFObjectMenuItems(fMenuTables, FParent.class);
addFObjectMenuItems(fMenuTables, FChild.class);
addFObjectMenuItems(fMenuTables, FSample1.class);
addFObjectMenuItems(fMenuTables, FSample2.class);
add(fMenuTables);

Define and Run the Application

Define and Run the application to make sure that both the FSample1 and FSample2 business entities are correctly defined.

Create a Business Association

Select the common.associations package and then select File -> New -> Class. Name the new class FSample1Sample2s. (The F is important since it tells Foundation that this is a Foundation business entity, the order states that Sample1 is the parent and Sample2 is the child, the s at the end just signifies that there can be more than 1 child records). Add com.foundation.common.FOneToManyAssociation as the Superclass. Uncheck Constructors from Superclass and check Inherited abstract methods.

Add the Association Type

Add a getType() method to return a Relation, see Section 3.5 Defining a Business Association in the Developers Guide for more information on the different types of associations and what they do.

public FAssociation.Type getType() {
return FAssociation.Type.Relation;
}

Set the From Class

Add FSample1 as the From class as it will be the parent entity in this relationship.

public Class<FSample1> getFromClass() {

return FSample1.class;

}

Set the getFromHint() method to return something meaningful about the relationship.

Set the To Class

Add FSample2 as the To class as it will be the child entity in this relationship.

public Class<FSample2> getToClass() {

return FSample2.class;

}

Set the getToHint() method to return something meaningful about the relationship.

Create a Reference to the Parent in the Child Class

Create a reference to FSample1 in FSample2 class:

public FRef<FSample1> fSample1Ref = new FRef<FSample1>() {
public String getLabel() { return “Sample1”; }
public Class<FSample1> getParentFObjectClass() { return FSample1.class; }
public Class<FSample1Sample2s> getFAssociationClass() { return FSample1Sample2s.class; }
public String getHint() { return “The Sample1 of this child”; }
};

Create a List of Children in the Parent Class

Create a list of FSample2’s in the FSample1 class:

public FList<FSample2> fSample2s = new FList<FSample2>(FSample2.class) {
public String getLabel() { return “Sample2”; }
public Class<FSample1Sample2s> getFAssociationClass() { return FSample1Sample2s.class; }
public String getHint() { return “The Sample2s of this parent”; }
};

Define and Run the Application

Define and Run the application.

Since we defined the relationship as a Relation Sample1 and Sample2 entities can live on their own. They can be associated and disassociated without affecting the actual records themselves.

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.