]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.graphfile/src/org/simantics/graphfile/hack/GraphFileEditorInputFactory.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.graphfile / src / org / simantics / graphfile / hack / GraphFileEditorInputFactory.java
index 9f0a05093d370e522708985a79040e2ab2a49891..73f10d0b31e216846a42c8a68830e0d848b4be97 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2013 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.graphfile.hack;\r
-\r
-import org.eclipse.core.resources.IWorkspace;\r
-import org.eclipse.core.resources.ResourcesPlugin;\r
-import org.eclipse.core.runtime.IAdaptable;\r
-import org.eclipse.ui.IElementFactory;\r
-import org.eclipse.ui.IMemento;\r
-import org.simantics.Simantics;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.request.Read;\r
-import org.simantics.db.service.SerialisationSupport;\r
-\r
-/**\r
- * FileEditorInputFactory for GraphFiles. Handles loading and saving GraphFile references.\r
- * \r
- * TODO : uses resource id to reference resources. That is unreliable.\r
- * \r
- * @author Marko Luukkainen <marko.luukkainen@vtt.fi>\r
- *\r
- */\r
-public class GraphFileEditorInputFactory implements IElementFactory{\r
-        /**\r
-     * Factory id. The workbench plug-in registers a factory by this name\r
-     * with the "org.eclipse.ui.elementFactories" extension point.\r
-     */\r
-    private static final String ID_FACTORY = "org.simantics.graphfile.hack.GraphFileEditorInputFactory"; //$NON-NLS-1$\r
-\r
-    /**\r
-     * Tag for the IFile.fullPath of the file resource.\r
-     */\r
-    private static final String TAG_RESOURCE_ID = "id"; //$NON-NLS-1$\r
-\r
-    /**\r
-     * Creates a new factory.\r
-     */\r
-    public GraphFileEditorInputFactory() {\r
-    }\r
-\r
-    /* (non-Javadoc)\r
-     * Method declared on IElementFactory.\r
-     */\r
-    public IAdaptable createElement(IMemento memento) {\r
-        // Get the file name.\r
-        String sid = memento.getString(TAG_RESOURCE_ID);\r
-        if (sid == null) {\r
-                       return null;\r
-               }\r
-        final long id = Long.parseLong(sid);\r
-        \r
-        Resource fileResource = null;\r
-        try {\r
-               fileResource = Simantics.getSession().syncRequest(new Read<Resource>() {\r
-                       @Override\r
-                       public Resource perform(ReadGraph graph) throws DatabaseException {\r
-                                 SerialisationSupport support = graph.getService(SerialisationSupport.class);\r
-                             try {\r
-                                 Resource r = support.getResource(id);\r
-                                 return r;\r
-                             } catch (Exception e) {\r
-                                 return null;\r
-                             }\r
-                                 \r
-                       }\r
-               });\r
-        } catch (DatabaseException e) {\r
-               return null;\r
-        }\r
-        \r
-        if (fileResource == null)\r
-               return null;\r
-\r
-        // Get a handle to the IFile...which can be a handle\r
-        // to a resource that does not exist in workspace\r
-        IWorkspace ws = (IWorkspace) ResourcesPlugin.getWorkspace();\r
-        GraphFile file = new GraphFile(fileResource, ws);\r
-        return new GraphFileEditorInput(file);\r
-    }\r
-\r
-    /**\r
-     * Returns the element factory id for this class.\r
-     * \r
-     * @return the element factory id\r
-     */\r
-    public static String getFactoryId() {\r
-        return ID_FACTORY;\r
-    }\r
-\r
-    /**\r
-     * Saves the state of the given file editor input into the given memento.\r
-     *\r
-     * @param memento the storage area for element state\r
-     * @param input the file editor input\r
-     */\r
-    public static void saveState(IMemento memento, GraphFileEditorInput input) {\r
-        GraphFile file = (GraphFile)input.getFile();\r
-        memento.putString(TAG_RESOURCE_ID, Long.toString(file.getFileResource().getResourceId()));\r
-    }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2013 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.graphfile.hack;
+
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.ui.IElementFactory;
+import org.eclipse.ui.IMemento;
+import org.simantics.Simantics;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.request.Read;
+import org.simantics.db.service.SerialisationSupport;
+
+/**
+ * FileEditorInputFactory for GraphFiles. Handles loading and saving GraphFile references.
+ * 
+ * TODO : uses resource id to reference resources. That is unreliable.
+ * 
+ * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
+ *
+ */
+public class GraphFileEditorInputFactory implements IElementFactory{
+        /**
+     * Factory id. The workbench plug-in registers a factory by this name
+     * with the "org.eclipse.ui.elementFactories" extension point.
+     */
+    private static final String ID_FACTORY = "org.simantics.graphfile.hack.GraphFileEditorInputFactory"; //$NON-NLS-1$
+
+    /**
+     * Tag for the IFile.fullPath of the file resource.
+     */
+    private static final String TAG_RESOURCE_ID = "id"; //$NON-NLS-1$
+
+    /**
+     * Creates a new factory.
+     */
+    public GraphFileEditorInputFactory() {
+    }
+
+    /* (non-Javadoc)
+     * Method declared on IElementFactory.
+     */
+    public IAdaptable createElement(IMemento memento) {
+        // Get the file name.
+        String sid = memento.getString(TAG_RESOURCE_ID);
+        if (sid == null) {
+                       return null;
+               }
+        final long id = Long.parseLong(sid);
+        
+        Resource fileResource = null;
+        try {
+               fileResource = Simantics.getSession().syncRequest(new Read<Resource>() {
+                       @Override
+                       public Resource perform(ReadGraph graph) throws DatabaseException {
+                                 SerialisationSupport support = graph.getService(SerialisationSupport.class);
+                             try {
+                                 Resource r = support.getResource(id);
+                                 return r;
+                             } catch (Exception e) {
+                                 return null;
+                             }
+                                 
+                       }
+               });
+        } catch (DatabaseException e) {
+               return null;
+        }
+        
+        if (fileResource == null)
+               return null;
+
+        // Get a handle to the IFile...which can be a handle
+        // to a resource that does not exist in workspace
+        IWorkspace ws = (IWorkspace) ResourcesPlugin.getWorkspace();
+        GraphFile file = new GraphFile(fileResource, ws);
+        return new GraphFileEditorInput(file);
+    }
+
+    /**
+     * Returns the element factory id for this class.
+     * 
+     * @return the element factory id
+     */
+    public static String getFactoryId() {
+        return ID_FACTORY;
+    }
+
+    /**
+     * Saves the state of the given file editor input into the given memento.
+     *
+     * @param memento the storage area for element state
+     * @param input the file editor input
+     */
+    public static void saveState(IMemento memento, GraphFileEditorInput input) {
+        GraphFile file = (GraphFile)input.getFile();
+        memento.putString(TAG_RESOURCE_ID, Long.toString(file.getFileResource().getResourceId()));
+    }
+}