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