]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.g3d/src/org/simantics/proconf/g3d/tools/PropertyTree.java
Removing ancient 3d framework
[simantics/3d.git] / org.simantics.g3d / src / org / simantics / proconf / g3d / tools / PropertyTree.java
diff --git a/org.simantics.g3d/src/org/simantics/proconf/g3d/tools/PropertyTree.java b/org.simantics.g3d/src/org/simantics/proconf/g3d/tools/PropertyTree.java
deleted file mode 100644 (file)
index 290c921..0000000
+++ /dev/null
@@ -1,313 +0,0 @@
-/*******************************************************************************\r
- * Copyright (c) 2007- VTT Technical Research Centre of Finland.\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.proconf.g3d.tools;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-import java.util.List;\r
-\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.widgets.Display;\r
-import org.eclipse.swt.widgets.Tree;\r
-import org.eclipse.swt.widgets.TreeItem;\r
-import org.simantics.db.Builtins;\r
-import org.simantics.db.Graph;\r
-import org.simantics.db.GraphRequestAdapter;\r
-import org.simantics.db.GraphRequestStatus;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.Session;\r
-import org.simantics.layer0.utils.EntityFactory;\r
-import org.simantics.layer0.utils.IEntity;\r
-import org.simantics.layer0.utils.ResourceDebugUtils;\r
-import org.simantics.layer0.utils.Statement;\r
-import org.simantics.proconf.g3d.common.StructuredResourceSelection;\r
-\r
-/**\r
- * PropertyTree finds common properties for set of objects, and\r
- * then based on user's selection returns all property instances.\r
- * \r
- * @author Marko Luukkainen\r
- *\r
- */\r
-public class PropertyTree {\r
-    private Tree tree;\r
-    private Session session;\r
-    \r
-    \r
-    public PropertyTree(Tree tree, Session session) {\r
-        this.tree = tree;\r
-        this.session = session;\r
-    }\r
-    \r
-    public void setProperties(List<Resource> selectedInstances) {\r
-        tree.removeAll();\r
-        addProperties(null,selectedInstances);\r
-        tree.redraw();\r
-    }\r
-    \r
-    public void setProperties(StructuredResourceSelection selection) {\r
-        ArrayList<Resource> selectedInstances = new ArrayList<Resource>();\r
-        for (Resource r : selection.getSelectionList()) {\r
-            if (!contains(selectedInstances,r)) {\r
-               selectedInstances.add(r);\r
-                \r
-                //System.out.println("Added " + name.getName());\r
-            } else {\r
-               \r
-               // System.out.println("Discarded " + name.getName());\r
-            }\r
-        }\r
-        setProperties(selectedInstances);\r
-    }\r
-    \r
-    public Tree getTree() {\r
-        return tree;\r
-    }\r
-\r
-    private void addProperties(final TreeItem parent, final List<Resource> selectedInstances) {\r
-       session.asyncRead(new GraphRequestAdapter() {\r
-               @Override\r
-               public GraphRequestStatus perform(Graph g) throws Exception {\r
-                       Builtins builtins = g.getBuiltins();\r
-                       ArrayList<Resource> relationTypes = new ArrayList<Resource>();\r
-               for (Resource resource : selectedInstances) {\r
-                   IEntity thing = EntityFactory.create(g, resource);\r
-                   \r
-                   Collection<Statement> properties = thing.getRelatedStatements(builtins.HasProperty);\r
-                  // RelationSet properties = resource.getRelatedResourcesWithRelationIds(GlobalIdMap.get(Builtins.HasProperty));\r
-                   \r
-                   for (Statement r : properties) {\r
-                       // Statement contains relation from instance to property(instance)\r
-                       // Find the property's type(s)\r
-                       // TODO : seems to be bad way of finding type\r
-                       Collection<IEntity> types = r.getObject().getRelatedObjects(builtins.InstanceOf);\r
-                       if (types.size() != 1)\r
-                               throw new UnsupportedOperationException("Cannot support multi-instances");\r
-                       IEntity type = types.iterator().next();\r
-                       if (!contains(relationTypes, r.getPredicate().getResource())) {\r
-                           \r
-                           if (type.isInheritedFrom(builtins.Double)) {\r
-                               \r
-                               relationTypes.add(r.getPredicate().getResource());\r
-                              \r
-                               //System.out.println("Added " + name.getName() + " " + type.getId() + " " + r.getRelationId() + " " + relationType.getId());\r
-                               final String name = getNameForThing(r.getPredicate());//getNameForThing(thing);\r
-                               final Object treeData = r.getPredicate().getResource();\r
-                               Display.getDefault().asyncExec(new Runnable() {\r
-                               //parent.getDisplay().asyncExec(new Runnable() {\r
-                                       TreeItem item = null;\r
-                                       @Override\r
-                                       public void run() {\r
-                                               if (parent != null)\r
-                                           item = new TreeItem(parent,SWT.NONE);\r
-                                       else\r
-                                           item = new TreeItem(tree,SWT.NONE);\r
-                                       item.setData(treeData);\r
-                                       item.setText(name);\r
-                                               \r
-                                       }\r
-                               });\r
-                               \r
-                           } else {\r
-                               //Resource pproperties[] = r.getRelatedResources(GlobalIdMap.get(Builtins.PropertyRelationType));\r
-                                   //Resource pproperties[] = resource.get(r.getObjectId()).getRelatedResources(GlobalIdMap.get(Builtins.HasProperty));\r
-                                   Collection<IEntity> pproperties = r.getObject().getRelatedObjects(builtins.HasProperty);\r
-                               if (pproperties.size() > 0) {\r
-                                       final ArrayList<Resource> list = new ArrayList<Resource>();\r
-                                       list.add(r.getObject().getResource());\r
-                                      \r
-                                       final String name = getNameForThing(r.getPredicate());//getNameForThing(thing);\r
-                                       final Object treeData = r.getPredicate().getResource();\r
-                                       relationTypes.add(r.getPredicate().getResource());\r
-                                       Display.getDefault().asyncExec(new Runnable() {\r
-                                       //parent.getDisplay().asyncExec(new Runnable() {\r
-                                               @Override\r
-                                               public void run() {\r
-                                                       TreeItem item = null;\r
-                                                                               if (parent != null)\r
-                                                                                       item = new TreeItem(parent, SWT.NONE);\r
-                                                                               else\r
-                                                                                       item = new TreeItem(tree, SWT.NONE);\r
-                                                                               item.setText(name);\r
-                                                                               item.setData(treeData);\r
-                                                                               addProperties(item,list);\r
-                                               }\r
-                                       });\r
-                                   }\r
-                           }\r
-                       } \r
-                   }\r
-               }\r
-                       return GraphRequestStatus.transactionComplete();\r
-               }\r
-       });\r
-        \r
-    }\r
-    \r
-    private String getNameForThing(IEntity thing) {\r
-       return ResourceDebugUtils.getReadableNameForEntity(thing);\r
-        /*\r
-        String tName = thing.getName();\r
-         if (tName == null) {\r
-               Collection<Thing> ptypes = thing.getTypes();\r
-               for (Thing pt : ptypes) {\r
-                       tName = pt.getName();\r
-                       if (tName != null)\r
-                               break;\r
-               }\r
-         }\r
-         if (tName == null)\r
-                return "Error / no name for " + thing;\r
-         return tName;\r
-         */\r
-    }\r
-    \r
-    private boolean contains(java.util.List<Resource> list, Resource value) {\r
-        for (int i = 0; i < list.size(); i++) {\r
-            if (list.get(i).equals(value))\r
-                return true;\r
-        }\r
-        return false;\r
-    }\r
-    \r
-    /**\r
-     * Returns all properties (instances) contained in the list depending on selection in the tree and \r
-     * TODO : currently can be run only in UI -thread with transaction.\r
-     * \r
-     * @param graph\r
-     * @param shapes\r
-     * @return\r
-     */\r
-    public List<Resource> findLeafPropertyInstances(Graph graph,List<Resource> shapes) {\r
-        TreeItem[] selectedProperties = tree.getSelection();\r
-        List<Resource> props = new ArrayList<Resource>();\r
-        for (TreeItem propertyItem : selectedProperties) {\r
-            \r
-            TreeItem t = propertyItem;\r
-            boolean c = false;\r
-            // if list contains treeNode's parent, node's property is already mapped / will be mapped later\r
-            while (t.getParentItem() != null) {\r
-                if (contains(selectedProperties, t.getParentItem())) {\r
-                    c = true;\r
-                    break;\r
-                }\r
-                t = t.getParentItem();\r
-\r
-            }\r
-            if (!c) {\r
-               props.addAll(findLeafProperties(graph,shapes, propertyItem));\r
-            }\r
-        }\r
-        return props;\r
-    }\r
-    \r
-    public List<Resource> findPropertyInstances(Graph graph,List<Resource> shapes) {\r
-        TreeItem[] selectedProperties = tree.getSelection();\r
-        List<Resource> props = new ArrayList<Resource>();\r
-        for (TreeItem propertyItem : selectedProperties) {\r
-            \r
-            TreeItem t = propertyItem;\r
-            boolean c = false;\r
-            // if list contains treeNode's parent, node's property is already mapped / will be mapped later\r
-            while (t.getParentItem() != null) {\r
-                if (contains(selectedProperties, t.getParentItem())) {\r
-                    c = true;\r
-                    break;\r
-                }\r
-                t = t.getParentItem();\r
-\r
-            }\r
-            if (!c) {\r
-               props.addAll(findProperties(graph,shapes, propertyItem));\r
-            }\r
-        }\r
-        return props;\r
-    }\r
-    \r
-    private List<Resource> findProperties(Graph graph,java.util.List<Resource> shapes, TreeItem propertyItem) {\r
-        ArrayList<Resource> propertyChain = new ArrayList<Resource>();\r
-        TreeItem t = propertyItem;\r
-        while (t != null) {\r
-            propertyChain.add((Resource) t.getData());\r
-            t = t.getParentItem();\r
-        }\r
-        \r
-        return findProperties(graph,shapes,propertyChain);\r
-       \r
-    }\r
-    \r
-    private List<Resource> findLeafProperties(Graph graph,java.util.List<Resource> shapes, TreeItem propertyItem) {\r
-        ArrayList<Resource> propertyChain = new ArrayList<Resource>();\r
-        TreeItem t = propertyItem;\r
-        while (t != null) {\r
-            propertyChain.add((Resource)t.getData());\r
-            t = t.getParentItem();\r
-        }\r
-        // now propertyChain contains property hierarchy from leaf to root\r
-        //Long typeID = (Long) propertyItem.getData();\r
-        if (propertyItem.getItemCount() == 0) { \r
-            return findProperties(graph,shapes,propertyChain);\r
-        } else {\r
-            List<Resource> props = new ArrayList<Resource>();\r
-            //Long typeID = (Long) propertyItem.getData();\r
-            TreeItem children[] = propertyItem.getItems();\r
-            //ArrayList<Resource> props = getPropertiesForType(shapes, typeID);\r
-            for (TreeItem i : children)\r
-                //mapProperty(parameter,props, i);\r
-                props.addAll(findLeafProperties(graph,shapes, i));\r
-            return props;\r
-        }\r
-    }\r
-    \r
-    private List<Resource> findProperties(Graph graph, java.util.List<Resource> shapes, ArrayList<Resource> propertyChain) {\r
-        ArrayList<Resource> res = new ArrayList<Resource>(shapes);\r
-        // propertyChain contains hierarhy of properties form leaf to root :\r
-        // we'll find root property from shapes and then iterate each property instance\r
-        // until we'll fin all requested properties (first element in property chain)\r
-        \r
-//        System.out.print("instances ");\r
-//        for (Resource r : res) {\r
-//            System.out.print(r + " ");\r
-//        }\r
-//        System.out.println();\r
-        \r
-        while (propertyChain.size() > 0) {\r
-            res = getPropertiesForType(graph, res, propertyChain.get(propertyChain.size() - 1));\r
-//            System.out.print(propertyChain.get(propertyChain.size() - 1) +" instances ");\r
-//            for (Resource r : res) {\r
-//                System.out.print(r + " ");\r
-//            }\r
-//            System.out.println();\r
-            propertyChain.remove(propertyChain.size() - 1);\r
-        }\r
-        // now res contains all instances of requested property\r
-        return res;\r
-    }\r
-    \r
-    private ArrayList<Resource> getPropertiesForType(Graph graph,java.util.List<Resource> instances, Resource typeID) {\r
-        ArrayList<Resource> properties = new ArrayList<Resource>();\r
-        for (Resource instance : instances) {\r
-               IEntity t = EntityFactory.create(graph,instance);\r
-               Collection<IEntity> props = t.getRelatedObjects(typeID);\r
-            for (IEntity p : props)\r
-                properties.add(p.getResource());\r
-                \r
-        }\r
-        return properties;\r
-    }\r
-    \r
-    private boolean contains(TreeItem items[], TreeItem item) {\r
-        for (TreeItem i : items)\r
-            if (i.equals(item))\r
-                return true;\r
-        return false;\r
-    }\r
-}\r