Skip to main content



      Home
Home » Eclipse Projects » Plugin Development Environment (PDE) » close editor when delete occurs
close editor when delete occurs [message #17245] Tue, 19 August 2008 10:14 Go to next message
Eclipse UserFriend
We have a custom view that has a tree explorer of certain files. These can
be used to launch an editor. When someone deletes a file from this tree, we
want the editor to also close. How do I do that? Is it editor changes or
changes to this view?
Re: close editor when delete occurs [message #17296 is a reply to message #17245] Tue, 19 August 2008 18:29 Go to previous message
Eclipse UserFriend
Originally posted by: eclipse-news.rizzoweb.com

Jay Simpson wrote:
> We have a custom view that has a tree explorer of certain files. These can
> be used to launch an editor. When someone deletes a file from this tree, we
> want the editor to also close. How do I do that? Is it editor changes or
> changes to this view?
>
>

What I did was create a specialized IResourceChangeListener instance
that calls
ResourcesPlugin.getWorkspace().addResourceChangeListener(thi s,
IResourceChangeEvent.POST_CHANGE) when it is created. My editor holds
the reference to the listener and disposes it when the editor is disposed.
The listener's resourceChanged() implementation walks the event's delta
looking for removed files and if one of them matches the editor's input
file, the listener closes the editor. See code below.

It is a complex answer to a seemingly simple problem, but I looked
through the Java and plain text editor code and did not find anything
simpler.

Hope this helps,
Eric


public void resourceChanged(IResourceChangeEvent event) {
// Only listening to these.
// if (event.getType() == IResourceDelta.POST_CHANGE)
{
IResourceDelta delta = event.getDelta();
try {
IResourceDeltaVisitor visitor = new IResourceDeltaVisitor() {
public boolean visit(IResourceDelta delta) {
if (delta.getFlags() != IResourceDelta.MARKERS &&
delta.getResource().getType() == IResource.FILE) {
if (delta.getKind() == IResourceDelta.REMOVED) {
IResource resource = delta.getResource();
if (resource.equals(editor.getInputFile())) {
closeEditor();
}
}
// TODO: handle IResourceDelta.CHANGED events by offering
to reload the file
}

return true;
}
};

delta.accept(visitor);
}
catch (CoreException exception) {
SkywayCoreUIPlugin.getDefault().logError("Error tracking resource
change " + event, exception); //$NON-NLS-1$
}
}
}
Re: close editor when delete occurs [message #577098 is a reply to message #17245] Tue, 19 August 2008 18:29 Go to previous message
Eclipse UserFriend
Jay Simpson wrote:
> We have a custom view that has a tree explorer of certain files. These can
> be used to launch an editor. When someone deletes a file from this tree, we
> want the editor to also close. How do I do that? Is it editor changes or
> changes to this view?
>
>

What I did was create a specialized IResourceChangeListener instance
that calls
ResourcesPlugin.getWorkspace().addResourceChangeListener(thi s,
IResourceChangeEvent.POST_CHANGE) when it is created. My editor holds
the reference to the listener and disposes it when the editor is disposed.
The listener's resourceChanged() implementation walks the event's delta
looking for removed files and if one of them matches the editor's input
file, the listener closes the editor. See code below.

It is a complex answer to a seemingly simple problem, but I looked
through the Java and plain text editor code and did not find anything
simpler.

Hope this helps,
Eric


public void resourceChanged(IResourceChangeEvent event) {
// Only listening to these.
// if (event.getType() == IResourceDelta.POST_CHANGE)
{
IResourceDelta delta = event.getDelta();
try {
IResourceDeltaVisitor visitor = new IResourceDeltaVisitor() {
public boolean visit(IResourceDelta delta) {
if (delta.getFlags() != IResourceDelta.MARKERS &&
delta.getResource().getType() == IResource.FILE) {
if (delta.getKind() == IResourceDelta.REMOVED) {
IResource resource = delta.getResource();
if (resource.equals(editor.getInputFile())) {
closeEditor();
}
}
// TODO: handle IResourceDelta.CHANGED events by offering
to reload the file
}

return true;
}
};

delta.accept(visitor);
}
catch (CoreException exception) {
SkywayCoreUIPlugin.getDefault().logError("Error tracking resource
change " + event, exception); //$NON-NLS-1$
}
}
}
Previous Topic:Finding the Plugins directory
Next Topic:Ganymede desparately slow when setting target platform
Goto Forum:
  


Current Time: Thu May 01 23:37:40 EDT 2025

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

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

Back to the top