Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » New TreeItem is not updating in UI
New TreeItem is not updating in UI [message #898279] Thu, 26 July 2012 06:25 Go to next message
preeti baviskar is currently offline preeti baviskarFriend
Messages: 11
Registered: July 2012
Junior Member
Hi.
I am using Tree with multiple column and inside that using TreeViewer.

Tree treeSWComponent = new Tree(swComponentComp, SWT.BORDER);

TreeViewer tree_viewer=new TreeViewer(treeSWComponent);

TreeColumn trclmnSwcomponent = new TreeColumn(treeSWComponent, SWT.NONE);
trclmnSwcomponent.setText("Component");

TreeColumn trclmnDataType = new TreeColumn(treeSWComponent, SWT.NONE);
trclmnDataType.setText("Data Type");

TreeColumn trclmnSignalMapping = new TreeColumn(treeSWComponent, SWT.NONE);
trclmnSignalMapping.setText("Signal Mapping");

Here, I am providing the functionality on child TreeItem to create TreeItem but its not showing on UI. But actually its child getting created.
Re: New TreeItem is not updating in UI [message #898299 is a reply to message #898279] Thu, 26 July 2012 07:10 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Hi,

I really don't understand what are you trying to do. Could you please post more code and better explanation of your problem?

Also when working with the JFace TreeViewer you should rarely create the SWT's TreeColumn and TreeItem on your own.
Re: New TreeItem is not updating in UI [message #898335 is a reply to message #898299] Thu, 26 July 2012 08:47 Go to previous messageGo to next message
preeti baviskar is currently offline preeti baviskarFriend
Messages: 11
Registered: July 2012
Junior Member
Actually I want one tree with multiple column. I am using TreeViewer since I wanted to use contentProvider and tree to show it in multiple column. (as in attachment)

So on popup menu selection, I am trying to create child item on Tree. It's getting created but when expand it its not showing anything.
  • Attachment: snippet.JPG
    (Size: 28.92KB, Downloaded 243 times)
Re: New TreeItem is not updating in UI [message #898349 is a reply to message #898335] Thu, 26 July 2012 09:11 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
How do you create the child?
Re: New TreeItem is not updating in UI [message #898355 is a reply to message #898349] Thu, 26 July 2012 09:18 Go to previous messageGo to next message
preeti baviskar is currently offline preeti baviskarFriend
Messages: 11
Registered: July 2012
Junior Member
TreeItem[] selectedItem = tree.getSelection();
TreeItem ti = new TreeItem(selectedItem[0], SWT.None);
ti.setText("Some Text");
Re: New TreeItem is not updating in UI [message #898366 is a reply to message #898355] Thu, 26 July 2012 09:32 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Well, this is because the TreeViwer uses the model and the content provider for creating the TreeItems.

When you expand an item it asks the content provider for children of the expanded model element.
Since you didn't add the new model element to the model structure, the TreeViewer removed your manually created TreeItem.

Basically, when working with a TreeViewer, you should make structural changes on the input model and then
call TreeViewer.refresh(the child's parent model object) to create new child items.

try to look at this article
http://www.eclipse.org/articles/Article-TreeViewer/TreeViewerArticle.htm
Re: New TreeItem is not updating in UI [message #898372 is a reply to message #898366] Thu, 26 July 2012 09:42 Go to previous messageGo to next message
preeti baviskar is currently offline preeti baviskarFriend
Messages: 11
Registered: July 2012
Junior Member
Hi,
Thanks for reply.
But how to tell content provider about model change. In
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) method, what are the old and new Input?
Re: New TreeItem is not updating in UI [message #898377 is a reply to message #898372] Thu, 26 July 2012 09:50 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Read the article. It's really useful.

The inputChanged is useful when your model is somehow observable and you would listen for it's changes.

Do the following things:
- create the model object representing the child you would like to add in the tree
- call treeViewer.refresh(parent model of the new created child model)

the viewer then asks your content provider for children of the parent model, so you have something like this
@Override
public Object[] getChildren(Object parentElement) {
    if (parentElement instanceof ParentModel) {
	return ((ParentModel) parentElement).getChildren();
    }
    other parent model types get their own children ...
}
Re: New TreeItem is not updating in UI [message #898461 is a reply to message #898377] Thu, 26 July 2012 12:25 Go to previous message
preeti baviskar is currently offline preeti baviskarFriend
Messages: 11
Registered: July 2012
Junior Member
Thanks for your valuable reply.
Previous Topic:Deferred content provider
Next Topic:Reset DeferredTreeContentManager
Goto Forum:
  


Current Time: Tue Mar 19 11:19:31 GMT 2024

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

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

Back to the top