Class TLcyWorkspaceAddon


public class TLcyWorkspaceAddon extends ALcyPreferencesAddOn

This add-on offers the frontend to load/save workspaces. It adds menu items to load, save, save as and set the default workspace and keeps a list of recently loaded workspaces. The real workspace encoding/decoding work is delegated to ILcyLucyEnv.getWorkspaceManager().

Workspace loading at start-up

When you deliver your Lucy-based application to the end-users, you can ensure that Lucy loads a workspace on start-up. This is done by bundling a workspace file into the resources of your Lucy-based application, and pointing to this workspace file in the configuration file of this add-on:


   TLcyWorkspaceAddon.useFallbackWorkspace=true
   TLcyWorkspaceAddon.fallbackWorkspace=path/to/workspace_file.lws
 

This add-on also provides the end-user the possibility to define his/her own workspace which should be loaded on start-up. For example if the user wants to re-organize the layout of the different panels, it is very convenient if they can store this in a workspace which gets loaded on start-up. This avoids that they have to re-apply those layout changes on each start-up.

The end-user can achieve this by:

  1. Altering the workspace until it meets their requirements
  2. Save the workspace
  3. Use the File | Set startup workspace menu item to indicate the current workspace should be used on start-up

The path to this workspace will be saved in the user preferences, hence being specific to that user. If needed, the user can clear the startup workspace as well through the UI.

The configuration file of this add-on allows to disable the user-defined startup workspace mechanism by setting the following properties (which will also remove the UI entries for the startup workspace):


   TLcyWorkspaceAddon.loadUserDefinedStartupWorkspace=false
   TLcyWorkspaceAddon.setStartupWorkspaceAction.menuBar.insert=false
 

It can be interesting to bundle the fallback workspace into a JAR file. The Lucy developer guide chapter about workspaces explains how to achieve this.

Because this add-on loads a workspace in its plugInto(ILcyLucyEnv) method, all add-ons that participate in workspace management should be loaded already. It is therefore strongly advised to load this add-on after all other add-ons.

Non-file based workspaces

The 'Open workspace' and 'Save workspace (as)' actions provided by this add-on show by default a file chooser to let the user select which workspace to open or where to save the workspace to. The path of the file selected by the user is passed as a string to the ILcyLucyEnv.getWorkspaceManager() which performs the actual encoding/decoding of the workspace. Therefore the ALcyWorkspaceCodec set on the workspace manager must accept those paths. This is for example the case if an instance of TLcyFileWorkspaceCodec is used (the default). If an ALcyWorkspaceCodec is used that does not accept file paths (for example a codec that saves workspace to a database), you have two options:

  • Replace this add-on by a custom add-on.
  • Override the selectWorkspaceDestination(String, Component) and selectWorkspaceSource(Component) methods. This way you can provide your own UI to the user while retaining all other functionality of this add-on. The strings returned by those methods will be passed to the TLcyWorkspaceManager directly. This is illustrated in the samples.lucy.workspace.ChooseFromListWorkspaceAddOn sample class.
    Note that in this case you might have to disable the data source handler of this add-on. Consult the configuration file for more information.

Disabling workspace support

Workspace management might not always be desired. For example if an existing application based on Lucy was made before workspace management was available (v5.3), it would make sense to disable workspace management. This can be done by removing this add-on from the addons.xml file. This will disable the workspace loading at start-up, and remove all the workspace-related entries from the UI.

If you only want to disable workspace loading at start-up but keep the UI elements, you need to load the workspace add-on with a modified configuration file:


   TLcyWorkspaceAddon.useFallbackWorkspace=false
   TLcyWorkspaceAddon.loadUserDefinedStartupWorkspace=false
   # As the user defined workspace is not loaded on start-up, you
   # typically want to remove the corresponding menu entry as well
   TLcyWorkspaceAddon.setStartupWorkspaceAction.menuBar.insert=false
 

Note that when no workspace is loaded at start-up, no map will be shown when Lucy starts. You can fix this by letting the map add-on create a new map on startup. This is achieved by modifying the configuration file of the map add-on.

To create a Lightspeed map on startup, you have to modify the configuration file of the TLcyLspMapAddOn (TLcyLspMapAddOn.cfg) as follows:


   TLcyLspMapAddOn.mapTypesToCreate = default
 

To create a GXY map on startup, you have to modify the configuration file of the TLcyMapAddOn (map_addon.cfg) as follows:


   mapcomponentcount = 1
 

To have a map overview on startup, you have to modify the configuration file of the TLcyMapOverviewAddOn (mapoverview_addon.cfg) as follows:


   map_overview.new_overview_on_startup = true
 
  • Constructor Details

    • TLcyWorkspaceAddon

      public TLcyWorkspaceAddon()
      Default constructor.
  • Method Details

    • plugInto

      public void plugInto(ILcyLucyEnv aLucyEnv)
      Description copied from class: ALcyPreferencesAddOn
      Creates and plugs in the add-on's preferences tool.
      Overrides:
      plugInto in class ALcyPreferencesAddOn
      Parameters:
      aLucyEnv - the Lucy environment to plug into
      See Also:
    • loadWorkspace

      public final void loadWorkspace(String aWorkspaceIdentifier)

      This method is the API equivalent of the user opening a workspace from the UI. Just like the UI action, it will:

      • If there are any pending changes, ask the user whether or not to save them before loading the workspace.
      • Show progress UI during the loading of the workspace.

      This method should be called on the EDT.

      Parameters:
      aWorkspaceIdentifier - The identifier of the workspace. See TLcyWorkspaceManager.decodeWorkspace(String).
      Since:
      2016.1
    • unplugFrom

      public void unplugFrom(ILcyLucyEnv aLucyEnv)
      Description copied from class: ALcyPreferencesAddOn
      Unplugs the add-on's preferences tool.
      Overrides:
      unplugFrom in class ALcyPreferencesAddOn
      Parameters:
      aLucyEnv - the Lucy environment
      See Also:
    • selectWorkspaceDestination

      protected String selectWorkspaceDestination(String aProposedDestination, Component aParentComponent)

      Returns the destination to save the workspace to. This method is called on the Event Dispatch Thread.

      You can override this method if you are for example saving workspaces to a database instead of to a file. Where the file-based implementation of this method will show a file chooser, you could for example show an input dialog showing the already existing workspaces in the dialog and an input field where the user can input a name for the new workspace.

      Since this method is called on the EDT, a typical implementation will show a modal dialog to the user. If you have to perform a long running task, make sure to do it on a background thread. The samples.lucy.workspace.ChooseFromListWorkspaceAddOn sample class illustrates how to do this.

      Note: when overriding this method it might be needed to disable the data source handler of this add-on as well. Consult the configuration file for more information.

      Parameters:
      aProposedDestination - The proposed destination. For example when using the 'File | Save' action, this will be the current path of the workspace. This parameter can be null. For example when using the 'File | Save as' action, the parameter will be null because the user indicated that the workspace must be saved to a new location.
      aParentComponent - The parent component. You can use this argument if you want to show UI to the user.
      Returns:
      The destination to which the workspace must be saved. This string will be passed to the ALcyWorkspaceCodec. Return null to indicate that the saving of the workspace is cancelled.
      Since:
      2015.1
      See Also:
    • selectWorkspaceSource

      protected String selectWorkspaceSource(Component aParentComponent)

      Method which is responsible for letting the user select which workspace to open, and returns a source string for that workspace.

      Since this method is called on the EDT, a typical implementation will show a modal dialog to the user. If you have to perform a long running task, make sure to do it on a background thread. The samples.lucy.workspace.ChooseFromListWorkspaceAddOn sample class illustrates how to do this.

      Note: when overriding this method it might be needed to disable the data source handler of this add-on as well. Consult the configuration file for more information.

      Parameters:
      aParentComponent - The parent component. You can use this argument if you want to show UI to the user.
      Returns:
      the source string representing the workspace file to open, or null when the user cancelled opening of the workspace. This string will be passed to the ALcyWorkspaceCodec.
      Since:
      2015.1
      See Also: