Eclipse RCP Hints
I'm developing and deploying an Eclipse RCP application and albeit being an excelent plataform for your Java application, it has a learning curve that I consider steep. So, during the development I'll be posting here some hints to do pretty basic stuff but that takes some time (and I didn't find everything on Google) to figure out how to do.
Q: How to stack views (ie, putting one view over the other on a perspective)
A: Draw the second view relative to the first one, instead of relative to the main composite/editorArea. Example
-
mainLayout.addView(FirstView.ID, IPageLayout.LEFT, 0.7f, editorArea);
-
mainLayout.addView(SecondView.ID + ":2", IPageLayout.BOTTOM, 0.5f, FirstView.ID);
Q: Set a shell to be not resizable
A:
-
sShell = new Shell(Display.getCurrent(), SWT.CLOSE);
Q: Add perspective shortcuts to the perspectiveBar.
A: http://dev.eclipse.org/newslists/news.eclipse.platform.rcp/msg07277.html
Q: Allow views to be minimizable or maximizable.
A: When setting up the perspective on
createInitialLayout(IPageLayout layout), do the following:
-
layout.setFixed(false);
Q: How to create a composite that has scrollbars to move the content.
A:
-
// create the main composite
-
ScrolledComposite scrolled = new ScrolledComposite(parent, SWT.V_SCROLL);
-
// build something...
-
// ... to put something inside the composite
-
scrolled.setContent(text);
-
// compute the size to adjust the bar
-
scrolled.setSize(text.computeSize(SWT.DEFAULT, SWT.DEFAULT));
Q: How to get the running views
A:
-
IViewReference[] views =
-
PlatformUI.getWorkbench().getActiveWorkbenchWindow().
-
getActivePage().getViewReferences();
And perform a cycle to search for the view that matches your criteria. views[i] can be casted to ViewPart and you can obtain is ID by doing ((ViewPart) views[i]).ID;




[…] I’ll be collecting here some Eclipse RCP hints whenever I come across them. It’s a really nice plataform to use but it definitely gives some headaches when you’re trying to deploy your application with it for the first time. […]