SOURCECODE |
How to... create a DataBasketEntryGrouper
Description:
DataBasketEntryGroupers are important to display the contents of a DataBasket in a FormSheet. Every movement creates a new DataBasketEntry. So it could happen, that one CatalogItem for example has created many CatalogItemDataBasketEntrys in the DataBasket.
(See also: HowTo..use a DataBasketConditon )
If you want to display a DataBasket with DBEntrys of StockItems in a CountingStock, the already implemented CountingStockDBEGrouper will be sufficent.
If you donīt want grouping at all, use the NOPDataBasketEntryGrouper.
If you want to implement your own grouping, follow the instructions.
ToDo's:
- Implement interface DataBasketEntryGrouper.
- Implement method
public boolean canGroup(DataBasketEntry dbe1, DataBasketEntry dbe2)
.
Here you have to decide which DataBasketEntrys should be grouped and which not.
- Implement method
public DataBasketEntry group(DataBasketEntry dbe1, DataBasketEntry dbe2)
Here you have to implement how two DataBasketEntrys merge into one Entry.
Uses:
DataBasketEntryGrouper CountingStockDBEGrouper NOPDataBasketEntryGrouper
import data.DataBasketEntry;
import data.swing.DataBasketEntryGrouper;
1
// Main Class
public class MyDataBasketEntryGrouper implements DataBasketEntryGrouper
{
2
// Method to decide if DBEs should be displayed as one Entry
public boolean canGroup(DataBasketEntry dbe1, DataBasketEntry dbe2)
{
// Entries with same Name(SecondaryKey) and of the same kind(MainKey) could be grouped
return (dbe1.getMainKey().equals(dbe2.getMainKey()) &&
dbe1.getSecondaryKey().equals(dbe2.getSecondaryKey()));
}
3
// Method to group the two given DataBaskeEntries and return the resulting, more general entry.
public DataBasketEntry group(DataBasketEntry dbe1, DataBasketEntry dbe2)
{
// The first item will be displayed for both
return dbe1;
}
}