Search in sources :

Example 1 with Persist

use of org.eclipse.e4.ui.di.Persist in project org.csstudio.display.builder by kasemir.

the class RuntimeViewPart method persist.

/**
 * Persist the view's input "on demand".
 *
 *  <p>Framework only persists to memento on exit,
 *  and only for the currently visible views.
 *
 *  <p>Display info for views in other perspectives
 *  which are hidden on application shutdown will be lost.
 *  By forcing a persist for each view while the app is still running,
 *  each view can be restored when a perspective is later re-activated.
 *
 *  <p>Memento is saved in the
 *  .metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi
 *  inside a "persistedState" element of the E4 model element.
 *
 *  <p>This method places it in the model just as the framework
 *  does by calling saveState() on shutdown,
 *  but allows saving the state at any time.
 */
private void persist() {
    try {
        // Obtain E4 model element for E3 view,
        // based on http://www.vogella.com/tutorials/EclipsePlugIn/article.html#eclipsecontext
        final IEclipseContext context = getViewSite().getService(IEclipseContext.class);
        final MPart part = context.get(MPart.class);
        // Based on org.eclipse.ui.internal.ViewReference#persist():
        // 
        // XML version of memento is written to E4 model.
        // If compatibility layer changes its memento persistence,
        // this will break...
        // $NON-NLS-1$
        final XMLMemento root = XMLMemento.createWriteRoot("view");
        saveState(root);
        final StringWriter writer = new StringWriter();
        root.save(writer);
        part.getPersistedState().put(TAG_MEMENTO, writer.toString());
    } catch (Exception ex) {
        logger.log(Level.WARNING, "Cannot persist " + display_info, ex);
    }
}
Also used : MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) XMLMemento(org.eclipse.ui.XMLMemento) StringWriter(java.io.StringWriter) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) WorkbenchException(org.eclipse.ui.WorkbenchException) PartInitException(org.eclipse.ui.PartInitException)

Example 2 with Persist

use of org.eclipse.e4.ui.di.Persist in project whole by wholeplatform.

the class AbstractE4Part method save.

@Persist
public void save() {
    if (modelInput != null) {
        workspace.removeResourceChangeListener(resourceListener);
        IPersistenceProvider pp = modelInput.getPersistenceProvider();
        try {
            RootFragment rootFragment = (RootFragment) viewer.getContents().getModel();
            modelInput.getPersistenceKit().writeModel(rootFragment.wGetRoot(), pp);
            viewer.getCommandStack().markSaveLocation();
            part.setDirty(false);
        } catch (Exception e) {
        } finally {
            workspace.addResourceChangeListener(resourceListener);
        }
    }
}
Also used : IPersistenceProvider(org.whole.lang.codebase.IPersistenceProvider) RootFragment(org.whole.lang.commons.model.RootFragment) Persist(org.eclipse.e4.ui.di.Persist)

Example 3 with Persist

use of org.eclipse.e4.ui.di.Persist in project yamcs-studio by yamcs.

the class OPIView method persist.

/**
 * Persist the view's input "on demand".
 *
 * <p>
 * To allow saving the memento at any time.
 *
 * <p>
 * Memento is saved in the .metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi inside a "persistedState"
 * element of the E4 model element.
 *
 * <p>
 * This method places it in the model just as the framework does by calling saveState() on shutdown, but allows
 * saving the state at any time.
 */
private void persist() {
    // Obtain E4 model element for E3 view,
    // based on http://www.vogella.com/tutorials/EclipsePlugIn/article.html#eclipsecontext
    final IEclipseContext context = (IEclipseContext) getViewSite().getService(IEclipseContext.class);
    final MPart model = context.get(MPart.class);
    // Based on org.eclipse.ui.internal.ViewReference#persist():
    // 
    // XML version of memento is written to E4 model.
    // If compatibility layer changes its memento persistence,
    // this will break...
    // $NON-NLS-1$
    final XMLMemento root = XMLMemento.createWriteRoot("view");
    saveState(root);
    final StringWriter writer = new StringWriter();
    try {
        root.save(writer);
        model.getPersistedState().put(TAG_MEMENTO, writer.toString());
    } catch (Exception ex) {
        OPIBuilderPlugin.getLogger().log(Level.WARNING, toString() + " failed to persist input", ex);
    }
}
Also used : MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) XMLMemento(org.eclipse.ui.XMLMemento) StringWriter(java.io.StringWriter) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) WorkbenchException(org.eclipse.ui.WorkbenchException) PartInitException(org.eclipse.ui.PartInitException)

Aggregations

StringWriter (java.io.StringWriter)2 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)2 MPart (org.eclipse.e4.ui.model.application.ui.basic.MPart)2 PartInitException (org.eclipse.ui.PartInitException)2 WorkbenchException (org.eclipse.ui.WorkbenchException)2 XMLMemento (org.eclipse.ui.XMLMemento)2 Persist (org.eclipse.e4.ui.di.Persist)1 IPersistenceProvider (org.whole.lang.codebase.IPersistenceProvider)1 RootFragment (org.whole.lang.commons.model.RootFragment)1