Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Detecting TreeViewer content change
Detecting TreeViewer content change [message #315705] Mon, 21 May 2007 14:38 Go to next message
Eclipse UserFriend
Originally posted by: balu_amburayath.stercomm.com

I have implemented two custom views (both are objects of TreeViewer). One
view displays one set of resources(folders) of a project while the other
displays the remaining set of resources (folders) of the same project.

A custom action (context menu) on one view displays a menu to create files
and folders to that project. Once a resource is added, I reload the entire
tree to reflect the changes.

Question:
How do I detect the tree contents of the first View has changed so that I
can refresh the contents in the second view?

I have implemented selection listener as below. But I am not sure how to
determine if the contents of the first has changed or not.

Any help is appreciated (could not find this type of discussion in the
groups)

Thanks in advance.

listener = new ISelectionListener() {
public void selectionChanged(IWorkbenchPart part, ISelection sel)
{
if (!(sel instanceof IStructuredSelection))
return;
IStructuredSelection ss = (IStructuredSelection) sel;
Object o = ss.getFirstElement();
if (o instanceof MyFirstView)
//Do something
}
};
Re: Detecting TreeViewer content change [message #315706 is a reply to message #315705] Mon, 21 May 2007 15:20 Go to previous messageGo to next message
Eclipse UserFriend
The only one who knows that is your model. Viewers responsibility is to
represent your model. Having said that the databinding-framework part of
3.3 is a framework designed to help you track model changes. On the
other hand normally your model fires PropertyChangeEvents when it
changes its internal structure and it is fairly simple for you implement
this feature if you are familiar with Beans in Java and how to are working.

Tom

BA schrieb:
> I have implemented two custom views (both are objects of TreeViewer).
> One view displays one set of resources(folders) of a project while the
> other displays the remaining set of resources (folders) of the same
> project.
>
> A custom action (context menu) on one view displays a menu to create
> files and folders to that project. Once a resource is added, I reload
> the entire tree to reflect the changes.
>
> Question:
> How do I detect the tree contents of the first View has changed so that
> I can refresh the contents in the second view?
>
> I have implemented selection listener as below. But I am not sure how to
> determine if the contents of the first has changed or not.
>
> Any help is appreciated (could not find this type of discussion in the
> groups)
>
> Thanks in advance.
>
> listener = new ISelectionListener() {
> public void selectionChanged(IWorkbenchPart part,
> ISelection sel) { if (!(sel
> instanceof IStructuredSelection))
> return;
> IStructuredSelection ss = (IStructuredSelection) sel;
> Object o = ss.getFirstElement();
> if (o instanceof MyFirstView)
> //Do something
> }
> };
>
Re: Detecting TreeViewer content change [message #315721 is a reply to message #315706] Tue, 22 May 2007 08:15 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: balu_amburayath.stercomm.com

Thank you. Property change seems to be a good option to try.

Let me extend the question a little more. What if my view wants to listen
to changes made through other out of the box views such as Navigator or
Package Explorer?

Basically what I want is to listen to all views who might allow users to
make changes to projects such as adding new files, folders etc. If my view
has any of those projects open, I want to refresh and show the changes.

This is very similar to how communication works between Package Explr and
Navigator views. If some change happens in one, the other one gets
automatically reflected.

Regards.
Re: Detecting TreeViewer content change [message #315763 is a reply to message #315721] Tue, 22 May 2007 13:46 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: lamont_gilbert.rigidsoftware.com

On Tue, 22 May 2007 12:15:04 +0000, BA wrote:

> Thank you. Property change seems to be a good option to try.
>
> Let me extend the question a little more. What if my view wants to listen
> to changes made through other out of the box views such as Navigator or
> Package Explorer?
>
> Basically what I want is to listen to all views who might allow users to
> make changes to projects such as adding new files, folders etc. If my view
> has any of those projects open, I want to refresh and show the changes.

Thats why you dont listen to the view. There could be any number of them.
If you listen to the model (project in this case) then you catch those
changes.

>
> This is very similar to how communication works between Package Explr
> and Navigator views. If some change happens in one, the other one gets
> automatically reflected.
>
> Regards.

Yes, but the event happens because the model changes, not because the
view's representation of the model changes. So listen to the model.
Re: Detecting TreeViewer content change [message #315775 is a reply to message #315763] Tue, 22 May 2007 16:30 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: balu_amburayath.stercomm.com

Thank you. I understand the point fully.

Is there any snippet that demonstrates how to listent to a project (which
is the model in this case) change? Or if there is any suggestion on the
approach for listening, that will help too.

In other words, what is the property I should listen to detect this?

Thanks for the help.
Re: Detecting TreeViewer content change [message #315791 is a reply to message #315775] Wed, 23 May 2007 03:39 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: se04353.fh-hagenberg.at

BA wrote:

> Thank you. I understand the point fully.

> Is there any snippet that demonstrates how to listent to a project (which
> is the model in this case) change? Or if there is any suggestion on the
> approach for listening, that will help too.

> In other words, what is the property I should listen to detect this?

> Thanks for the help.

Try it like this:

your Model has a method to add/remove listeners in
ArrayList<IModelListener>

some more methods you might need:

public static Model getInstance() {
if (instance == null) {
instance = new Model(); // create var (e.g.new ...)
// seperate this two, or you might get troubles with refresh
instance.createModel(); // fill (e.g.add project)
}
return instance;
}

protected void modelChanged() {
for (Iterator iter = listeners.iterator(); iter.hasNext();) {
IModelListener listener = (IModelListener) iter.next();
listener.modelChanged();
}
}

now you have your Class Project
in a method were you change something in a project
public void change or add XYZ(...) {
vector.add(xyz);
Model.getInstance().modelChanged();
}

you can add your views as listener with
Model.getInstance().addListener(this);
and the view needs to implement interface IModelListener;

=> standard concept for listeners, something like this:
public interface IModelListener {
public void modelChanged();
}

hope you got an idea how to implement it

tom
Re: Detecting TreeViewer content change [message #315807 is a reply to message #315791] Wed, 23 May 2007 10:22 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: balu_amburayath.stercomm.com

Thanks for painstakenly explining this. I guess one crucial point is still
not clear to me.

A user may add a resource such as Project, folder, file etc through any
view such as Package Explorer, Navigator View etc. These actions will
result in changes to the underlying file system (for example, adding a
folder from the View, will create a new folder in the file system).

The part that is not clear is how do I detect such changes that happen to
the file system that occured through external means?

Once I know a change to a folder or file or project has taken place, I can
notify all listeners accordingly inside my model class.

Or am I missing something else here?

Regards.
Re: Detecting TreeViewer content change [message #315809 is a reply to message #315807] Wed, 23 May 2007 10:27 Go to previous messageGo to next message
Eclipse UserFriend
ResourcesPlugin.getWorkspace().addResourceChangeListener(thi s);


BA schrieb:
> Thanks for painstakenly explining this. I guess one crucial point is
> still not clear to me.
>
> A user may add a resource such as Project, folder, file etc through any
> view such as Package Explorer, Navigator View etc. These actions will
> result in changes to the underlying file system (for example, adding a
> folder from the View, will create a new folder in the file system).
>
> The part that is not clear is how do I detect such changes that happen
> to the file system that occured through external means?
>
> Once I know a change to a folder or file or project has taken place, I
> can notify all listeners accordingly inside my model class.
>
> Or am I missing something else here?
>
> Regards.
>
Re: Detecting TreeViewer content change [message #315839 is a reply to message #315809] Wed, 23 May 2007 16:31 Go to previous message
Eclipse UserFriend
Originally posted by: balu_amburayath.stercomm.com

Thanks.

With these pieces of info in hand, I implemented a model class that
listens to ResourceChanges and accordingly notifies the listeners of my
model appropriately.

During Run time, when a project is created through a view (package
explorer), I am able to get notification inside the Model class, but when
my listeners access my model data, iterate through the list of projects
and accesses MEMBERS of the newly created project, I get

exception "org.eclipse.core.internal.resources.ResourceException: The
resource tree is locked for modifications."

I am doing project.isAccessible() check before iteration, but the error
continues.

I need to get the list of members in order to display on the TreeView.

Is there any way to get around this other than actually doing a File IO
operation that hits the file system directly?

Regards.
Previous Topic:Accessing ContentProvider from Extension Point
Next Topic:Using developped plugins in a Runtime Workbench
Goto Forum:
  


Current Time: Tue Jul 22 09:13:17 EDT 2025

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

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

Back to the top