]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.ui/src/org/simantics/ui/dnd/ResourceTransferData.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.ui / src / org / simantics / ui / dnd / ResourceTransferData.java
index 999e3c16ec37ecdd1c4ab65abc7fe7d46904ecde..7d4cd8c7a513b69a29b837adffc4d3cb5d20454d 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 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.ui.dnd;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-import java.util.List;\r
-\r
-import org.eclipse.ui.IMemento;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.Session;\r
-import org.simantics.db.SessionReference;\r
-import org.simantics.db.common.ResourceArray;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.service.SerialisationSupport;\r
-import org.simantics.utils.ui.workbench.StringMemento;\r
-\r
-/**\r
- * Transferable that contains a set of resource path references.\r
- *\r
- * @author Toni Kalajainen\r
- */\r
-public class ResourceTransferData extends ArrayList<ResourceArray> {\r
-\r
-    private static final long serialVersionUID = -6980850210973439012L;\r
-    private String purpose;\r
-\r
-    public ResourceTransferData() {\r
-        super();\r
-    }\r
-\r
-    public ResourceTransferData(Collection<? extends ResourceArray> c) {\r
-        super(c);        // TODO Auto-generated constructor stub\r
-    }\r
-\r
-    public ResourceTransferData(ResourceArray...arrays) {\r
-        super();\r
-        addAll(arrays);\r
-    }\r
-\r
-    public ResourceTransferData(Session s, Collection<? extends ResourceArray> c) {\r
-        super(c);        // TODO Auto-generated constructor stub\r
-    }\r
-\r
-    public ResourceTransferData(Session s, ResourceArray...arrays) {\r
-        super();\r
-        addAll(arrays);\r
-    }\r
-\r
-    public ResourceTransferData(SessionReference s, Collection<? extends ResourceArray> c) {\r
-        super(c);        // TODO Auto-generated constructor stub\r
-    }\r
-\r
-    public ResourceTransferData(SessionReference s, ResourceArray...arrays) {\r
-        super();\r
-        addAll(arrays);\r
-    }\r
-\r
-    public ResourceTransferData(SessionReference s) {\r
-        super();\r
-    }\r
-\r
-    public ResourceTransferData(Session s) {\r
-        super();\r
-    }\r
-\r
-    public String getPurpose() {\r
-        return purpose;\r
-    }\r
-\r
-    public void setPurpose(String purpose) {\r
-        this.purpose = purpose;\r
-    }\r
-\r
-    public void addAll(ResourceArray[] array)\r
-    {\r
-        for (ResourceArray a : array)\r
-            add(a);\r
-    }\r
-\r
-    public ResourceArray[] toResourceArrayArray()\r
-    {\r
-        return toArray(ResourceArray.NONE);\r
-    }\r
-\r
-    //////////// SERIALIZATION //////////////\r
-\r
-    /** Key to resource array of memento child */\r
-    private static final String RES_KEY = "res";\r
-    /** Key to purpose string of a memento */\r
-    private static final String PURPOSE_KEY = "purpose";\r
-\r
-    public void readFromMemento(SerialisationSupport serializer, IMemento memento)\r
-    throws DatabaseException\r
-    {\r
-//        String sessionReference = memento.getString("SessionReference");\r
-\r
-        String purpose = memento.getString(PURPOSE_KEY);\r
-\r
-        List<ResourceArray> res = new ArrayList<ResourceArray>();\r
-        for (IMemento child : memento.getChildren(RES_KEY))\r
-        {\r
-            ResourceArray array = readResourceArrayFromMemento(serializer, child);\r
-            res.add(array);\r
-        }\r
-\r
-        addAll(res);\r
-//        setSessionReference(sessionReference);\r
-        setPurpose(purpose);\r
-    }\r
-\r
-    public static ResourceArray readResourceArrayFromMemento(SerialisationSupport serializer, IMemento memento)\r
-    throws DatabaseException\r
-    {\r
-        List<Resource> result = new ArrayList<Resource>();\r
-        int index = 0;\r
-        while (memento.getString(""+index)!=null) {\r
-            String randomAccessId = memento.getString(""+index);\r
-            long id = Long.parseLong(randomAccessId);\r
-            Resource r = serializer.getResource(id);\r
-            result.add(r);\r
-            index++;\r
-        }\r
-        return new ResourceArray( result );\r
-    }\r
-\r
-    public void writeToMemento(SerialisationSupport serializer, IMemento memento)\r
-    throws DatabaseException\r
-    {\r
-        int index = 0;\r
-        if (purpose != null)\r
-            writePurpose(memento);\r
-        for (ResourceArray array : this)\r
-        {\r
-            String id = ""+index++;\r
-            StringMemento child = (StringMemento) memento.createChild(RES_KEY, id);\r
-            writeResourceArrayToMemento(serializer, array, child);\r
-        }\r
-    }\r
-\r
-    private void writePurpose(IMemento memento) {\r
-        assert purpose != null;\r
-        memento.putString(PURPOSE_KEY, purpose);\r
-    }\r
-\r
-    public static void writeResourceArrayToMemento(SerialisationSupport serializer, ResourceArray array, IMemento sm)\r
-    throws DatabaseException\r
-    {\r
-        for (int i=0; i<array.resources.length; i++)\r
-        {\r
-            Resource r = array.resources[i];\r
-            String rai = "" + serializer.getRandomAccessId(r);\r
-            sm.putString(""+i, rai);\r
-        }\r
-    }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 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.ui.dnd;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.ui.IMemento;
+import org.simantics.db.Resource;
+import org.simantics.db.Session;
+import org.simantics.db.SessionReference;
+import org.simantics.db.common.ResourceArray;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.service.SerialisationSupport;
+import org.simantics.utils.ui.workbench.StringMemento;
+
+/**
+ * Transferable that contains a set of resource path references.
+ *
+ * @author Toni Kalajainen
+ */
+public class ResourceTransferData extends ArrayList<ResourceArray> {
+
+    private static final long serialVersionUID = -6980850210973439012L;
+    private String purpose;
+
+    public ResourceTransferData() {
+        super();
+    }
+
+    public ResourceTransferData(Collection<? extends ResourceArray> c) {
+        super(c);        // TODO Auto-generated constructor stub
+    }
+
+    public ResourceTransferData(ResourceArray...arrays) {
+        super();
+        addAll(arrays);
+    }
+
+    public ResourceTransferData(Session s, Collection<? extends ResourceArray> c) {
+        super(c);        // TODO Auto-generated constructor stub
+    }
+
+    public ResourceTransferData(Session s, ResourceArray...arrays) {
+        super();
+        addAll(arrays);
+    }
+
+    public ResourceTransferData(SessionReference s, Collection<? extends ResourceArray> c) {
+        super(c);        // TODO Auto-generated constructor stub
+    }
+
+    public ResourceTransferData(SessionReference s, ResourceArray...arrays) {
+        super();
+        addAll(arrays);
+    }
+
+    public ResourceTransferData(SessionReference s) {
+        super();
+    }
+
+    public ResourceTransferData(Session s) {
+        super();
+    }
+
+    public String getPurpose() {
+        return purpose;
+    }
+
+    public void setPurpose(String purpose) {
+        this.purpose = purpose;
+    }
+
+    public void addAll(ResourceArray[] array)
+    {
+        for (ResourceArray a : array)
+            add(a);
+    }
+
+    public ResourceArray[] toResourceArrayArray()
+    {
+        return toArray(ResourceArray.NONE);
+    }
+
+    //////////// SERIALIZATION //////////////
+
+    /** Key to resource array of memento child */
+    private static final String RES_KEY = "res";
+    /** Key to purpose string of a memento */
+    private static final String PURPOSE_KEY = "purpose";
+
+    public void readFromMemento(SerialisationSupport serializer, IMemento memento)
+    throws DatabaseException
+    {
+//        String sessionReference = memento.getString("SessionReference");
+
+        String purpose = memento.getString(PURPOSE_KEY);
+
+        List<ResourceArray> res = new ArrayList<ResourceArray>();
+        for (IMemento child : memento.getChildren(RES_KEY))
+        {
+            ResourceArray array = readResourceArrayFromMemento(serializer, child);
+            res.add(array);
+        }
+
+        addAll(res);
+//        setSessionReference(sessionReference);
+        setPurpose(purpose);
+    }
+
+    public static ResourceArray readResourceArrayFromMemento(SerialisationSupport serializer, IMemento memento)
+    throws DatabaseException
+    {
+        List<Resource> result = new ArrayList<Resource>();
+        int index = 0;
+        while (memento.getString(""+index)!=null) {
+            String randomAccessId = memento.getString(""+index);
+            long id = Long.parseLong(randomAccessId);
+            Resource r = serializer.getResource(id);
+            result.add(r);
+            index++;
+        }
+        return new ResourceArray( result );
+    }
+
+    public void writeToMemento(SerialisationSupport serializer, IMemento memento)
+    throws DatabaseException
+    {
+        int index = 0;
+        if (purpose != null)
+            writePurpose(memento);
+        for (ResourceArray array : this)
+        {
+            String id = ""+index++;
+            StringMemento child = (StringMemento) memento.createChild(RES_KEY, id);
+            writeResourceArrayToMemento(serializer, array, child);
+        }
+    }
+
+    private void writePurpose(IMemento memento) {
+        assert purpose != null;
+        memento.putString(PURPOSE_KEY, purpose);
+    }
+
+    public static void writeResourceArrayToMemento(SerialisationSupport serializer, ResourceArray array, IMemento sm)
+    throws DatabaseException
+    {
+        for (int i=0; i<array.resources.length; i++)
+        {
+            Resource r = array.resources[i];
+            String rai = "" + serializer.getRandomAccessId(r);
+            sm.putString(""+i, rai);
+        }
+    }
+}