SOURCECODE |
How to... 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.
ToDo's:
- Create a new instance of FormSheetContentCreator
- In the FormSheetContentCreator instance's constructor just call the superclass
- Implement the method
createFormSheetContent(FormSheet fs)
where the Framework uses fs as the FormSheet which the FSCC is added to
- Add the FormSheetContentCreator to the designated FormSheet either by initializing the FormSheet with the FSCC in the constructor or by adding the FSCC with
addContentCreator(FormSheetContentCreator fscc)
In this example we add a SingleTableFormSheet and two buttons to the FormSheet. For more information on the elements, please refer to the tutorial or to the section "Tables" or to "How to change the standard ok or cancel button behaviour".
Uses:
FormSheet FormSheetContentCreator
import sale.*;
import data.Currency;
import data.ooimpl.*;
import data.stdforms.*;
//The best Place for adding Actions to buttons is the FormSheeContentCreator
//It ensures the serialization of the actions so they won't be lost after saving the Shop's status
1
public class DefaultCounterFormCreator extends FormSheetContentCreator {
2
public DefaultCounterFormCreator() {
super();
}
3
//The method you have to implement in order to add the FormSheetContent
public void createFormSheetContent(FormSheet map) {
CountingStockImpl cs = (CountingStockImpl)Shop.getTheShop().getStock("Video-Countingstock");
FormSheet fs = SingleTableFormSheet.create( "Available Videocassettes",
cs,
null,
new OfferTED(false));
map.setComponent(fs.getComponent());
//remove the buttons to be able to add totally new ones
map.removeAllButtons();
//define the FormSheetFormButton with its caption and buttonID
FormSheet.FormButton b = new FormSheet.FormButton("give back", 2, null);
//define a new sale.Action
sale.Action act = new sale.Action() {
public void doAction(SaleProcess p, SalesPoint s) {
s.runProcess(new GiveBackProcess());
}
};
//set the Action at the Button
b.setAction(act);
//add the Button to the FormSheet
map.addButton (b);
//all the steps above as one method call
map.addButton ("rent", 1, new sale.Action() { //a new instance of sale.Action
public void doAction(SaleProcess p, SalesPoint s) { //initialized and implemented at the same time
//the action itself
s.runProcess(new RentProcess());
}
});
}
}
3
Now use either the Constructor FormSheet(String sCaption, FormSheetContentCreator fscc, boolean fWaitResponse)
or the method addContentCreator(FormSheetContentCreator fscc)
of FormSheet to have it display what you defined here