Search in sources :

Example 1 with AppInstance

use of org.phoebus.framework.spi.AppInstance in project phoebus by ControlSystemStudio.

the class MementoHelper method saveDockItem.

/**
 * Save state of a DockItem
 *
 *  <p>Store the application name, optionally the resource (input),
 *  and then allow the application itself to store details.
 *
 *  @param memento
 *  @param item
 */
private static void saveDockItem(final MementoTree memento, final DockItem item) {
    final AppInstance application = item.getApplication();
    if (application == null || application.isTransient())
        return;
    final MementoTree item_memento = memento.getChild(item.getID());
    item_memento.setString(DockItem.KEY_APPLICATION, application.getAppDescriptor().getName());
    if (item instanceof DockItemWithInput) {
        final URI input = ((DockItemWithInput) item).getInput();
        if (input != null)
            item_memento.setString(INPUT_URI, input.toString());
    }
    try {
        application.save(item_memento);
    } catch (Throwable ex) {
        logger.log(Level.SEVERE, "Application " + application.getAppDescriptor().getDisplayName() + " memento error", ex);
    }
}
Also used : AppInstance(org.phoebus.framework.spi.AppInstance) MementoTree(org.phoebus.framework.persistence.MementoTree) XMLMementoTree(org.phoebus.framework.persistence.XMLMementoTree) DockItemWithInput(org.phoebus.ui.docking.DockItemWithInput) URI(java.net.URI)

Example 2 with AppInstance

use of org.phoebus.framework.spi.AppInstance in project phoebus by ControlSystemStudio.

the class MementoHelper method restoreApplication.

private static void restoreApplication(final MementoTree item_memento, final DockPane pane, final AppDescriptor app) {
    DockPane.setActiveDockPane(pane);
    final AppInstance instance;
    if (app instanceof AppResourceDescriptor) {
        final AppResourceDescriptor app_res = (AppResourceDescriptor) app;
        final String input = item_memento.getString(INPUT_URI).orElse(null);
        instance = input == null ? app_res.create() : app_res.create(URI.create(input));
    } else
        instance = app.create();
    instance.restore(item_memento);
}
Also used : AppInstance(org.phoebus.framework.spi.AppInstance) AppResourceDescriptor(org.phoebus.framework.spi.AppResourceDescriptor)

Aggregations

AppInstance (org.phoebus.framework.spi.AppInstance)2 URI (java.net.URI)1 MementoTree (org.phoebus.framework.persistence.MementoTree)1 XMLMementoTree (org.phoebus.framework.persistence.XMLMementoTree)1 AppResourceDescriptor (org.phoebus.framework.spi.AppResourceDescriptor)1 DockItemWithInput (org.phoebus.ui.docking.DockItemWithInput)1