Pages

Tuesday, 25 October 2011

Ever thought of running a RCP in Browser ? RAP is here !

I have been hearing a lot in terms of web based version of Eclipse APIs and browser based RCP off late. On googling a bit, I found out that RAP has indeed made it possible to launch the RCP in a web browser.A RAP screencast showing how to convert the RCP Mail Template into a RAP application can be seen at this link - View screencast in new window.
Wait, what is RAP anyway?

RAP stands for Rich Ajax Platform. It is an Eclipse Project that enables Java developers to build browser-based AJAX applications using the full Java libraries, Eclipse APIs and a plug-in architecture. It does so by providing a web-enabled implementation of SWT, JFace and the Workbench.

Although, this experiment sort of works but I am not sure how useful will it be to try and run a HEAVY swt based app in a plain browser. Hope to see much more development happening in this context as one benefit that this is surely going to bring is the freedom from installing a RCP on each client machine.

WAY TO GO RAP.

Quick Access (Ctrl+3) feature added

Quick Access (Ctrl+3) command has been introduced in Eclipse 3.4.  

It allows you to access UI-elements - like Views, Perspectives, Commands, etc. - by just typing their name.
Some usage examples:
  • Open the Navigator View? Ctrl+3, Navi, return
  • Debug Last Launched? Ctrl+3, DLL, return
  • Open the Debug Perspective? Ctrl+3, Perspectives D (Perspectives Debug), return

Tuesday, 26 July 2011

Remove Unwanted Perspectives from your RCP

While creating a RCP recently I noticed that I had dependencies on some of the Eclipse JDT and Plugin development features and due to this the RCP was showing some really unnecessary entries in the Perspective selection bar.

On debugging a little I found out the concept of pre-defined perspectives (those which come as a result of contributions from Plugin.xml of any contributing plugin) and it is indeed pain to remove those perspectives from any RCP.

Here is the snippet that I hacked to get rid of those predefined perspectives -

Call the  removeUnWantedPerspectives() (attached below) method from postWindowCreate() method of your RCP's WorkbenchWindowAdvisor extension class -

     public static final String[] IGNORE_PERSPECTIVES = new String[] {
            "org.eclipse.birt.report.designer.ui.ReportPerspective", "org.eclipse.debug.ui.DebugPerspective",
            "org.eclipse.jdt.ui.JavaPerspective", "org.eclipse.jdt.ui.JavaHierarchyPerspective",
            "org.eclipse.jdt.ui.JavaBrowsingPerspective", "org.eclipse.mylyn.tasks.ui.perspectives.planning",
            "org.eclipse.pde.ui.PDEPerspective", "org.eclipse.team.cvs.ui.cvsPerspective",
            "org.eclipse.ui.resourcePerspective", };

    /**
     * Removes the unwanted perspectives from your RCP application
     */
    private void removeUnWantedPerspectives() {
        IPerspectiveRegistry perspectiveRegistry = PlatformUI.getWorkbench().getPerspectiveRegistry();
        IPerspectiveDescriptor[] perspectiveDescriptors = perspectiveRegistry.getPerspectives();
        List ignoredPerspectives = Arrays.asList(GenericConstants.IGNORE_PERSPECTIVES);
        List removePerspectiveDesc = new ArrayList();
       
        // Add the perspective descriptors with the matching perspective ids to the list
        for (IPerspectiveDescriptor perspectiveDescriptor : perspectiveDescriptors) {
            if(ignoredPerspectives.contains(perspectiveDescriptor.getId())) {
                removePerspectiveDesc.add(perspectiveDescriptor);
            }
        }
       
        // If the list is non-empty then remove all such perspectives from the IExtensionChangeHandler
        if(perspectiveRegistry instanceof IExtensionChangeHandler && !removePerspectiveDesc.isEmpty()) {
            IExtensionChangeHandler extChgHandler = (IExtensionChangeHandler) perspectiveRegistry;
            extChgHandler.removeExtension(null, removePerspectiveDesc.toArray());
        }
    }