I don’t care what kind of item it is as long as it has the property I need. But in any case, the Container Interface puts pretty strict rules on what it contains, quote:
All Items in the Container must include the same number of Properties
*
* All Items in the Container must include the same Property ID sets (see
* Item.getItemPropertyIds()).
*
* all Properties in the Items corresponding to the same Property ID must
* have the same data type.
*
* All Items within a container are uniquely identified by their non-null
* ids
Here is one class, an item holding its own properties which get ‘wired’ (hopefully) to their viewer.
public class ThumbnailItem extends PropertysetItem{
StringProperty location = new StringProperty();
StringProperty type = new StringProperty();
StringProperty value = new StringProperty();
static public final String LID = "location";
static public final String TID = "type";
static public final String VID = "value";
public ThumbnailItem(String atype, String alocation, String avalue){
super();
id = atype+alocation;
type.setValue(atype);
location.setValue(alocation);
value.setValue(avalue);
addItemProperty( LID, location); // only using location as reference
addItemProperty( TID, type);
addItemProperty( VID, value);
}
....
I create an instance of this, put it in a collection, then read it right back using the item as ID.
[code]
thumitem = new ThumbnailItem( child.getStringType(), child.getLocation(), value);
if( thItems.addItem( thumitem ) == null ) // ID is the item
log.error(“makeItems”,"Could not add item " + thumitem.getID());
//debug
for(int index=0;index<thItems.size();index++){
Object itemId = thItems.getIdByIndex(index); // get an ID == the item
Item vitem = thItems.getItem( itemId ); // <<<<<<<<<<<<<<<<<<< this alternative does not work
// what I get returned is a IndexededContainer.IndexContainerItem holding the correct index
// but when I get to typeValue, it holds null
//Item vitem = (Item)itemId; // <<<<<<<<<<<<<<<<<<<<<<<<<<<< this alternative works
Property prop = vitem.getItemProperty(ThumbnailItem.LID);
String typeValue = (String)prop.getValue();
System.err.println("typeValue " + typeValue);
}
[/code]
What am I doing wrong?
I want my collections to bind to tables, etc and work as expected.
As far as I can see, if I use Pojos instead, they are not bound for update, so not suitable without rebinding.