Search code examples
eclipseeclipse-rcpeclipse-luna

Save Perspective Layout in Eclipse 4


We have an pure Eclipse 4 application making use of model-fragments. When starting this application, the default-perspective is loaded and the user has the ability to login and select the perspective he want's to work with. During the startup of the perspective the corresponding database-credentials are setup. Now the user can work in this perspective and even customize the layout of this perspective. After the work is done, the user can exit the application via the 'X' in the top-right or via a command in the menu.

Now the user can start the application again and we can produce 2 different states. First, if we use the -clearPersistetState-Flag, the application start with the default-perspective, but even the customized layout in the other perspectives is reset. Second, if we don't use the flag, the application starts with the last active perspective. Due to the workflow to start with the default-perspective to login/select-perspective and set the DB-credentials, this leads to a large amount of exceptions (because of the not set DB-credentials).

So what am I looking for: I want to save the layout of perspectives made by the user (moved a part from stack A to stack B,...). On startup I want to start ONLY the default-perspective and load the other perspectives after the user-selection.

At the moment I'm stuck with this problem, searching leads mostly to Eclipse 3.X solutions, so I hope for some ideas.

Thanks in advance, Steffen


Solution

  • For Eclipse 3.x, I re-wrote Perspective/PerspectiveRegistry to add support for saving & restoring perspective layout by instance (in your case, by user) rather than by persp_id:

    • Save: Beside persp_id, also including a secondary id to identify different instance of the same perspective.
    • Restore: Load perspective matching both persp_id and secondary (instance) id.
    • Fallback: It is recommended to save a copy with persp_id only. If matching secondary id failed, you can always fall back to the latest one.

    For E4 RCP application, Lars Vogel gives out enough information in his article: Eclipse 4 Model Persistence - Tutorial.

    I create my own ResourceHandler by first copying the implementation from org.eclipse.e4.ui.internal.workbench.ResourceHandler (too difficult to extend it):

    • #save(): save resource with instance id (e.g. including it in output resource file name).
    • #loadMostRecentModel(): use instance id to locate resource (file).
    • Fallback: also keep a copy as fallback.