Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Update of JFace TreeViewer fails
Update of JFace TreeViewer fails [message #329963] Fri, 11 July 2008 13:40 Go to next message
Mathias Zenger is currently offline Mathias ZengerFriend
Messages: 10
Registered: July 2009
Junior Member
Hi,

I have a problem using a JFace TreeViewer in my application. (I am using
Eclipse 3.4 and Instantiation's SWTBuilder). The application shall show
device groups and devices in a tree - just like a file system.

root (empty element. not shown)
|
container
|
-- group1
|
-- group2
|
-- devive1
|
-- device2

When adding new elements to my tree (or removing) the domain object gets
manipulated correctly but the tree shown in the UI remains the same. Here
you can see the code for adding an element and changing their content:

/* removing is similar. both fail!!! */

final Button _btnAddGroup = new Button(_grpDevEditor, SWT.NONE);
_btnAddGroup.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(final SelectionEvent e) {
IStructuredSelection sel =
(IStructuredSelection)_trvDevices.getSelection();
if (sel != null) {
ResourceModel model = (ResourceModel)sel.getFirstElement();
if (model instanceof DeviceGroupModel) {
DeviceGroupModel parent = (DeviceGroupModel)sel.getFirstElement();
if (parent.getParent() == root) {
new DeviceGroupModel(container, _txtName.getText(),
_txtImage.getText());
}
else {
new DeviceGroupModel(parent, _txtName.getText(),
_txtImage.getText());
}
_trvDevices.refresh();
}
}
}
});

/* changing contents works fine!!! */

final Button _btnSave = new Button(_grpDevEditor, SWT.NONE);
_btnSave.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(final SelectionEvent e) {
IStructuredSelection sel =
(IStructuredSelection)_trvDevices.getSelection();
if (sel != null) {
ResourceModel model = (ResourceModel)sel.getFirstElement();
if (model instanceof DeviceModel) {
DeviceModel mod = (DeviceModel)sel.getFirstElement();
mod.setName(_txtName.getText());
mod.setTypeDescription(_txtDescription.getText());
mod.setTypeReference(_txtReference.getText());
mod.setTypeImage(_txtImage.getText());
_trvDevices.refresh();
}
else {
if (model instanceof DeviceGroupModel) {
DeviceGroupModel mod = (DeviceGroupModel)sel.getFirstElement();
mod.setName(_txtName.getText());
mod.setTypeImage(_txtImage.getText());
_trvDevices.refresh();
}
}
}
}
});

Has anybody an idea what I am doing wrong? Is there an event or listener
missing?

Since I am a beginner I did most of the data bindings with the tool. It
also generated the content and label provider classes. As you can imagine
I am a bit lost now.

Thanks for helping! Best regards,
Mathias
Re: Update of JFace TreeViewer fails [message #329969 is a reply to message #329963] Fri, 11 July 2008 14:18 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

The code looks correct. Do you see any exception? If there's an uncaught
exception thrown it should be part of the .metadata/.log or if you
started with -consoleLog in the Eclipse console.

Tom

Mathias schrieb:
> Hi,
>
> I have a problem using a JFace TreeViewer in my application. (I am using
> Eclipse 3.4 and Instantiation's SWTBuilder). The application shall show
> device groups and devices in a tree - just like a file system.
>
> root (empty element. not shown)
> |
> container
> |
> -- group1
> |
> -- group2
> |
> -- devive1
> |
> -- device2
>
> When adding new elements to my tree (or removing) the domain object gets
> manipulated correctly but the tree shown in the UI remains the same.
> Here you can see the code for adding an element and changing their content:
>
> /* removing is similar. both fail!!! */
>
> final Button _btnAddGroup = new Button(_grpDevEditor, SWT.NONE);
> _btnAddGroup.addSelectionListener(new SelectionAdapter() {
> public void widgetSelected(final SelectionEvent e) {
> IStructuredSelection sel =
> (IStructuredSelection)_trvDevices.getSelection();
> if (sel != null) {
> ResourceModel model = (ResourceModel)sel.getFirstElement();
> if (model instanceof DeviceGroupModel) {
> DeviceGroupModel parent =
> (DeviceGroupModel)sel.getFirstElement();
> if (parent.getParent() == root) {
> new DeviceGroupModel(container, _txtName.getText(),
> _txtImage.getText());
> }
> else {
> new DeviceGroupModel(parent, _txtName.getText(),
> _txtImage.getText());
> }
> _trvDevices.refresh();
> }
> }
> }
> });
>
> /* changing contents works fine!!! */
>
> final Button _btnSave = new Button(_grpDevEditor, SWT.NONE);
> _btnSave.addSelectionListener(new SelectionAdapter() {
> public void widgetSelected(final SelectionEvent e) {
> IStructuredSelection sel =
> (IStructuredSelection)_trvDevices.getSelection();
> if (sel != null) {
> ResourceModel model = (ResourceModel)sel.getFirstElement();
> if (model instanceof DeviceModel) {
> DeviceModel mod = (DeviceModel)sel.getFirstElement();
> mod.setName(_txtName.getText());
> mod.setTypeDescription(_txtDescription.getText());
> mod.setTypeReference(_txtReference.getText());
> mod.setTypeImage(_txtImage.getText());
> _trvDevices.refresh();
> }
> else {
> if (model instanceof DeviceGroupModel) {
> DeviceGroupModel mod = (DeviceGroupModel)sel.getFirstElement();
> mod.setName(_txtName.getText());
> mod.setTypeImage(_txtImage.getText());
> _trvDevices.refresh();
> }
> }
> }
> }
> });
>
> Has anybody an idea what I am doing wrong? Is there an event or listener
> missing?
>
> Since I am a beginner I did most of the data bindings with the tool. It
> also generated the content and label provider classes. As you can
> imagine I am a bit lost now.
>
> Thanks for helping! Best regards,
> Mathias
>


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: Update of JFace TreeViewer fails [message #330007 is a reply to message #329969] Sat, 12 July 2008 13:38 Go to previous messageGo to next message
Mathias Zenger is currently offline Mathias ZengerFriend
Messages: 10
Registered: July 2009
Junior Member
Hi Tom,

Thanks for the answer (good to hear that my source doesn't look too bad
:). Unfortunately I am not at my working place right now. But as far as I
remember there was no exception at all. I will check this on Monday anyway.

I was still wondering why the updates of the existing tree elements that I
added as initial data worked fine (save button action). I guess the point
is that the properties that I'm changing fire a property change event and
therefore the tree updates correctly. Somehow I am not shure if there is a
similar event or a listener missing for the changes of my tree elements
(List).

That's the problem when using auto generated code. Could be that there is
an important part missing in my resource model or in my content/label
providers. I will post this source on Monday and hope you'll find the time
to take a look at it, too.

Enjoy the weekend. Regards,
Mathias
Re: Update of JFace TreeViewer fails [message #330009 is a reply to message #330007] Sat, 12 July 2008 14:57 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
To update only labels it is better to use TreeViewer#update() you should
only issue a TreeViewer#refresh() when you have structural changes and
even then it is better to update your model and then call
TreeViewer#add/insert/remove.

If you need to get started with viewers and how they aork take a look
at: http://wiki.eclipse.org/JFaceSnippets

Tom

Mathias schrieb:
> Hi Tom,
>
> Thanks for the answer (good to hear that my source doesn't look too bad
> :). Unfortunately I am not at my working place right now. But as far as
> I remember there was no exception at all. I will check this on Monday
> anyway.
>
> I was still wondering why the updates of the existing tree elements that
> I added as initial data worked fine (save button action). I guess the
> point is that the properties that I'm changing fire a property change
> event and therefore the tree updates correctly. Somehow I am not shure
> if there is a similar event or a listener missing for the changes of my
> tree elements (List).
>
> That's the problem when using auto generated code. Could be that there
> is an important part missing in my resource model or in my content/label
> providers. I will post this source on Monday and hope you'll find the
> time to take a look at it, too.
>
> Enjoy the weekend. Regards,
> Mathias
>


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Previous Topic:How to override the "run" command
Next Topic:What's the difference between "fetchDeferredChildren" and "getChildren"
Goto Forum:
  


Current Time: Sat Nov 09 05:13:46 GMT 2024

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

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

Back to the top