Home » Eclipse Projects » Rich Client Platform (RCP) » Using show view within the perspective creation
Using show view within the perspective creation [message #842722] |
Thu, 12 April 2012 15:10 |
abadamcd1 abadamcd1 Messages: 40 Registered: December 2011 |
Member |
|
|
I keep getting a null return value when trying to get the active workbench page inside my perspective's createInitialLayout function.
Doesn't matter if I use getPages or getActivePage. Is there a way to get the active page during the perspective setup? I need to have the active page because I need to create views with a secondary ID on startup, which seemingly can only be done with the page.showView() function.
Here's my code
public void createInitialLayout(IPageLayout layout) {
layout.setEditorAreaVisible(false);
layout.setFixed(true);
String editorArea = layout.getEditorArea();
IFolderLayout mainFolder = layout.createFolder(MAIN_FOLDER_ID, IPageLayout.LEFT,
1.0f, editorArea);
mainFolder.addView(View2.ID);
IFolderLayout networkFolder = layout.createFolder(NETWORK_FOLDER_ID,
IPageLayout.LEFT, 0.15F, MAIN_FOLDER_ID);
networkFolder.addPlaceholder(View.ID + ":*");
IWorkbench wb = PlatformUI.getWorkbench();
IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
IWorkbenchPage page = win.getPages()[0];
try {
page.showView(View.ID, "1", IWorkbenchPage.VIEW_VISIBLE);
page.showView(View.ID, "2", IWorkbenchPage.VIEW_VISIBLE);
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
EDIT
So I've been able to retrieve the active workbench window if I put my code int a syncExec command. However, I still can't get it to return any pages.
//networkFolder.addView(View.ID);
final Display disp = PlatformUI.getWorkbench().getDisplay();
disp.syncExec(new Runnable(){
public void run(){
if(!disp.isDisposed()){
IWorkbench wb = PlatformUI.getWorkbench();
System.out.println(wb.getWorkbenchWindowCount());
IWorkbenchWindow win = wb.getWorkbenchWindows()[0];
IWorkbenchPage[] pages = win.getPages();
System.out.println("pages:" + pages.length);
/*try {
page.showView(View.ID, "1", IWorkbenchPage.VIEW_VISIBLE);
page.showView(View.ID, "2", IWorkbenchPage.VIEW_VISIBLE);
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}*/
}
}
});
[Updated on: Thu, 12 April 2012 19:04] Report message to a moderator
|
|
| | | | | | | | | | | | | | | | | | |
Re: Using show view within the perspective creation [message #845899 is a reply to message #842722] |
Sun, 15 April 2012 14:24 |
Wim Jongman Messages: 423 Registered: July 2009 |
Senior Member |
|
|
Hi Crypt,
You are obvioulsy too early. Try to add a listener to the workbenchwindow.
Try a page listener.
Regards,
Wim
> I keep getting a null return value when trying to get the active workbench
page inside my perspective's createInitialLayout function.
>
> Doesn't matter if I use getPages or getActivePage. Is there a way to get
the active page during the perspective setup? I need to have the active page
because I need to create views with a secondary ID on startup, which
seemingly can only be done with the page.showView() function.
>
> Here's my code
>
> public void createInitialLayout(IPageLayout layout) {
> layout.setEditorAreaVisible(false);
> layout.setFixed(true);
>
> String editorArea = layout.getEditorArea();
>
> IFolderLayout mainFolder = layout.createFolder(MAIN_FOLDER_ID,
IPageLayout.LEFT,
> 1.0f, editorArea);
> mainFolder.addView(View2.ID);
>
> IFolderLayout networkFolder = layout.createFolder(NETWORK_FOLDER_ID,
> IPageLayout.LEFT, 0.15F, MAIN_FOLDER_ID);
>
> networkFolder.addPlaceholder(View.ID + ":*");
>
> IWorkbench wb = PlatformUI.getWorkbench();
> IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
> IWorkbenchPage page = win.getPages()[0];
>
> try {
> page.showView(View.ID, "1", IWorkbenchPage.VIEW_VISIBLE);
> page.showView(View.ID, "2", IWorkbenchPage.VIEW_VISIBLE);
> } catch (PartInitException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>
> }
|
|
|
Goto Forum:
Current Time: Thu Sep 26 02:20:21 GMT 2024
Powered by FUDForum. Page generated in 0.06168 seconds
|