HowTo's - Display: FormSheet

Create a FormSheet

Description:
Although it is quite easy to initialize and display a FormSheet, it is a bit difficult to describe how to do it because of the vast opportunities to display them and the many possibilities to use the FormSheets and combine them with Components or even JComponents.
The first thing you should do before you create your own FormSheet is to consult the framework API and take a closer look at FormSheet. There you will find all methods and of course the subClasses of FormSheet, like the LogOnForm, the MsgForm or the TableForms, which are all specialized FormSheets of great use.
Talking about the elements, every FormSheet needs a caption, which is normally defined by calling the constructor and at least some JComponents to display. These can be put together either by a FormSheetContentCreator or by creating and overwriting methods within a new FormSheet instance before or using it's methods during runtime.
It is though recommended to use the ContentCreator as shown in this example, for it is able to serialize the Components and all their properities, esp. their behaviour, which will be lost if you just use FormSheet methods and serialize the Shop's status.

Used classes:

Related topics:

ToDo:

  1. Instantiate a subclass of FormSheetContentCreator.
  2. Add the constructor and call the superclass to inherit its methods.
  3. Add the protected void createFormSheetContent(FormSheet fs) method and therein add/remove your components to the FormSheet.
  4. Add the FormSheetContentCreator to your FormSheet class by calling the method addContentCreator(FormSheetContentCreator or by initializing in the constructor.

Example Source Code:

FormSheetContentCreator class:

1
public class DisplayFormSheetContentCreator extends FormSheetContentCreator
{
			
    2
    public DisplayFormSheetContentCreator()
    {
        super();
    }
			
    3
    protected void createFormSheetContent(FormSheet fs)
    {
        // add/remove your components here
        fs.removeAllButtons();
        fs.addButton("TutorialButton", 1, new ArchitectureCustomAction());
    }
}
		

Class that uses a FormSheet:

4
// adding the FormSheetContentCreator in FormSheet constructor
        FormSheet fs = new FormSheet("DisplayFormSheet",
                new DisplayFormSheetContentCreator(),
                false);
			
// adding the FormSheetContentCreator by using the addContentCreator method
        SingleTableFormSheet fs = SingleTableFormSheet.create(
                "DisplayFormSheet",
                catalog,
                uigate);
        fs.addContentCreator(new DisplayFormSheetContentCreator());
		

Back to:


Define a FormSheet for a SalesPoint

Description:
The recommended way to define a FormSheet for a SalesPoint is to redefine the method getDefaultFormSheet() of your Salespoint instance, which is used by the Framework to resolve the FormSheet which shall be displayed at that SalesPoint. You may also add a FormSheet during runtime by using the method setFormSheet(SaleProcess sp, FormSheet fs). As you can see, this method is also used to add a SalesProcess to the SalesPoint, which itself is able to display FormSheets.
This example describes how to add a FormSheet to the SalesPoint, while the FormSheet itself should be assembled in a FormSheetContentCreator.

Used classes:

Related topics:

ToDo:

  1. Redefine the method getDefaultFormSheet() in the SalesPoint class.
  2. Return the FormSheet you want to use.

Example Source Code:

public class DisplaySalesPoint extends SalesPoint
{
    public DisplaySalesPoint(String sName)
    {
        super(sName);
    }
			
    1
    protected FormSheet getDefaultFormSheet()
    {
        2
        return new FormSheet("DefaultFormSheet", 
                new DisplayFormSheetContentCreator(), false);
    }
}
		

Back to:


Define a StatusFormSheet for a SalesPoint

Description:
SalesPoints are being displayed in a separate window but also have a StatusDisplay at the Shop, which is the TabbedPane in the Shop's Frame, labled the name of the SalesPoint. By bringing it on top, it shows what is defined as the StatusDisplay in your SalesPoint instance and also adds the Menu defined as StatusMenuSheet in the SalesPoint instance to the Shop's MenuSheet. By default, both, the StatusFormSheet and the StatusMenuSheet are empty.
Feel free to use the StatusDisplay and MenuSheet, which are equally handled to the DefaultFormSheet and the DefaultMenuSheet except that due to the strong division of the Shop and it's SalesPoints it is not possible to have processes running on it. You may trigger a Processes on it, but they will always be displayed by the SalesPoint's window. Therefor a more suitable name would be "Statical Display". For further information on Processes refer to the section "Processes".
This example describes how to define a FormSheet as the SalesPoint's StatusFormSheet, while the FormSheet itself should be assembled in a FormSheetContentCreator.

Used classes:

Related topics:

ToDo:

  1. Redefine the method getDefaultStatusFormSheet() in the SalesPoint class.
  2. Return the FormSheet you want to use.

Example Source Code:

public class DisplaySalesPoint extends SalesPoint
{
    public DisplaySalesPoint(String sName)
    {
        super(sName);
    }
			
    1
    protected FormSheet getDefaultStatusFormSheet()
    {
        2
        return new FormSheet("StatusFormSheet",
                new DisplayFormSheetContentCreator(), false);
}
		

Back to:


Change the standard OK or CANCEL button behaviour

Description:
A FormSheet initially has two buttons, one labeled "ok" and one with "cancel" on it. But they don't do anything by default, so you have to define their behaviour. There are mainly three ways to define the behaviour of the buttons. One is to create your own FormSheet and implement the methods ok() and cancel() and the other one is to remove the buttons and add your own ones with a FormSheetContentCreator. The second one is more commonly used, because it is less effort to add two buttons instead of creating lots of new FormSheets just to define the behaviour of a single click on a button.
The third one is almost as common but due to the lack of influence on the button's look and feel less used. It's because here you only set an action to the standard button by resolving it with getButton(int id) and using setAction(Action action) on it. The button's ids are stored as static int in the FormSheet, where BTNID_CANCEL stands for the cancel button and BTNID_OK for the ok button.
In order to make the behaviour serializable you have to define it within a FormSheetContentCreator. Otherwise the information will be lost after loading. It is also possible to alter the buttons design and caption when adding new ones.

Used classes:

Related topics:

ToDo:

  1. Initialize a new FormSheet.
  2. Create a new FormSheetContentCreator for the FormSheet and add it.
  3. In the protected void createFormSheetContent(FormSheet fs) method of the FormSheetContentCreator remove the OK-Button by calling removeButton(int id).
  4. Add a new FormButton using the addButton method. Like here you can shortly add an sale.Action to the button.
    (See also: Define an Action for a Button in a Component).
  5. Set a new sale.Action to the CANCEL-Button by fetching it with the getButton(int id) method and setting the action with setAction(Action).
    (See also: Define an Action for a Button in a Component).

Example Source Code:

class where FormSheet is set:

 
        1
        FormSheet sheet = new FormSheet("DisplaySheet", null);
			
	2
        sheet.addContentCreator(new DisplayFormSheetContentCreator());
		

FormSheetContentCreator class:

 
2
public class DisplayFormSheetContentCreator extends FormSheetContentCreator
{
			
    3
    protected void createFormSheetContent(FormSheet fs)
    {
        fs.removeButton(FormSheet.BTNID_OK);
			
    4
        fs.addButton("Ok", 102, new DisplayCustomAction());
			
    5
        fs.getButton(FormSheet.BTNID_CANCEL).setAction(new DisplayCustomAction());
			
    }
}
		

Back to:


Define an Action for a Button in a Component

Description:
The reason for adding buttons to your application is of course to let the user interact with it.
By default, buttons don't have any functions, so you have to add a sale.Action to the button either by the method setAction(Action aAction) provided by the button or by already initializing the button with an action.
Remember to put all this into a FormSheetContentCreator in order to have the Actions serialized as you save the Shop's status. Otherwise all the information will be lost after loading and the buttons will be useless.

Used classes:

Related topics:

ToDo:

  1. There are two ways of defining an Action:
    1. Create a class implementing the interface Action and add the public void doAction(SaleProcess process, SalesPoint point) throws Throwable method to it. Therein define what to do if the action was called.
    2. Create an anonymous implementation of Action and define what to do if triggered.

Example Source Code:

 
1 a
public class DisplayCustomAction implements Action
{
			
    public void doAction(SaleProcess process, SalesPoint point) throws Throwable
    {
    // define what shall be done when triggering the action
        point.runProcess(new DisplaySaleProcess("SampleProcess"));
    }
}
			
1 b
public class DisplaySalesPoint extends SalesPoint
{
			
    protected FormSheet getDefaultFormSheet()
    {
			
        FormSheet fs = new FormSheet("FormSheet", null);
        fs.getButton(FormSheet.BTNID_OK).setAction(
                new Action()
                {
                    public void doAction(SaleProcess process, SalesPoint point) throws Throwable
                    {
                        // define what shall be done when triggering the action
                        point.runProcess(new DisplaySaleProcess("SampleProcess"));
                    }
                });
    }
        

Back to:


previous Data Management: StockDisplay: MenuSheet next


Valid HTML 4.01!