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.
Sandip Chitale 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
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...
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
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);
Bahar Sateli 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.