Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » I want do something before closing a view
I want do something before closing a view [message #542179] Thu, 24 June 2010 07:39 Go to next message
Ricky Ru is currently offline Ricky RuFriend
Messages: 14
Registered: February 2010
Junior Member
Hi friends,

As the title indicates, what should I do for it? I think I should add a listener and implement the close method. But can anyone tell me what the api is?

Thanks
Re: I want do something before closing a view [message #542252 is a reply to message #542179] Thu, 24 June 2010 11:16 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
On 24.06.2010 09:39, Ricky Ru wrote:
> Hi friends,
>
> As the title indicates, what should I do for it? I think I should add a
> listener and implement the close method. But can anyone tell me what the
> api is?

You could use an IPartListener2 and listen for the partClosed
event. Since this is an often-occuring task, You might want
to create a helper class that accepts an IViewPart and does
this for you, see below.

HTH & Greetings from Bremen,

Daniel Krügler


public abstract class PartOpenCloseObserver {

private IPartListener2 listener = new IPartListener2() {

@Override
public void partActivated(IWorkbenchPartReference partRef) {
}

@Override
public void partBroughtToTop(IWorkbenchPartReference partRef) {
}

@Override
public void partClosed(IWorkbenchPartReference partRef) {
if (partRef.getPart(false) == part) {
partRef.getPage().removePartListener(listener);
PartOpenCloseObserver.this.partClosed(part);
}
}

@Override
public void partDeactivated(IWorkbenchPartReference partRef) {
}

@Override
public void partHidden(IWorkbenchPartReference partRef) {
}

@Override
public void partInputChanged(IWorkbenchPartReference partRef) {
}

@Override
public void partOpened(IWorkbenchPartReference partRef) {
if (partRef.getPart(false) == part) {
PartOpenCloseObserver.this.partOpened(part);
}
}

@Override
public void partVisible(IWorkbenchPartReference partRef) {
}

};

private IWorkbenchPart part;

public PartOpenCloseObserver(IViewPart part) {
Assert.isNotNull(part);
this.part = part;
part.getSite().getPage().addPartListener(listener);
}

public PartOpenCloseObserver(IEditorPart part) {
Assert.isNotNull(part);
this.part = part;
part.getSite().getPage().addPartListener(listener);
}

public abstract void partOpened(IWorkbenchPart part);

public abstract void partClosed(IWorkbenchPart part);

}
Re: I want do something before closing a view [message #542630 is a reply to message #542179] Fri, 25 June 2010 13:46 Go to previous messageGo to next message
Christophe Fondacci is currently offline Christophe FondacciFriend
Messages: 95
Registered: July 2009
Location: Paris
Member
Hello Ricky,

If you're sure the view has been created (view controls were created / view had focus), you could simply overload the dispose() method in your view part and add all your "something" work in this method.

Note that this method will not be called if the view was never shown and the user simply clicked the cross without displaying the view, unless you forced view initialization through :
IWorkbenchPage.showView(YourView.VIEW_ID, null, IWorkbenchPage.VIEW_CREATE);


Hope this helps,
Christophe
http://www.nextep-softwares.com
Re: I want do something before closing a view [message #543352 is a reply to message #542630] Tue, 29 June 2010 08:01 Go to previous message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
On 25.06.2010 15:46, Christophe Fondacci wrote:
> Hello Ricky,
>
> If you're sure the view has been created (view controls were created /
> view had focus), you could simply overload the dispose() method in your
> view part and add all your "something" work in this method.

I stumbled several times across the problem, that the ViewPart.dispose()
function is actually called, *after* the controls have been disposed,
which is sometimes too late for some-cleanup work - Therefore I
recommend to listen to an IPartListener2 instead.

Greetings from Bremen,

- Daniel Krügler
Previous Topic:RCP product licence control
Next Topic:[databinding] Example for remove/add Viewer entries
Goto Forum:
  


Current Time: Sun Dec 05 05:57:47 GMT 2021

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

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

Back to the top