import org.simantics.interop.test.GraphChanges;
import org.simantics.interop.update.Activator;
import org.simantics.interop.update.model.ModelUpdate;
-import org.simantics.interop.update.model.PropertyChange;
import org.simantics.interop.update.model.ModelUpdate.WarningListener;
+import org.simantics.interop.update.model.PropertyChange;
import org.simantics.interop.update.model.UpdateList;
import org.simantics.interop.update.model.UpdateNode;
import org.simantics.interop.update.model.UpdateOp;
import org.simantics.interop.update.model.UpdateTree;
import org.simantics.interop.utils.TableUtils;
import org.simantics.ui.SimanticsUI;
-import org.simantics.utils.datastructures.Callback;
import org.simantics.utils.datastructures.Pair;
import org.simantics.utils.ui.ExceptionUtils;
}
- }, new Callback<DatabaseException>() {
- @Override
- public void run(DatabaseException parameter) {
- if (parameter != null)
- ExceptionUtils.logAndShowError("Cannot update model", parameter);
- }
+ }, e -> {
+ if (e != null)
+ ExceptionUtils.logAndShowError("Cannot update model", e);
});
}
private class SelectionEditingSupport extends EditingSupport {
- @SuppressWarnings("rawtypes")
public SelectionEditingSupport(ColumnViewer viewer) {
super(viewer);
-
}
@Override
return pc.selected();
}
- @SuppressWarnings("unchecked")
@Override
protected void setValue(Object element, Object value) {
if (update == null || !update.isInit())
package org.simantics.xml.sax.base;\r
\r
import java.io.Serializable;\r
+import java.util.ArrayList;\r
import java.util.Collection;\r
import java.util.HashMap;\r
+import java.util.List;\r
import java.util.Map;\r
\r
import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.utils.ListUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.utils.datastructures.MapList;\r
import org.xml.sax.Attributes;\r
\r
public class ParserElement implements Serializable {\r
String uri;\r
String localName;\r
String qName;\r
- Map<String,Attribute> attributes = new HashMap<String, Attribute>();\r
- \r
+ Map<String, Attribute> attributes;\r
+ MapList<Resource, ParserElement> lists;\r
+\r
XMLElementParser elementParser;\r
XMLParser xmlParser;\r
- \r
+\r
public ParserElement(String uri, String localName, String qName, Attributes attributes) {\r
this.uri = uri;\r
this.localName = localName;\r
this.qName = qName;\r
- for (int i = 0; i < attributes.getLength(); i++) {\r
+ int attrCount = attributes.getLength();\r
+ this.attributes = new HashMap<>(attrCount);\r
+ for (int i = 0; i < attrCount; i++) {\r
this.attributes.put(attributes.getLocalName(i),new Attribute(attributes.getLocalName(i),attributes.getQName(i),attributes.getURI(i),attributes.getValue(i)));\r
}\r
}\r
this.uri = uri;\r
this.localName = localName;\r
this.qName = qName;\r
+ this.attributes = new HashMap<>(attributes.size());\r
for (Attribute a : attributes) {\r
this.attributes.put(a.localName,new Attribute(a.localName,a.qName,a.uri,a.value));\r
}\r
return xmlParser;\r
}\r
\r
+ public void registerListChild(Resource predicate, ParserElement child) {\r
+ if (lists == null)\r
+ lists = new MapList<>();\r
+ lists.add(predicate, child);\r
+ }\r
+\r
+ public void createLists(WriteGraph graph) throws DatabaseException {\r
+ if (lists == null)\r
+ return;\r
+ Layer0 L0 = Layer0.getInstance(graph);\r
+ for (Resource predicate : lists.getKeys()) {\r
+ List<Resource> children = new ArrayList<>();\r
+ for (ParserElement child : lists.getValues(predicate))\r
+ children.add(child.getData());\r
+ Resource list = ListUtils.create(graph, L0.List, L0.List_Element, null, children);\r
+ graph.claim(getData(), predicate, list);\r
+ }\r
+ }\r
+\r
}
\ No newline at end of file
// element type specific list
fw.delayedWriter.println(" {");
- fw.delayedWriter.println(" Resource list = graph.getPossibleObject(element.getData(),"+ontShort+getName(parent)+"_has"+refName + "_List);");
- fw.delayedWriter.println(" if (list == null) {");
- fw.delayedWriter.println(" list = org.simantics.db.common.utils.ListUtils.create(graph, java.util.Collections.singletonList(child.getData()));");
- fw.delayedWriter.println(" graph.claim(element.getData(),"+ontShort+getName(parent)+"_has"+refName + "_List,list);");
- fw.delayedWriter.println(" } else {");
- fw.delayedWriter.println(" org.simantics.db.common.utils.ListUtils.insertBack(graph, list, java.util.Collections.singletonList(child.getData()));");
- fw.delayedWriter.println(" }");
+ fw.delayedWriter.println(" element.registerListChild("+ontShort+getName(parent)+"_has"+refName + "_List, child);");
+// fw.delayedWriter.println(" Resource list = graph.getPossibleObject(element.getData(),"+ontShort+getName(parent)+"_has"+refName + "_List);");
+// fw.delayedWriter.println(" if (list == null) {");
+// fw.delayedWriter.println(" list = org.simantics.db.common.utils.ListUtils.create(graph, java.util.Collections.singletonList(child.getData()));");
+// fw.delayedWriter.println(" graph.claim(element.getData(),"+ontShort+getName(parent)+"_has"+refName + "_List,list);");
+// fw.delayedWriter.println(" } else {");
+// fw.delayedWriter.println(" org.simantics.db.common.utils.ListUtils.insertBack(graph, list, java.util.Collections.singletonList(child.getData()));");
+// fw.delayedWriter.println(" }");
fw.delayedWriter.println(" }");
}
if (useOriginalList) {
// generic list
fw.delayedWriter.println(" {");
fw.delayedWriter.println(" XMLResource XML = XMLResource.getInstance(graph);");
- fw.delayedWriter.println(" Resource list = graph.getPossibleObject(element.getData(), XML.hasOriginalElementList);");
- fw.delayedWriter.println(" if (list == null) {");
- fw.delayedWriter.println(" list = org.simantics.db.common.utils.ListUtils.create(graph, java.util.Collections.singletonList(child.getData()));");
- fw.delayedWriter.println(" graph.claim(element.getData(), XML.hasOriginalElementList,list);");
- fw.delayedWriter.println(" } else {");
- fw.delayedWriter.println(" org.simantics.db.common.utils.ListUtils.insertBack(graph, list, java.util.Collections.singletonList(child.getData()));");
- fw.delayedWriter.println(" }");
+ fw.delayedWriter.println(" element.registerListChild(XML.hasOriginalElementList, child);");
+// fw.delayedWriter.println(" Resource list = graph.getPossibleObject(element.getData(), XML.hasOriginalElementList);");
+// fw.delayedWriter.println(" if (list == null) {");
+// fw.delayedWriter.println(" list = org.simantics.db.common.utils.ListUtils.create(graph, java.util.Collections.singletonList(child.getData()));");
+// fw.delayedWriter.println(" graph.claim(element.getData(), XML.hasOriginalElementList,list);");
+// fw.delayedWriter.println(" } else {");
+// fw.delayedWriter.println(" org.simantics.db.common.utils.ListUtils.insertBack(graph, list, java.util.Collections.singletonList(child.getData()));");
+// fw.delayedWriter.println(" }");
fw.delayedWriter.println(" }");
}
// element type specific list
fw.delayedWriter.println(" {");
- fw.delayedWriter.println(" Resource list = graph.getPossibleObject(element.getData(),"+ontShort+getName(parent)+"_has"+refName + "_List);");
- fw.delayedWriter.println(" if (list == null) {");
- fw.delayedWriter.println(" list = org.simantics.db.common.utils.ListUtils.create(graph, java.util.Collections.singletonList(child.getData()));");
- fw.delayedWriter.println(" graph.claim(element.getData(),"+ontShort+getName(parent)+"_has"+refName + "_List,list);");
- fw.delayedWriter.println(" } else {");
- fw.delayedWriter.println(" org.simantics.db.common.utils.ListUtils.insertBack(graph, list, java.util.Collections.singletonList(child.getData()));");
- fw.delayedWriter.println(" }");
+ fw.delayedWriter.println(" element.registerListChild(" + ontShort+getName(parent)+"_has"+refName + "_List, child);");
+// fw.delayedWriter.println(" Resource list = graph.getPossibleObject(element.getData(),"+ontShort+getName(parent)+"_has"+refName + "_List);");
+// fw.delayedWriter.println(" if (list == null) {");
+// fw.delayedWriter.println(" list = org.simantics.db.common.utils.ListUtils.create(graph, java.util.Collections.singletonList(child.getData()));");
+// fw.delayedWriter.println(" graph.claim(element.getData(),"+ontShort+getName(parent)+"_has"+refName + "_List,list);");
+// fw.delayedWriter.println(" } else {");
+// fw.delayedWriter.println(" org.simantics.db.common.utils.ListUtils.insertBack(graph, list, java.util.Collections.singletonList(child.getData()));");
+// fw.delayedWriter.println(" }");
fw.delayedWriter.println(" }");
}
if (useOriginalList) {
// generic list
fw.delayedWriter.println(" {");
fw.delayedWriter.println(" XMLResource XML = XMLResource.getInstance(graph);");
- fw.delayedWriter.println(" Resource list = graph.getPossibleObject(element.getData(), XML.hasOriginalElementList);");
- fw.delayedWriter.println(" if (list == null) {");
- fw.delayedWriter.println(" list = org.simantics.db.common.utils.ListUtils.create(graph, java.util.Collections.singletonList(child.getData()));");
- fw.delayedWriter.println(" graph.claim(element.getData(), XML.hasOriginalElementList,list);");
- fw.delayedWriter.println(" } else {");
- fw.delayedWriter.println(" org.simantics.db.common.utils.ListUtils.insertBack(graph, list, java.util.Collections.singletonList(child.getData()));");
- fw.delayedWriter.println(" }");
+ fw.delayedWriter.println(" element.registerListChild(XML.hasOriginalElementList, child);");
+// fw.delayedWriter.println(" Resource list = graph.getPossibleObject(element.getData(), XML.hasOriginalElementList);");
+// fw.delayedWriter.println(" if (list == null) {");
+// fw.delayedWriter.println(" list = org.simantics.db.common.utils.ListUtils.create(graph, java.util.Collections.singletonList(child.getData()));");
+// fw.delayedWriter.println(" graph.claim(element.getData(), XML.hasOriginalElementList,list);");
+// fw.delayedWriter.println(" } else {");
+// fw.delayedWriter.println(" org.simantics.db.common.utils.ListUtils.insertBack(graph, list, java.util.Collections.singletonList(child.getData()));");
+// fw.delayedWriter.println(" }");
fw.delayedWriter.println(" }");
}