Global Layouts

Global saving and restoring is an operation in which all applications running on a user's desktop are saved to a named layout which can later be restored.

Saving a Global Layout

The Layouts API can be accessed through glue.layouts().

To save a global layout, use the save() method specifying a name for the layout. Note that if a layout with that name already exists, it will be replaced. If a name is not specified, a random name will be generated.

CompletionStage<Void> layout = glue.layouts().save(options -> options
        .withName("Name of Layout")

Restoring a Global Layout

To restore a global layout, use the restore() method:

LayoutRestoreOptions restoreOptions = LayoutRestoreOptions.builder("LayoutToRestore").build();
CompletionStage<Void> restore = glue.layouts().restore(restoreOptions);

Managing Layouts

Listing Layouts

To get a collection of all layouts, use the list() method:

Collection<Layout> layouts = glue.layouts().list();

Exporting Layouts

To export all layouts for the current user, use the exportLayouts() method:

CompletionStage<Collection<Layout>> exportedLayouts = glue.layouts().exportLayouts();

Importing Layouts

You can import collections of layouts by either merging them with the existing ones, or replacing the existing ones. Use the importLayouts() method by passing a collection of layouts and import mode (MERGE or REPLACE):

CompletionStage<Void> importLayouts = glue.layouts().importLayouts(Collections.emptyList(), LayoutImportMode.REPLACE);

Removing Layouts

To remove a layout, use the delete() method and specify the type and name of the layout to remove. The method returns a CompletionStage<Void> which completes when the layout has been deleted:

glue.layouts().delete(LayoutType.GLOBAL, "Name of Layout");

Saving Custom Data

Applications can store custom data in a saved layout. When the layout is restored, the custom data is also restored and returned to the applications. Currently, the custom data can only be the window context. When the layout is restored, the context of the window in the layout will also be restored if it has been saved previously.

Note that saving large volumes of custom data as window context (e.g., thousands of lines of table data) can lead to significant delays when saving a layout. A layout usually contains several (in some cases - many) applications and/or Workspaces (which can also contain many apps) and if one or more of the apps saves large amounts of context data each time a layout is saved, this will significantly slow down the saving process. The methods for saving custom context work best with smaller amounts of data. If your application needs to save large amounts of data, you have to think about how to design this process better - for instance, you may store IDs, indices, etc., as context data, save the actual data to a database and when you restore the layout, fetch the data using the data IDs saved as window context.

To save custom data, applications can subscribe for layout save requests using the onSave() method. The callback passed as an argument will be invoked when a layout save is requested. The callback must return a Map<String, Object> containing pairs of context property names and their values:

Map<String, Object> context = new HashMap<>();
context.put("gridWidth", 420);
context.put("gridHeight", 42);

glue.layouts().onSave(() -> context);