Reputation: 77
I am trying to allow my user to search through a table of information, dynamically hiding/showing results that contain the search. I have the hiding part down, and it works well, but I'm having trouble, showing the table item again, once the search criteria is changed.
Here is my hide code:
searchField.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent arg0) {
modified = true;
for (int i = 0; i < table.getItems().length; i++) {
if (!(table.getItem(i).getText(2)
.contains(searchField.getText()))) {
table.getItem(i).dispose();
}
}
if ("".equals(searchField.getText())) {
modified = false;
//where I would want to un-hide items
}
}
});
Upvotes: 0
Views: 777
Reputation: 1
You have probably to save the data from TableItem
into collection before you call dispose
. Then when you search again you could check that collection and if matches are found, then insert back into Table
by creating new TableItem
.
Upvotes: 0
Reputation: 3304
Isn't it better to actually operate with some kind of a table model and JFace bindings, rather, then do it like that? And yes, disposing is not hiding. You should probably remove the item from the table.
Upvotes: 0
Reputation: 36894
Looking at your code, it seems you try to hide the item
by calling dispose()
. If you dispose a widget, it is gone for good. You cannot get it back.
If you want to unhide it again, will have to create a new item at the position of the previously hidden one with the same content.
Upvotes: 0