Shared Samples

Build, modify and run workflows on geospatial data using Spatial Modeler SDK. Build complex algorithms or run routine tasks, and build add-ons to ERDAS IMAGINE and GeoMedia.
Showing results for 
Search instead for 
Do you mean 

Client Storage

by Technical Evangelist ‎09-30-2019 02:57 AM - edited ‎09-30-2019 06:22 AM (67 Views)

Abstract

The client storage sample shows different storage options on the client side. 

Bitbucket Link

https://bitbucket.org/HGDN/hgdn_mae/src/master/Desktop/Storage/

Description

MAE Client offers several ways to store information on the client side. In this sample the following storage options are shown:

  • Temporary Storage
  • Session Warehouse
  • Settings Warehouse

Temporary Storage

The StoragePlugin offers one action (addGeometryToStorage) to add a polygon to a temporary storage. The geometry is captured using a GeometryCapture instance. 
The storage is created as TemporaryStorage and is only available during the current session.

 

@Action(actionLocation = ActionLocation.PluginTab.class)
  public void addGeometryToStorage() {
    TemporaryStorage storage = getOrCreateStorage();

    GeometryCaptureListener<Polygon> geometryCaptureListener =
        new GeometryCaptureListener<>() {

          ...

          @Override
          public void onGeometriesCaptured(GeometryCapture source, Stream<Polygon> geometries) {
            storage.getLayer().setVisible(true);

            try {
              storage.add(geometries);
            } catch (StorageException e) {
              Log.getLogger().log(Level.SEVERE, "", e);
            }
          }
        };

    ...
  }

  private TemporaryStorage getOrCreateStorage() {
    if (storage == null) {
      storage = ApplicationContext.getStorages().getTemporaryStorage("MyTemporaryStorage",
          RedlineMapInterpreter.class, STYLE);
    }

    return storage;
  }

When the storage is created, a new layer is added to the legend similar to the redlining or measurement layers. 

 

SessionWarehouse

MAE Client offers a SessionCache to temporarily add values in case they are needed several times during the current session. 

The SessionWarehousePlugin offers one action (addSelectedElementToSession) that adds the id of the active layer and the id of the selected element to the SessionCache so that it might be displayed if the user clicks on showSessionValue.

 

private static final String LAYER = "LastSelectionLayer";
  private static final String ELEMENTID = "LastSelection";

  @Action(actionLocation = ActionLocation.PluginTab.class, activeLayerRequired = true,
      minSelection = 1, maxSelection = 1)
  public void addSelectedElementToSession() {
    ...

    SessionCache.put(LAYER, browser.getActiveLayer().orElseThrow().getId());

    SessionCache.put(ELEMENTID,
        mapSelectionCurator.getSelected().findFirst().orElseThrow().toString());

    SessionValueDialog dialog =
        new SessionValueDialog(SessionCache.get(LAYER), SessionCache.get(ELEMENTID));
    dialog.setVisible(true);
  }

 

SettingsWarehouse

MAE Client offers a SettingWarehouse to persist additional information on the client side so that the information does not get lost between different sessions. SettingWarehouse may only deal with simple datatypes.

The SettingWarehousePlugin offers one action that lets the user decide whether to show some additional user information in a dock panel by clicking on Show/Hide Stored Info or not.

 

public class SettingWarehousePlugin implements Plugin {
  ...

  @Override
  public void onUiReady() {
    SettingWarehouse.put("StoredInfo", "MyUserName");
  }

  @Action(actionLocation = ActionLocation.PluginTab.class)
  public void handleStoredInfo() {
    if (userDock == null) {
      userDock = getUserDock();

      SwingUi.addDock(userDock, DockConstraint.TOP);
    } else {
      SwingUi.removeDock(userDock);
      userDock = null;
    }
  }

  ...
}

 

Overview
Contributors