Update of JFace TreeViewer fails [message #329963] |
Fri, 11 July 2008 09:40  |
Eclipse User |
|
|
|
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 10:18   |
Eclipse User |
|
|
|
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 #330009 is a reply to message #330007] |
Sat, 12 July 2008 10:57  |
Eclipse User |
|
|
|
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
------------------------------------------------------------ --------
|
|
|
Powered by
FUDForum. Page generated in 0.02856 seconds