Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Hiding and restoring a view in RCP
Hiding and restoring a view in RCP [message #1005350] Fri, 25 January 2013 01:36 Go to next message
Prasanth Jonna Vamsi is currently offline Prasanth Jonna Vamsi
Messages: 10
Registered: January 2013
Junior Member
I have 4 views in my perspective. I need to hide a view and restore it on.

But what i inferred is eclipse is closing the view on the call of hideView() and showView is creating a new view. But i need to just hide and show the view as it works for "View - > Console / View -> error log " in eclipse.

My sample code

IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
String viewIdToToggle = HBinningView.ID;
IViewReference viewToToggle = activePage.findViewReference(viewIdToToggle);
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getShell();
if (!isChecked()) {

activePage.hideView(viewToToggle);


} else {
try {
activePage.showView(viewIdToToggle);
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Re: Hiding and restoring a view in RCP [message #1005457 is a reply to message #1005350] Fri, 25 January 2013 14:18 Go to previous messageGo to next message
John Steele is currently offline John Steele
Messages: 49
Registered: January 2010
Member
Hmmm... Sounds fishy. I just tested your code by placing a break point at the beginning of the createPartControl(Composite parent) method of the View, and it's only called once when it's initially created.

From that point forward createPartControl(Composite parent) is never called again; indicating it's not re-creating the view per activePage.showView(viewIdToToggle) call.

I put another break point in the dispose() method of the View, and sure enough, it's only called once when the platform is shutdown. Again, indicating the view is only disposed once.

Is this a trick question? Or am I misinterpreting the question?

[Updated on: Fri, 25 January 2013 14:20]

Report message to a moderator

Re: Hiding and restoring a view in RCP [message #1005641 is a reply to message #1005457] Mon, 28 January 2013 01:15 Go to previous messageGo to next message
Prasanth Jonna Vamsi is currently offline Prasanth Jonna Vamsi
Messages: 10
Registered: January 2013
Junior Member
I think you haven' called activePage.hideView(viewToToggle); . If just showview() is called, createPartControl() will not be called.
Try calling activePage.hideView(viewToToggle); and then activePage.showView(viewIdToToggle); . Now a new view is getting created for me. You can find that createPartControl() being called again..

Thanks
Prasanth
Re: Hiding and restoring a view in RCP [message #1005646 is a reply to message #1005641] Mon, 28 January 2013 02:54 Go to previous messageGo to next message
John Steele is currently offline John Steele
Messages: 49
Registered: January 2010
Member
I'm seriously only going to entertain this one more time, so give me a minute to run a quick test.
Re: Hiding and restoring a view in RCP [message #1005647 is a reply to message #1005646] Mon, 28 January 2013 03:05 Go to previous messageGo to next message
John Steele is currently offline John Steele
Messages: 49
Registered: January 2010
Member
Interesting, now it's disposing each time I hide it. Let me dig further.
Re: Hiding and restoring a view in RCP [message #1005650 is a reply to message #1005647] Mon, 28 January 2013 04:02 Go to previous messageGo to next message
John Steele is currently offline John Steele
Messages: 49
Registered: January 2010
Member
Okay, sorry it took so long. For some reason when I tried this the other day it wasn't disposing or re-instantiating the view each time I closed/reopened it. I don't know what I was doing differently than now, but in any case, I think this is what you're looking for:

if (!open) {
	IViewPart view = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(TestView.ID);
	PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().activate(view);
} else {
	IViewPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(TestView.ID);
	IWorkbenchPartReference ref = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getReference(part);
	PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().setPartState(ref, IWorkbenchPage.STATE_MINIMIZED);
}
open = !open;
Re: Hiding and restoring a view in RCP [message #1005656 is a reply to message #1005650] Mon, 28 January 2013 05:17 Go to previous messageGo to next message
Prasanth Jonna Vamsi is currently offline Prasanth Jonna Vamsi
Messages: 10
Registered: January 2013
Junior Member
I even tried this one too . But problem in my case is I have two views separated by tabs. [If i click on one tab it shows 1 view and another tab, it shows other view ] Now if you minimize , it minimizes the whole view rather than that particular tab.
Re: Hiding and restoring a view in RCP [message #1005659 is a reply to message #1005656] Mon, 28 January 2013 05:27 Go to previous messageGo to next message
Prasanth Jonna Vamsi is currently offline Prasanth Jonna Vamsi
Messages: 10
Registered: January 2013
Junior Member
I need something similar to the console view in eclipse. I can close the console window and then select the console from View -> console, and same contents are retained [and note its a tab ]
Re: Hiding and restoring a view in RCP [message #1005666 is a reply to message #1005659] Mon, 28 January 2013 07:27 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5326
Registered: July 2009
Senior Member
Did you tested if console view is not also disposed but it remebers it's
state?

One more thing to remember with this is that: Of course Eclipse will
dispose views when they are hidden. A reason why one is not can be that
you have multiple perspectives open and the view is shown in multiple ones.

Tom

Am 28.01.13 06:27, schrieb Prasanth Jonna Vamsi:
> I need something similar to the console view in eclipse. I can close the
> console window and then select the console from View -> console, and
> same contents are retained [and note its a tab ]
Re: Hiding and restoring a view in RCP [message #1005701 is a reply to message #1005656] Mon, 28 January 2013 10:34 Go to previous message
John Steele is currently offline John Steele
Messages: 49
Registered: January 2010
Member
I see, if I'm understanding this correctly, if you toggle the view when the two views are within the same Folder the entire Folder is being minimized. I didn't have this problem because I put the view that I was minimizing in its own Folder within the perspective, so the view performing the minimizing action doesn't also get minimized.
j
Prasanth Jonna Vamsi wrote on Mon, 28 January 2013 00:17
I even tried this one too . But problem in my case is I have two views separated by tabs. [If i click on one tab it shows 1 view and another tab, it shows other view ] Now if you minimize , it minimizes the whole view rather than that particular tab.

Previous Topic:Enable/disable command handlers depending on command parameter
Next Topic:Cheatsheet: async action problem
Goto Forum:
  


Current Time: Thu Sep 18 18:02:57 GMT 2014

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

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