Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » Calling viewer.update(element, ...) on a filtered object does not 'unfilter' it.
Calling viewer.update(element, ...) on a filtered object does not 'unfilter' it. [message #485678] Mon, 14 September 2009 12:57
Florian Hackenberger is currently offline Florian HackenbergerFriend
Messages: 123
Registered: July 2009
Senior Member
Hi!

I'm on eclipse 3.4 and I'm using the jface TableViewer. The viewer has a
filter which filters objects if the property 'hidden' is true.
Say we have an element 'test1' which has the property hidden initially set
to true, so the viewer does not display it.
The property changes to false, and we want the viewer to reflect the change
(unhide the element).
According to the docs of StructuredViewer.update(Object, String[]):
* If the viewer has a filter which is affected by a change to one of the
* properties, the element may appear or disappear if the change affects
* whether or not the element is filtered out.
the element should be visible after calling viewer.update(element, new
String[] { "hidden" }), it is still hidden however. The test code is below.
BTW: The filter always returns true for isFilterProperty(...).

Can someone please tell me if I have overlooked something obvious, or point
me to a bug report, if that actually is a bug?

Cheers,
Florian

public class TableViewTest /* extends ViewPart */{
public static final String ID = "test.TableViewTest"; //$NON-NLS-1$

TableViewer viewer;

public class ViewerContent {
public ViewerContent(boolean hidden, String title) {
super();
this.hidden = hidden;
this.title = title;
}
public boolean hidden = false;
public String title;
}

public ViewerContent[] content = new ViewerContent[] {
new ViewerContent(true, "test1"),
new ViewerContent(false, "test2")
};

public void createPartControl(Composite parent) {
Composite comp = new Composite(parent, parent.getStyle());
GridLayoutFactory.swtDefaults().numColumns(1).applyTo(comp);

Button button = new Button(comp, SWT.TOGGLE);
GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true,
false).applyTo(button);
button.setText("show element test1");
button.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
@Override
public void widgetSelected(SelectionEvent e) {
content[0].hidden = !content[0].hidden;
// Does not work (contrary to the docs)
viewer.update(content[0], new String[] { "hidden" });
// Does not work either
viewer.refresh(content[0]);
// Works
viewer.refresh();
}
});

// Define the viewer
viewer = new TableViewer(comp);
GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).grab(true,
true).applyTo(viewer.getControl());

viewer.setContentProvider(new IStructuredContentProvider() {
@Override
public void dispose() {
}
@Override
public void inputChanged(Viewer viewer, Object oldInput,
Object newInput) {
}
@Override
public Object[] getElements(Object inputElement) {
return content;
}
});
viewer.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return ((ViewerContent)element).title;
}
});
viewer.setFilters(new ViewerFilter[] { new ViewerFilter() {
@Override
public boolean isFilterProperty(Object element, String property) {
return true;
}
@Override
public boolean select(Viewer viewer, Object parentElement,
Object element) {
return !((ViewerContent)element).hidden;
}
}});
viewer.setInput(new Object[] {});
}
public void setFocus() {
}
}


--
DI Florian Hackenberger
florian@hackenberger.at
www.hackenberger.at
Previous Topic:Treeviewer losing expand/collapse boxes when jarred
Next Topic:TreeViewer Partial update
Goto Forum:
  


Current Time: Fri Nov 28 20:43:02 GMT 2014

Powered by FUDForum. Page generated in 0.05925 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software