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:
- none
ToDo:
-
Instantiate a subclass of
FormSheetContentCreator. - Add the constructor and call the superclass to inherit its methods.
-
Add the
protected void createFormSheetContent(FormSheet fs)method and therein add/remove your components to theFormSheet. -
Add the
FormSheetContentCreatorto yourFormSheetclass by calling the methodaddContentCreator(FormSheetContentCreatoror 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:
-
Redefine the method
getDefaultFormSheet()in theSalesPointclass. -
Return the
FormSheetyou 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:
-
Redefine the method
getDefaultStatusFormSheet()in theSalesPointclass. -
Return the
FormSheetyou 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:
-
Initialize a new
FormSheet. -
Create a new
FormSheetContentCreatorfor theFormSheetand add it. -
In the
protected void createFormSheetContent(FormSheet fs)method of theFormSheetContentCreatorremove theOK-Button by callingremoveButton(int id). -
Add a new
FormButtonusing theaddButtonmethod. Like here you can shortly add ansale.Actionto the button.
(See also: Define an Action for a Button in a Component). -
Set a new
sale.Actionto theCANCEL-Button by fetching it with thegetButton(int id)method and setting the action withsetAction(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:
-
There are two ways of defining an
Action:-
Create a class implementing the interface
Actionand add thepublic void doAction(SaleProcess process, SalesPoint point) throws Throwablemethod to it. Therein define what to do if the action was called. -
Create an anonymous implementation of
Actionand define what to do if triggered.
-
Create a class implementing the interface
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:
Data Management: Stock | Display: MenuSheet ![]() |
Data Management: Stock