]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling.template2d.ui/src/org/simantics/modeling/template2d/ui/actions/FixLinkedList.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.modeling.template2d.ui / src / org / simantics / modeling / template2d / ui / actions / FixLinkedList.java
index 2963144cc74e303fa20f51f3880e5b0b4e3c2352..0198ff3bc3bd038a336e9d8422640fc1273dd196 100644 (file)
@@ -1,79 +1,79 @@
-/*******************************************************************************\r
- * Copyright (c) 2012 Association for Decentralized Information Management in\r
- * 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.modeling.template2d.ui.actions;\r
-\r
-import java.util.Collection;\r
-import java.util.HashSet;\r
-import java.util.List;\r
-import java.util.Set;\r
-\r
-import org.simantics.Simantics;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.request.ObjectsWithType;\r
-import org.simantics.db.common.request.WriteRequest;\r
-import org.simantics.db.common.utils.ListUtils;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.adapter.ActionFactory;\r
-import org.simantics.db.layer0.util.RemoverUtil;\r
-import org.simantics.layer0.Layer0;\r
-import org.simantics.scenegraph.ontology.ScenegraphResources;\r
-\r
-public class FixLinkedList implements ActionFactory {\r
-\r
-    @Override\r
-    public Runnable create(Object target) {\r
-        if(!(target instanceof Resource))\r
-            return null;\r
-        final Resource parent = (Resource)target;\r
-\r
-        return new Runnable() {\r
-            @Override\r
-            public void run() {\r
-                Simantics.getSession().asyncRequest(new WriteRequest() {\r
-                    @Override\r
-                    public void perform(WriteGraph g) throws DatabaseException {\r
-                        g.markUndoPoint();\r
-                        Layer0 L0 = Layer0.getInstance(g);\r
-                        ScenegraphResources SG = ScenegraphResources.getInstance(g);\r
-\r
-                        Collection<Resource> consist = g.syncRequest(new ObjectsWithType(parent, L0.ConsistsOf, SG.Node));\r
-\r
-                        Resource list = g.getPossibleObject(parent, SG.Node_children);\r
-                        if (list != null) {\r
-                            try {\r
-                                List<Resource> children = ListUtils.toList(g, list);\r
-                                Set<Resource> childSet = new HashSet<Resource>(children);\r
-                                Set<Resource> consistSet = new HashSet<Resource>(consist);\r
-                                if (childSet.equals(consistSet)) {\r
-                                    return;\r
-                                }\r
-                            } catch (DatabaseException e) {\r
-                            }\r
-\r
-                            // List is invalid, recreate it.\r
-                            RemoverUtil.remove(g, list);\r
-                            g.deny(parent, SG.Node_children);\r
-                            list = ListUtils.create(g, consist);\r
-                            g.claim(parent, SG.Node_children, list);\r
-\r
-                        } else {\r
-                            // No list at all - create one from children.\r
-                            list = ListUtils.create(g, consist);\r
-                            g.claim(parent, SG.Node_children, list);\r
-                        }\r
-                    }\r
-                });\r
-            }\r
-        };\r
-    }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012 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.modeling.template2d.ui.actions;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.simantics.Simantics;
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.ObjectsWithType;
+import org.simantics.db.common.request.WriteRequest;
+import org.simantics.db.common.utils.ListUtils;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.adapter.ActionFactory;
+import org.simantics.db.layer0.util.RemoverUtil;
+import org.simantics.layer0.Layer0;
+import org.simantics.scenegraph.ontology.ScenegraphResources;
+
+public class FixLinkedList implements ActionFactory {
+
+    @Override
+    public Runnable create(Object target) {
+        if(!(target instanceof Resource))
+            return null;
+        final Resource parent = (Resource)target;
+
+        return new Runnable() {
+            @Override
+            public void run() {
+                Simantics.getSession().asyncRequest(new WriteRequest() {
+                    @Override
+                    public void perform(WriteGraph g) throws DatabaseException {
+                        g.markUndoPoint();
+                        Layer0 L0 = Layer0.getInstance(g);
+                        ScenegraphResources SG = ScenegraphResources.getInstance(g);
+
+                        Collection<Resource> consist = g.syncRequest(new ObjectsWithType(parent, L0.ConsistsOf, SG.Node));
+
+                        Resource list = g.getPossibleObject(parent, SG.Node_children);
+                        if (list != null) {
+                            try {
+                                List<Resource> children = ListUtils.toList(g, list);
+                                Set<Resource> childSet = new HashSet<Resource>(children);
+                                Set<Resource> consistSet = new HashSet<Resource>(consist);
+                                if (childSet.equals(consistSet)) {
+                                    return;
+                                }
+                            } catch (DatabaseException e) {
+                            }
+
+                            // List is invalid, recreate it.
+                            RemoverUtil.remove(g, list);
+                            g.deny(parent, SG.Node_children);
+                            list = ListUtils.create(g, consist);
+                            g.claim(parent, SG.Node_children, list);
+
+                        } else {
+                            // No list at all - create one from children.
+                            list = ListUtils.create(g, consist);
+                            g.claim(parent, SG.Node_children, list);
+                        }
+                    }
+                });
+            }
+        };
+    }
+}