1 package org.simantics.interop.update.model;
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.HashSet;
8 import org.simantics.db.Resource;
9 import org.simantics.db.exception.DatabaseException;
10 import org.simantics.interop.test.GraphChanges;
12 public class UpdateNode3 {
18 private Collection<UpdateNode3> children = new ArrayList<UpdateNode3>();
21 public Collection<UpdateNode3> getChildren() {
25 public UpdateNode getUn1() {
29 public UpdateNode getUn2() {
33 public UpdateNode getUn3() {
37 public UpdateNode3(UpdateNode un1, UpdateNode un2, UpdateNode un3) {
43 public boolean isVisible() {
45 return un1.isVisible();
47 return un2.isVisible();
49 return un3.isVisible();
53 public void setVisible(boolean visible) {
55 un1.setVisible(visible);
57 un2.setVisible(visible);
59 un3.setVisible(visible);
63 public static UpdateNode3 getCombinedTree(ModelUpdate update) throws DatabaseException {
64 UpdateTree updateTree1 = update.getUpdateTree();
65 UpdateTree updateTree2 = update.getUpdateTree2();
66 UpdateTree updateTree3 = update.getUpdateTree3();
68 UpdateNode3 n3 = new UpdateNode3(updateTree1.getRootNode(), updateTree2.getRootNode(), updateTree3.getRootNode());
70 populate(n3, update.getChanges(), update.getChanges2(), update.getChanges3());
74 private static void populate(UpdateNode3 un, GraphChanges gc1, GraphChanges gc2, GraphChanges gc3) {
75 Set<UpdateNode> p1 = new HashSet<>();
76 Set<UpdateNode> p2 = new HashSet<>();
77 Set<UpdateNode> p3 = new HashSet<>();
79 if (un.getUn1() != null) {
80 for (UpdateNode n1 : un.getUn1().getChildren()) {
83 if (un.getUn2() != null)
84 n2 = getMathcing(n1, un.getUn2().getChildren(), gc1);
86 if (un.getUn3() != null) {
87 n3 = getMathcing(n1, un.getUn3().getChildren(), gc2);
88 if (n3 == null && n2 != null)
89 n3 = getMathcing(n2, un.getUn3().getChildren(), gc3);
91 UpdateNode3 cn = new UpdateNode3(n1, n2, n3);
93 populate(cn, gc1, gc2, gc3);
101 if (un.getUn2() != null) {
102 for (UpdateNode n2 : un.getUn2().getChildren()) {
107 UpdateNode n3 = null;
108 if (un.getUn3() != null) {
109 n3 = getMathcing(n2, un.getUn3().getChildren(), gc3);
111 UpdateNode3 cn = new UpdateNode3(null, n2, n3);
113 populate(cn, gc1, gc2, gc3);
119 if (un.getUn3() != null) {
120 for (UpdateNode n3 : un.getUn3().getChildren()) {
124 UpdateNode3 cn = new UpdateNode3(null, null, n3);
126 populate(cn, gc1, gc2, gc3);
131 private static UpdateNode getMathcing(UpdateNode n , Collection<UpdateNode> coll, GraphChanges gc) {
132 if (n.getResource() == null) {
133 if (coll.size() != 1)
135 UpdateNode n2 = coll.iterator().next();
136 if (n2.getClass() != n.getClass())
140 Resource o = gc.getComparable().getLeft(n.getResource());
142 o = gc.getComparable().getRight(n.getResource());
145 for (UpdateNode c : coll) {
146 if (o.equals(c.getResource()))