Search in sources :

Example 1 with IElementFactory

use of org.eclipse.ui.IElementFactory 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)

Aggregations

IAdaptable (org.eclipse.core.runtime.IAdaptable)1 IEditorInput (org.eclipse.ui.IEditorInput)1 IElementFactory (org.eclipse.ui.IElementFactory)1 IMemento (org.eclipse.ui.IMemento)1 PartInitException (org.eclipse.ui.PartInitException)1