/************************************************************** This is the skeleton of a bean that works in Sieve and can communicate with other tools. This class implements only the model; the UI is implemented in TableViewToolCustomizers, which is this class' customizer. By Fernando Das Neves, august 1999. **************************************************************/ /* Set here the package this tool belongs to. It can be any package, but for sluice this is tipically sieve.sluice.view (data filters), sieve.sluice.nuggets (data visualizers), or sieve.sluice.codebook (data readers) */ package sieve.sluice.myGroupOfTools; import sieve.sluice.*; /* * @author your_name_here * @version version_number_here * * Describe the purpose of this bean here */ public class TableViewTool extends DefaultTableView /* This is a convenience class, that gives default behavior for many methods. */ implements TableViewListener /* you need to implement TableViewListener, so you can see other tools */ { /* Default constructor. Needed for bean behavior */ public TableViewTool() { super(null); } /* You can include other optional constructors, like this */ public TableViewTool(TableView source) { super(source); } /* IMPORTANT: * Note there are a number of method in the TableView interface that * we are not implementing in this tool, because we are relying * on the default implementation provided by DefaultTableView. You * have to check wether that default implementation is valid in your case, * and reimplement those method for whose the default behavior is not appropiate */ /** * Returns no more than numberOfRecords records starting * at record number startingAt from * the fields specified in fields. */ public Object[][] get(String[] fields, int startingAt, int numberOfRecords) throws InterchangeException { /* This is the method you will most likely have to redefine. If your tool creates an new view for * other tools, then the behavior to return the proper content has to be here. In this case you * may want to check if you do not have to redefine * - getFieldCount(), * - getRecordCount(), and * - getFieldNames() * You are allowed to throw any InterchangeException if the request is invalid. * * On the other hand, if your tool only plots a TableView, then the default implementation of get() * will be enough, and you will not need to redefine this method. */ } } /* This method is called whenever there is a change in the data source. * If the data source changes completely, then a sourceRemovedViewEvent * is followed by a sourceAddedEvent. */ public void tableViewChanged(TableViewEvent event) { // No need to reset ourselves if this is just a descriptor change if (event instanceof TableViewChangedEvent) { /* This mean the content of the Table have changed, so we will call * updateTool() here. */ updateTool(); super.tableViewChanged(event); // broadcast event down in the flow. /* IMPORTANT: Note that we didn't analyze the cases of receiving SourceAddedEvent * and SourceRemovedEvent. The reason is that DefaultTableView.tableViewChanged() * calls addSourceView() and removeSourceView() for us when those events are received, * so any code to deal with those cases can be inserted in those methods. */ } } /* addSourceView() is called when a new link connects this tool from some * other tool that acts as data source. In this case, addSourceView() is called * instead of sending a sourceViewAdded event. You can use this same method * to implement the behavior for the sourceViewAdded event, and call it * from tableViewChanged(). * Remember that this method can receive source == null. */ public void addSourceView(TableView source) throws TooManySourcesException { /* We call super.addSourceView() first to ensure that the source * is updated before we do anything else. */ super.addSourceView(source); resetTool(); } /* removeSourceView() is called when a link is destroyed, disconnecting this tool * from some other tool that acts as data source. In this case, removeSourceView() * is called instead of sending a sourceViewRemoved event. You can use this same * method to implement the behavior for the sourceViewAdded event, and call it * from tableViewChanged(). */ public void removeSourceView(TableView source) throws TooManySourcesException { /* We call super.addSourceView() first to ensure that the source * is updated before we do anything else. */ super.removeSourceView(source); resetTool(); } /* This method is called every time the tool that feeds us with a TableView * have changed the table it uses. This means that fields and the content * of those fields that we may know are not valid any more. * * To get the data you need to update your tool, you can do * Object[][] data =super.get(super.getFieldNames(),0); * This will return the content of all fields the other tool have visible. * * IMPORTANT: Be sure to be able to return a coherent value * when get() is called at any point in time. */ protected void resetTool() { } /* * This method is internally called by tableViewChanged() every time * the tool that feeds us with a TableView have changed either * the set of field it wants us to see or the range of records. * The total set of fields the remain valid. The difference between this method * and resetTool() is that in updateTool we know the tool that generated the * change is still working with the same table, so if we implement any kind * of caching, that caching is still valid. * * To get the data you need to update your tool, you can do * Object[][] data = super.get(super.getFieldNames(),0); * This will return the content of all fields the other tool has visible. */ protected void updateTool() { } /* * This method is called to obtain the data inside the tableView. * Note that it is possible to ask for certain fields only, or * for a range of records. * There is no need to redefine this method if your tool does * not modify the received data, and only displays it. In that * case, the get() implementation inherited from DefaultTableView * is enough. * * If you look at sieve.sluice.views.DefaultTableView, you will * notice it also implements a get(fieldNames[], startingAt) method. * You do not need to reimplement it, since it does * this.get(fieldNames, startingAt,getRecordCount()-startingAt) * * IMPORTANT: When implementing this method, always try to minimize * data copying. */ public Object[][] get(String[] fieldNames, int startingAt, int howManyRecords) { } }