website stat

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

JAVA:
  1. mainLayout.addView(FirstView.ID, IPageLayout.LEFT, 0.7f, editorArea);
  2. mainLayout.addView(SecondView.ID + ":2", IPageLayout.BOTTOM, 0.5f, FirstView.ID);



Q: Set a shell to be not resizable
A:

JAVA:
  1. 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:

JAVA:
  1. layout.setFixed(false);



Q: How to create a composite that has scrollbars to move the content.
A:

JAVA:
  1. // create the main composite
  2. ScrolledComposite scrolled = new ScrolledComposite(parent, SWT.V_SCROLL);
  3. // build something...
  4. Label text = new Label(scrolled, SWT.NONE);
  5. // ... to put something inside the composite
  6. scrolled.setContent(text);
  7. // compute the size to adjust the bar
  8. scrolled.setSize(text.computeSize(SWT.DEFAULT, SWT.DEFAULT));

Q: How to get the running views
A:

JAVA:
  1. IViewReference[] views =
  2. PlatformUI.getWorkbench().getActiveWorkbenchWindow().
  3. 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;


1 Response to “Eclipse RCP Hints”

  1. Personal Bytes » Blog Archive » Eclipse RCP Hints
    Published at November 2nd, 2005 at 1:14 am

    […] 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. […]

Leave a Comment