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;
25 * Factory for restoring a <code>ResourceEditorInput</code>.
26 * The stored representation of a <code>ResourceEditorInput</code> remembers
27 * a reference to the input resource, which is a string ID.
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 ResourceEditorInputFactory 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.resourceEditorInputFactory"; //$NON-NLS-1$
43 public static final String TAG_RESOURCE_ID = "resourceId"; //$NON-NLS-1$
47 public static final String TAG_EDITOR_ID = "editorId"; //$NON-NLS-1$
49 /** Tag ID for node that contains external data */
50 public static final String TAG_EXTERNAL_MEMENTO_ID = "external"; //$NON-NLS-1$
53 * Creates a new factory.
55 public ResourceEditorInputFactory() {
59 * Method declared on IElementFactory.
61 public IAdaptable createElement(IMemento memento) {
62 // Get the resource id array.
63 IMemento[] children = memento.getChildren(TAG_RESOURCE_ID);
64 if (children.length == 0)
67 List<String> ids = new ArrayList<String>();
68 for (IMemento child : children)
69 ids.add(child.getTextData());
71 String editorId = memento.getString(TAG_EDITOR_ID);
74 ResourceEditorInput result = new ResourceEditorInput(editorId, ids);
76 // Read external persistent memento
77 String externalMementoStr = memento.getString(TAG_EXTERNAL_MEMENTO_ID);
78 if (externalMementoStr != null) {
79 StringMemento sm = new StringMemento(externalMementoStr);
80 sm.writeToMemento(result.getPersistentStore());
83 } catch (NumberFormatException e) {
85 } catch (IllegalArgumentException e) {
86 ErrorLogger.defaultLogError(e);
92 * Returns the element factory id for this class.
94 * @return the element factory id
96 public static String getFactoryId() {