import java.io.StringReader;\r
import java.util.HashMap;\r
import java.util.List;\r
+import java.util.Map;\r
import java.util.Set;\r
-import java.util.concurrent.ConcurrentSkipListMap;\r
-import java.util.concurrent.atomic.AtomicInteger;\r
\r
import org.eclipse.jface.preference.PreferenceConverter;\r
import org.eclipse.jface.resource.StringConverter;\r
import org.simantics.db.Statement;\r
import org.simantics.db.common.utils.ListUtils;\r
import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.procedure.AsyncMultiProcedure;\r
import org.simantics.db.procedure.AsyncProcedure;\r
-import org.simantics.db.procedure.SyncProcedure;\r
import org.simantics.diagram.G2DUtils;\r
import org.simantics.diagram.adapter.ElementFactoryAdapter;\r
import org.simantics.diagram.stubs.DiagramResource;\r
public void load(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, final Resource elementResource,\r
final IElement element, final AsyncProcedure<IElement> procedure) {\r
\r
- final AtomicInteger ready = new AtomicInteger(1);\r
- final ConcurrentSkipListMap<String, Pair<Resource, Object>> properties = new ConcurrentSkipListMap<String, Pair<Resource, Object>>();\r
-\r
element.setHint(DiagramHints.ROUTE_ALGORITHM, DependencyRouter.INSTANCE);\r
\r
- G2DResource G2D;\r
try {\r
- G2D = G2DResource.getInstance(graph.getSession());\r
- } catch (DatabaseException e) {\r
- e.printStackTrace();\r
- return;\r
- }\r
-\r
- // Find possible font\r
- graph.forPossibleStatement(elementResource, G2D.HasFont, new SyncProcedure<Statement>() {\r
-\r
- @Override\r
- public void execute(ReadGraph graph, Statement result) throws DatabaseException {\r
- if(result != null && !result.isAsserted(elementResource)) {\r
- element.setHint(ElementHints.KEY_FONT, G2DUtils.getFont(graph, result.getObject()));\r
- } else {\r
- String fontdata = graph.syncRequest(new SysdynDiagramPropertyExternalRead(new Pair<Resource, String>(elementResource, SysdynDiagramPreferences.ARROW_FONT)));\r
- if(fontdata != null) {\r
- FontData[] fdArray = PreferenceConverter.basicGetFontData(fontdata);\r
- if(fdArray != null) {\r
- if(fdArray.length == 1) {\r
- FontData fd = fdArray[0];\r
- if(fd != null) {\r
- Font font = new Font(fd.getName(), fd.getStyle(), fd.getHeight());\r
- element.setHint(ElementHints.KEY_FONT, font);\r
- }\r
- }\r
+ G2DResource G2D = G2DResource.getInstance(graph.getSession());\r
+\r
+ // Find possible font\r
+ Statement fontStm = graph.getPossibleStatement(elementResource, G2D.HasFont);\r
+ if(fontStm != null && !fontStm.isAsserted(elementResource)) {\r
+ element.setHint(ElementHints.KEY_FONT, G2DUtils.getFont(graph, fontStm.getObject()));\r
+ } else {\r
+ String fontdata = graph.syncRequest(new SysdynDiagramPropertyExternalRead(Pair.make(elementResource, SysdynDiagramPreferences.ARROW_FONT)));\r
+ if(fontdata != null) {\r
+ FontData[] fdArray = PreferenceConverter.basicGetFontData(fontdata);\r
+ if(fdArray != null && fdArray.length == 1) {\r
+ FontData fd = fdArray[0];\r
+ if(fd != null) {\r
+ Font font = new Font(fd.getName(), fd.getStyle(), fd.getHeight());\r
+ element.setHint(ElementHints.KEY_FONT, font);\r
}\r
}\r
-\r
}\r
}\r
\r
- @Override\r
- public void exception(ReadGraph graph, Throwable throwable) throws DatabaseException {\r
- throwable.printStackTrace();\r
- }\r
- });\r
-\r
- // Find possible color\r
- graph.forPossibleStatement(elementResource, G2D.HasColor, new SyncProcedure<Statement>() {\r
-\r
- @Override\r
- public void execute(ReadGraph graph, Statement result) throws DatabaseException {\r
- if(result != null && !result.isAsserted(elementResource)) {\r
- element.setHint(ElementHints.KEY_TEXT_COLOR, G2DUtils.getColor(graph, result.getObject()));\r
+ // Find possible color\r
+ Statement colorStm = graph.getPossibleStatement(elementResource, G2D.HasColor);\r
+ if(colorStm != null && !colorStm.isAsserted(elementResource)) {\r
+ element.setHint(ElementHints.KEY_TEXT_COLOR, G2DUtils.getColor(graph, colorStm.getObject()));\r
+ } else {\r
+ String color;\r
+ if (isForStockInitialOnly(graph, elementResource)) {\r
+ color = graph.syncRequest(new SysdynDiagramPropertyExternalRead(new Pair<Resource, String>(elementResource, SysdynDiagramPreferences.ARROW_STOCK_INITIAL_COLOR)));\r
} else {\r
- String color;\r
- if (isForStockInitialOnly(graph, elementResource)) {\r
- color = graph.syncRequest(new SysdynDiagramPropertyExternalRead(new Pair<Resource, String>(elementResource, SysdynDiagramPreferences.ARROW_STOCK_INITIAL_COLOR)));\r
- } else {\r
- color = graph.syncRequest(new SysdynDiagramPropertyExternalRead(new Pair<Resource, String>(elementResource, SysdynDiagramPreferences.ARROW_COLOR)));\r
- }\r
- if(color != null) {\r
- RGB rgb = StringConverter.asRGB(color, null);\r
- if(rgb != null) {\r
- Color c = new Color(rgb.red, rgb.green, rgb.blue);\r
- element.setHint(ElementHints.KEY_TEXT_COLOR, c);\r
- }\r
- }\r
-\r
+ color = graph.syncRequest(new SysdynDiagramPropertyExternalRead(new Pair<Resource, String>(elementResource, SysdynDiagramPreferences.ARROW_COLOR)));\r
}\r
- }\r
-\r
- @Override\r
- public void exception(ReadGraph graph, Throwable throwable) throws DatabaseException {\r
- throwable.printStackTrace();\r
- }\r
- });\r
-\r
-\r
- // A complicated-looking procedure for obtaining all HasProperties to properties map\r
- graph.forEachPredicate(elementResource, new AsyncMultiProcedure<Resource>() {\r
-\r
- @Override\r
- public void exception(AsyncReadGraph graph, Throwable throwable) {\r
- throwable.printStackTrace();\r
- }\r
-\r
- @Override\r
- public void execute(AsyncReadGraph graph, final Resource property) {\r
-\r
- ready.incrementAndGet();\r
- Layer0 l0;\r
- try {\r
- l0 = Layer0.getInstance(graph.getSession());\r
- } catch (DatabaseException e) {\r
- e.printStackTrace();\r
- return;\r
- }\r
-\r
- graph.forIsSubrelationOf(property, l0.HasProperty, new AsyncProcedure<Boolean>() {\r
-\r
- @Override\r
- public void exception(AsyncReadGraph graph, Throwable throwable) {\r
- throwable.printStackTrace();\r
+ if(color != null) {\r
+ RGB rgb = StringConverter.asRGB(color, null);\r
+ if(rgb != null) {\r
+ Color c = new Color(rgb.red, rgb.green, rgb.blue);\r
+ element.setHint(ElementHints.KEY_TEXT_COLOR, c);\r
}\r
-\r
- @Override\r
- public void execute(AsyncReadGraph graph, final Boolean isProperty) {\r
-\r
- if(isProperty) {\r
-\r
- graph.forPossibleRelatedValue(elementResource, property, new AsyncProcedure<Object>() {\r
-\r
- @Override\r
- public void exception(AsyncReadGraph graph, Throwable throwable) {\r
- throwable.printStackTrace();\r
- }\r
-\r
- @Override\r
- public void execute(AsyncReadGraph graph, final Object value) {\r
-\r
- Layer0 l0;\r
- try {\r
- l0 = Layer0.getInstance(graph.getSession());\r
- } catch (DatabaseException e) {\r
- e.printStackTrace();\r
- return;\r
- }\r
-\r
- graph.forPossibleRelatedValue(property, l0.HasName, Bindings.STRING, new AsyncProcedure<String>() {\r
-\r
- @Override\r
- public void exception(AsyncReadGraph graph, Throwable throwable) {\r
- throwable.printStackTrace();\r
- }\r
-\r
- @Override\r
- public void execute(AsyncReadGraph graph, String name) {\r
-\r
- properties.put(name, Pair.make(property, value));\r
- if(ready.decrementAndGet() == 0) {\r
- element.setHint(DiagramHints.PROPERTIES, new HashMap<String, Pair<Resource, Object>>(properties));\r
- procedure.execute(graph, element);\r
- }\r
-\r
- }\r
-\r
- });\r
-\r
- }\r
-\r
- });\r
-\r
-\r
- } else {\r
-\r
- if(ready.decrementAndGet() == 0) {\r
- element.setHint(DiagramHints.PROPERTIES, new HashMap<String, Pair<Resource, Object>>(properties));\r
- procedure.execute(graph, element);\r
- }\r
-\r
- }\r
-\r
- }\r
-\r
- });\r
+ }\r
}\r
\r
- @Override\r
- public void finished(AsyncReadGraph graph) {\r
-\r
- if(ready.decrementAndGet() == 0) {\r
- element.setHint(DiagramHints.PROPERTIES, new HashMap<String, Object>(properties));\r
- procedure.execute(graph, element);\r
+ // Get all HasProperties to properties map\r
+ final Map<String, Pair<Resource, Object>> properties = new HashMap<>();\r
+ Layer0 l0 = graph.l0();\r
+ for (Resource property : graph.getPredicates(elementResource)) {\r
+ if (graph.isSubrelationOf(property, l0.HasProperty)) {\r
+ Object value = graph.getPossibleRelatedValue(elementResource, property);\r
+ String name = graph.getPossibleRelatedValue(property, l0.HasName, Bindings.STRING);\r
+ if (value != null && name != null)\r
+ properties.put(name, Pair.make(property, value));\r
}\r
-\r
}\r
+ element.setHint(DiagramHints.PROPERTIES, properties);\r
\r
- });\r
-\r
+ procedure.execute(graph, element);\r
+ } catch (DatabaseException e) {\r
+ procedure.exception(graph, e);\r
+ }\r
}\r
\r
protected static boolean isForStockInitialOnly(ReadGraph graph,\r