1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.ui.workbench;
14 import java.util.ArrayList;
15 import java.util.List;
17 import org.eclipse.core.runtime.IAdaptable;
18 import org.eclipse.ui.IElementFactory;
19 import org.eclipse.ui.IMemento;
20 import org.simantics.utils.ui.ErrorLogger;
21 import org.simantics.utils.ui.workbench.StringMemento;
24 * Factory for restoring a <code>ResourceEditorInput2</code>. The stored
25 * representation of a <code>ResourceEditorInput2</code> remembers a reference
26 * to the input resource, which is a string ID, a model URI and an <a
27 * href="https://www.simantics.org/wiki/index.php/Terminology#R">RVI</a>.
30 * The workbench will automatically create instances of this class as required.
31 * It is not intended to be instantiated or subclassed by the client.
34 public class ResourceEditorInputFactory2 implements IElementFactory {
36 * Factory id. The workbench plug-in registers a factory by this name
37 * with the "org.eclipse.ui.elementFactories" extension point.
39 private static final String ID_FACTORY = "org.simantics.ui.workbench.resourceEditorInputFactory2"; //$NON-NLS-1$
43 public static final String TAG_RESOURCE_ID = ResourceEditorInputFactory.TAG_RESOURCE_ID; //$NON-NLS-1$
47 public static final String TAG_EDITOR_ID = ResourceEditorInputFactory.TAG_EDITOR_ID; //$NON-NLS-1$
52 public static final String TAG_MODEL_ID = "modelId";
57 public static final String TAG_RVI = "rvi";
59 /** Tag ID for node that contains external data */
60 public static final String TAG_EXTERNAL_MEMENTO_ID = "external"; //$NON-NLS-1$
63 * Creates a new factory.
65 public ResourceEditorInputFactory2() {
69 * Method declared on IElementFactory.
72 public IAdaptable createElement(IMemento memento) {
73 // Get the resource id array.
74 IMemento[] children = memento.getChildren(TAG_RESOURCE_ID);
75 if (children.length != 1)
78 List<String> ids = new ArrayList<String>();
79 for (IMemento child : children)
80 ids.add(child.getTextData());
82 String editorId = memento.getString(TAG_EDITOR_ID);
83 String modelId = memento.getString(TAG_MODEL_ID);
84 String rvi = memento.getString(TAG_RVI);
87 ResourceEditorInput2 result = new ResourceEditorInput2(editorId, ids.iterator().next(), modelId, rvi);
89 // Read external persistent memento
90 String externalMementoStr = memento.getString(TAG_EXTERNAL_MEMENTO_ID);
91 if (externalMementoStr != null) {
92 StringMemento sm = new StringMemento(externalMementoStr);
93 sm.writeToMemento(result.getPersistentStore());
96 } catch (NumberFormatException e) {
98 } catch (IllegalArgumentException e) {
99 ErrorLogger.defaultLogError(e);
105 * Returns the element factory id for this class.
107 * @return the element factory id
109 public static String getFactoryId() {