Search in sources :

Example 11 with IMemento

use of org.eclipse.ui.IMemento in project knime-core by knime.

the class NodeUsageRegistry method saveFrequentNodes.

/**
 * Saves most frequent nodes to XML memento. Called from
 * FavoriteNodesManager#saveFavoriteNodes.
 *
 * @see #loadFrequentNodes(IMemento)
 * @param freqNodes XML memento to save most frequently used nodes to
 */
public static void saveFrequentNodes(final IMemento freqNodes) {
    for (NodeTemplateFrequency nodeFreq : FREQUENCIES.values()) {
        IMemento item = freqNodes.createChild(TAG_FAVORITE);
        item.putString(TAG_NODE_ID, nodeFreq.getNode().getID());
        item.putInteger(TAG_FREQUENCY, nodeFreq.m_frequency);
    }
}
Also used : IMemento(org.eclipse.ui.IMemento)

Example 12 with IMemento

use of org.eclipse.ui.IMemento in project knime-core by knime.

the class FavoriteNodesManager method saveFavoriteNodes.

private void saveFavoriteNodes(final XMLMemento memento) {
    // personal favorites
    IMemento favNodes = memento.createChild(TAG_PERSONAL_FAVS);
    for (IRepositoryObject reposObj : m_favNodes.getChildren()) {
        IMemento item = favNodes.createChild(TAG_FAVORITE);
        item.putString(TAG_NODE_ID, ((NodeTemplate) reposObj).getID());
    }
    // most frequent
    IMemento freqNodes = memento.createChild(TAG_MOST_FREQUENT);
    NodeUsageRegistry.saveFrequentNodes(freqNodes);
    // last used
    IMemento lastUsedNodes = memento.createChild(TAG_LAST_USED);
    NodeUsageRegistry.saveLastUsedNodes(lastUsedNodes);
}
Also used : IMemento(org.eclipse.ui.IMemento) IRepositoryObject(org.knime.workbench.repository.model.IRepositoryObject)

Example 13 with IMemento

use of org.eclipse.ui.IMemento in project yamcs-studio by yamcs.

the class OPIView method init.

@Override
public void init(final IViewSite site, IMemento memento) throws PartInitException {
    super.init(site, memento);
    this.site = site;
    if (debug)
        System.out.println(site.getId() + ":" + site.getSecondaryId() + " opened " + (memento == null ? ", no memento" : "with memento"));
    if (memento == null) {
        memento = findMementoFromPlaceholder();
    }
    if (memento == null) {
        return;
    }
    // Load previously displayed input from memento
    final String factoryID = memento.getString(TAG_FACTORY_ID);
    if (factoryID == null) {
        OPIBuilderPlugin.getLogger().log(Level.WARNING, toString() + " has memento with empty factory ID");
        return;
    }
    final IMemento inputMem = memento.getChild(TAG_INPUT);
    final IElementFactory factory = PlatformUI.getWorkbench().getElementFactory(factoryID);
    if (factory == null)
        throw new PartInitException(NLS.bind("Cannot instantiate input element factory {0} for OPIView", factoryID));
    final IAdaptable element = factory.createElement(inputMem);
    if (!(element instanceof IEditorInput))
        throw new PartInitException("Instead of IEditorInput, " + factoryID + " returned " + element);
    // Set input, but don't persist to memento because we just read it from memento
    setOPIInput((IEditorInput) element, false);
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) IElementFactory(org.eclipse.ui.IElementFactory) PartInitException(org.eclipse.ui.PartInitException) IMemento(org.eclipse.ui.IMemento) IEditorInput(org.eclipse.ui.IEditorInput)

Example 14 with IMemento

use of org.eclipse.ui.IMemento in project yamcs-studio by yamcs.

the class OPIView method findMementoFromPlaceholder.

/**
 * Retrieve memento persisted in MPlaceholder if present.
 *
 * @return memento persisted in the placeholder.
 */
private IMemento findMementoFromPlaceholder() {
    IMemento memento = null;
    MPlaceholder placeholder = findPlaceholder();
    if (placeholder != null) {
        if (placeholder.getPersistedState().containsKey(TAG_MEMENTO)) {
            String mementoString = placeholder.getPersistedState().get(TAG_MEMENTO);
            memento = loadMemento(mementoString);
        }
    }
    return memento;
}
Also used : MPlaceholder(org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder) IMemento(org.eclipse.ui.IMemento)

Example 15 with IMemento

use of org.eclipse.ui.IMemento in project yamcs-studio by yamcs.

the class OPIView method saveState.

@Override
public void saveState(IMemento memento) {
    super.saveState(memento);
    if (input == null)
        return;
    IPersistableElement persistable = input.getPersistable();
    if (persistable != null) {
        /*
             * Store IPersistable of the IEditorInput in a separate section since it could potentially use a tag already
             * used in the parent memento and thus overwrite data.
             */
        IMemento persistableMemento = memento.createChild(TAG_INPUT);
        persistable.saveState(persistableMemento);
        memento.putString(TAG_FACTORY_ID, persistable.getFactoryId());
        // input.getToolTipText());
        if (debug)
            System.out.println(this + " saved to memento");
    }
}
Also used : IPersistableElement(org.eclipse.ui.IPersistableElement) IMemento(org.eclipse.ui.IMemento)

Aggregations

IMemento (org.eclipse.ui.IMemento)29 NodeTemplate (org.knime.workbench.repository.model.NodeTemplate)4 IOException (java.io.IOException)3 StringWriter (java.io.StringWriter)3 WorkbenchException (org.eclipse.ui.WorkbenchException)3 XMLMemento (org.eclipse.ui.XMLMemento)3 IMonitoredMXBeanGroup (org.talend.designer.runtime.visualization.MBean.IMonitoredMXBeanGroup)3 ArrayList (java.util.ArrayList)2 TreeDefinitionNode (org.eclipse.linuxtools.systemtap.structures.TreeDefinitionNode)2 ISearchResultPage (org.eclipse.search.ui.ISearchResultPage)2 JvmCoreException (org.talend.designer.runtime.visualization.JvmCoreException)2 IMBeanServer (org.talend.designer.runtime.visualization.MBean.IMBeanServer)2 FileReader (java.io.FileReader)1 Entry (java.util.Map.Entry)1 IAdaptable (org.eclipse.core.runtime.IAdaptable)1 MPlaceholder (org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder)1 TreeNode (org.eclipse.linuxtools.systemtap.structures.TreeNode)1 IActionBars (org.eclipse.ui.IActionBars)1 IEditorInput (org.eclipse.ui.IEditorInput)1 IElementFactory (org.eclipse.ui.IElementFactory)1