Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Closing a view programmatically
Closing a view programmatically [message #404460] Tue, 11 January 2005 15:22 Go to next message
Marcus Olk is currently offline Marcus OlkFriend
Messages: 130
Registered: July 2009
Senior Member
Quick question: is it true that it is simply impossible to close
a specific view programmatically? I don't mean to hide a view;
I want to close it just like I can close it using the GUI closer
in its title bar.

Cheers,
Marcus
Re: Closing a view programmatically [message #404461 is a reply to message #404460] Tue, 11 January 2005 17:29 Go to previous messageGo to next message
Sandip Chitale is currently offline Sandip ChitaleFriend
Messages: 27
Registered: July 2009
Location: California, USA
Junior Member
See:
/**
* Hides the given view that belongs to the reference, if any.
*
* @param view
* the references whos view is to be hidden
* @since 3.0
*/
public void hideView(IViewReference view);
or
/**
* Hides the given view. The view must belong to this page.
*
* @param view
* the view to hide
*/
public void hideView(IViewPart view);

of org.eclipse.ui.IWorkbenchPage

HTH,
Sandip


"Marcus Olk" <molk@comosoft.com> wrote in message news:cs0quk$ljf$1@www.eclipse.org...
> Quick question: is it true that it is simply impossible to close
> a specific view programmatically? I don't mean to hide a view;
> I want to close it just like I can close it using the GUI closer
> in its title bar.
>
> Cheers,
> Marcus
Re: Closing a view programmatically [message #404472 is a reply to message #404461] Wed, 12 January 2005 10:39 Go to previous messageGo to next message
Marcus Olk is currently offline Marcus OlkFriend
Messages: 130
Registered: July 2009
Senior Member
Sandip,

Sandip Chitale wrote:
> public void hideView(IViewReference view);
> or
> public void hideView(IViewPart view);
>
> HTH,

No, not really:

> "Marcus Olk" <molk@comosoft.com> wrote in message news:cs0quk$ljf$1@www.eclipse.org...
>>a specific view programmatically? I don't mean to hide a view;
>>I want to close it just like I can close it using the GUI closer
>>in its title bar.

That's what I was looking for: I simply want to get rid of
a view programmatically just as if I closed it using
the GUI control.

Problem being: I'd like to close certain views before workbench
shutdown to avoid them being restored in the next session.

If I use hideView() the view gets hidden but not disposed or
what ever it is called in Eclipish. The view seems to exist as
an reference or something and the framework stores its existance
and restores it in the next session.

I'am lacking the words how much time I spend on simply closing
a view... and still I'm not there...

Marcus
Re: Closing a view programmatically [message #404479 is a reply to message #404472] Wed, 12 January 2005 15:59 Go to previous messageGo to next message
Nick Edgar is currently offline Nick EdgarFriend
Messages: 439
Registered: July 2009
Senior Member
No, the hideView API is equivalent to closing it manually.
If the same view is open in another perspective in the same window, the
view instance is kept around, but that is the same behaviour as when
closing it manually.

Nick

Marcus Olk wrote:
> Sandip,
>
> Sandip Chitale wrote:
>
>> public void hideView(IViewReference view);
>> or
>> public void hideView(IViewPart view);
>
> >
>
>> HTH,
>
>
> No, not really:
>
>> "Marcus Olk" <molk@comosoft.com> wrote in message
>> news:cs0quk$ljf$1@www.eclipse.org...
>>
>>> a specific view programmatically? I don't mean to hide a view;
>>> I want to close it just like I can close it using the GUI closer
>>> in its title bar.
>
>
> That's what I was looking for: I simply want to get rid of
> a view programmatically just as if I closed it using
> the GUI control.
>
> Problem being: I'd like to close certain views before workbench
> shutdown to avoid them being restored in the next session.
>
> If I use hideView() the view gets hidden but not disposed or
> what ever it is called in Eclipish. The view seems to exist as
> an reference or something and the framework stores its existance
> and restores it in the next session.
>
> I'am lacking the words how much time I spend on simply closing
> a view... and still I'm not there...
>
> Marcus
Re: Closing a view programmatically [message #405091 is a reply to message #404479] Tue, 18 January 2005 11:11 Go to previous messageGo to next message
Marcus Olk is currently offline Marcus OlkFriend
Messages: 130
Registered: July 2009
Senior Member
Nick,

Nick Edgar wrote:
> No, the hideView API is equivalent to closing it manually.

Thanks for clarifying this. It was my fault. I chose the wrong index
while searching for the views to be closed :/

Maybe the following is of any use for someone
who wants to do something similiar:

/**
* Closes all instances of a given view type.
*
* <p>Searches for all views of a given type in all workbench windows
* and closes them.</p>
*
* @param viewType The view type to close
*
* @see IWorkbenchPage#hideView(org.eclipse.ui.IViewReference)
*/
private static void closeAllViews(final Class viewType)
{
final IWorkbenchWindow[] windows =
PlatformUI.getWorkbench().getWorkbenchWindows();

// for all workbench windows
for (int w = 0; w < windows.length; w++)
{
final IWorkbenchPage[] pages = windows[w].getPages();

// for all workbench pages
// of a given workbench window
for (int p = 0; p < pages.length; p++)
{
final IWorkbenchPage page = pages[p];
final IViewReference[] viewRefs = page.getViewReferences();

// for all view references
// of a given workbench page
// of a given workbench window
for (int v = 0; v < viewRefs.length; v++)
{
final IViewReference viewRef = viewRefs[v];
final IWorkbenchPart viewPart = viewRef.getPart(false);
final Class partType =
(viewPart != null)
? viewPart.getClass()
: null;

if ( viewType == null // == all views
|| viewType.equals(partType))
{
page.hideView(viewRef);
}
}
}
}
}

Using this internal method of a WorkbenchAdvisor subclass it is
possible to close all instances of a given view type,
e.g. before the workbench shuts down:

/**
* @see org.eclipse.ui.application.WorkbenchAdvisor#preShutdown()
*/
public boolean preShutdown()
{
closeAllViews(MyView.class);

return super.preShutdown();
}

fyi,
Marcus
Re: Closing a view programmatically [message #541650 is a reply to message #405091] Mon, 21 June 2010 23:02 Go to previous messageGo to next message
Bahar Sateli is currently offline Bahar SateliFriend
Messages: 19
Registered: May 2010
Location: Canada
Junior Member
Hey Marcus,

Thank you for the code to close a view. I've been searching for this code for hours!!!

My situation is, I want to close the view before Eclipse shuts down. I noticed you mentioned a preShutdown() method. Would you please tell me how and where to use it?

I tried putting your closing code in plug-in activator file's stop() method but didn't work out.

Thanks again,
Bahar
Re: Closing a view programmatically [message #1005013 is a reply to message #541650] Thu, 24 January 2013 10:11 Go to previous message
Prasanth Jonna Vamsi is currently offline Prasanth Jonna VamsiFriend
Messages: 10
Registered: January 2013
Junior Member
Hi All,
If hideview() closes the view, then how can we hide a view and later display the view.
Previous Topic:RCP app on Mac, "Cannot open files in the XYZ format" when app is already running.
Next Topic:Ghost Cells in Eclipse RCP
Goto Forum:
  


Current Time: Fri Apr 26 00:45:16 GMT 2024

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

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

Back to the top