Bundle-ActivationPolicy: lazy
Export-Package: org.simantics.interop.issues,
org.simantics.interop.stubs,
- org.simantics.interop.test
+ org.simantics.interop.test,
+ org.simantics.interop.utils
private List<Resource> traversed = new ArrayList<Resource>(); // list of relations that are traversed (and tested)\r
private List<Resource> tested = new ArrayList<Resource>(); // list of relations that are tested, but not traversed\r
private List<Resource> nonTraversed = new ArrayList<Resource>(); // list of relations that are not traversed\r
+ private List<Resource> nonTested = new ArrayList<Resource>(); // list of relations that are not tested\r
\r
private List<Statement> changes1 = new ArrayList<Statement>();\r
private List<Statement> changes2 = new ArrayList<Statement>();\r
private Set<Statement> changes2Set = new HashSet<Statement>();\r
private Set<Pair<Statement,Statement>> modificationsSet = new HashSet<Pair<Statement,Statement>>();\r
\r
- private BijectionMap<Statement, Statement> comparable = new BijectionMap<Statement, Statement>();\r
+ private BijectionMap<Statement, Statement> comparableStatements = new BijectionMap<Statement, Statement>();\r
+ private BijectionMap<Resource, Resource> comparableResources = new BijectionMap<Resource, Resource>();\r
\r
\r
// runtime attributes\r
tested.addAll(rels);\r
}\r
\r
+ public void addNonTested(Resource rel) {\r
+ nonTested.add(rel);\r
+ }\r
+ \r
+ public void addNonTested(Collection<Resource> rels) {\r
+ nonTested.addAll(rels);\r
+ }\r
+ \r
public void clearRels() {\r
traversed.clear();\r
tested.clear();\r
changes1.clear();\r
changes2.clear();\r
modifications.clear();\r
+ comparableResources.clear();\r
\r
Stack<Resource> stack1 = new Stack<Resource>();\r
Stack<Resource> stack2 = new Stack<Resource>();\r
stack1.push(r1);\r
stack2.push(r2);\r
\r
+ \r
List<Statement> ss1 = new ArrayList<Statement>();\r
List<Statement> ss2 = new ArrayList<Statement>();\r
\r
while (!stack1.isEmpty()) {\r
r1 = stack1.pop();\r
r2 = stack2.pop();\r
+ \r
+ if (comparableResources.contains(r1, r2)) {\r
+ System.out.println("already tested " + NameUtils.getSafeName(g, r1) + " " + NameUtils.getSafeName(g, r2));\r
+ continue;\r
+ }\r
+ comparableResources.map(r1, r2);\r
\r
System.out.println("test " + NameUtils.getSafeName(g, r1) + " " + NameUtils.getSafeName(g, r2));\r
compareProps(r1, r2);\r
ss2 = filterAsserted(r2, ss2);\r
ss1 = filterTraversed(ss1);\r
ss2 = filterTraversed(ss2);\r
+ ss1 = filterNonTested(ss1);\r
+ ss2 = filterNonTested(ss2);\r
\r
compareStatement(ss1, ss2, null, null);\r
ss1.clear();\r
\r
\r
\r
- public BijectionMap<Statement, Statement> getComparable() {\r
- return comparable;\r
+ public BijectionMap<Statement, Statement> getComparableStatements() {\r
+ return comparableStatements;\r
}\r
\r
public GraphChanges getChanges() {\r
return NameUtils.getSafeName(graph, s.getSubject()) + " " + NameUtils.getSafeName(graph, s.getPredicate()) + " " + NameUtils.getSafeName(graph, s.getObject());\r
}\r
\r
- private List<Statement> filterTraversed(Collection<Statement> in) throws ServiceException {\r
+ private List<Statement> filterTraversed(List<Statement> in) throws ServiceException {\r
+ return filter(traversed, in);\r
+ }\r
+ \r
+ private List<Statement> filterNonTested(List<Statement> in) throws ServiceException {\r
+ return filter(nonTested, in);\r
+ }\r
+ \r
+ private List<Statement> filter(Collection<Resource> toFilter, List<Statement> in) throws ServiceException {\r
+ if (toFilter.size() == 0)\r
+ return in;\r
List<Statement> out = new ArrayList<Statement>();\r
for (Statement s : in) {\r
boolean usable = true;\r
- for (Resource r : traversed) {\r
+ for (Resource r : toFilter) {\r
if (g.isSubrelationOf(s.getPredicate(),r)) {\r
usable = false;\r
break;\r
diff.add(Integer.MAX_VALUE);\r
continue;\r
}\r
- diff.add(propsDiffCount(s1.getObject(), s2.getObject()));\r
+ if (comparableResources.contains(s1.getObject(), s2.getObject()))\r
+ diff.add(-1);\r
+ else\r
+ diff.add(propsDiffCount(s1.getObject(), s2.getObject()));\r
}\r
differences.add(diff);\r
}\r
continue;\r
used1[i1] = true;\r
used2[i2] = true;\r
+ Statement s1 = ss1.get(i1+off1);\r
+ Statement s2 = ss2.get(i2+off2);\r
+ \r
if (stack1 != null) {\r
- stack1.add(ss1.get(i1+off1).getObject());\r
- stack2.add(ss2.get(i2+off2).getObject());\r
+ \r
+ stack1.add(s1.getObject());\r
+ stack2.add(s2.getObject());\r
+ \r
} else {\r
// TODO : how should we report non traversed differences\r
// using compareProps assumes that referenced objects are the same (references are not different)\r
// modifies.add(new Pair<Statement, Statement>(ss1.get(i1+off1), ss2.get(i2+off2)));\r
// }\r
}\r
+ comparableStatements.map(s1, s2);\r
+ //comparableResources.map(s1.getObject(), s2.getObject());\r
break;\r
}\r
}\r
//changes1.add(s1);\r
//changes2.add(s2);\r
addModification(s1, s2);\r
- comparable.map(s1, s2);\r
+ comparableStatements.map(s1, s2);\r
+ comparableResources.map(s1.getObject(),s2.getObject());\r
}\r
} else {\r
compareProps(s1.getObject(), s2.getObject());\r
//changes1.add(s1);\r
//changes2.add(s2);\r
addModification(s1, s2);\r
- comparable.map(s1, s2);\r
+ comparableStatements.map(s1, s2);\r
+ comparableResources.map(s1.getObject(),s2.getObject());\r
}\r
i1++;\r
i2++;\r
comparator.clearRels();\r
Layer0 l0 = Layer0.getInstance(graph);\r
comparator.addTraversed(l0.ConsistsOf);\r
+ comparator.addTraversed(l0.HasNext);\r
comparator.addTested(l0.IsWeaklyRelatedTo);\r
comparator.test(graph, r1, r2);\r
- BijectionMap<Statement, Statement> map = comparator.getComparable();\r
+ BijectionMap<Statement, Statement> map = comparator.getComparableStatements();\r
Map<Statement, Integer> indices = new HashMap<Statement, Integer>();\r
final StringBuilder sb1 = new StringBuilder();\r
final StringBuilder sb2 = new StringBuilder();\r
--- /dev/null
+package org.simantics.interop.utils;\r
+\r
+import org.eclipse.jface.viewers.CellLabelProvider;\r
+import org.eclipse.jface.viewers.ContentViewer;\r
+import org.eclipse.jface.viewers.IBaseLabelProvider;\r
+import org.eclipse.jface.viewers.ILabelProvider;\r
+import org.eclipse.jface.viewers.ITableLabelProvider;\r
+import org.eclipse.jface.viewers.TableViewer;\r
+import org.eclipse.jface.viewers.Viewer;\r
+import org.eclipse.jface.viewers.ViewerComparator;\r
+\r
+public class StringColumnComparator extends ViewerComparator {\r
+ private int propertyIndex;\r
+ private static final int DESCENDING = 1;\r
+ private int direction = DESCENDING;\r
+ \r
+ public StringColumnComparator() {\r
+ this.propertyIndex = 0;\r
+ this.direction = DESCENDING;\r
+ }\r
+ \r
+ public void setColumnt(int column) {\r
+ if (column == this.propertyIndex) {\r
+ direction = 1-direction;\r
+ } else {\r
+ this.propertyIndex = column;\r
+ direction = DESCENDING;\r
+ }\r
+ }\r
+ \r
+ @Override\r
+ public int compare(Viewer viewer, Object e1, Object e2) {\r
+ \r
+ \r
+ int cat1 = category(e1);\r
+ int cat2 = category(e2);\r
+\r
+ if (cat1 != cat2) {\r
+ return cat1 - cat2;\r
+ }\r
+ \r
+ String name1 = null;\r
+ String name2 = null;\r
+ \r
+ \r
+ \r
+ if (viewer == null || !(viewer instanceof ContentViewer)) {\r
+ name1 = e1.toString();\r
+ name2 = e2.toString();\r
+ } else {\r
+ IBaseLabelProvider prov = ((ContentViewer) viewer).getLabelProvider();\r
+ if (viewer instanceof TableViewer && ((TableViewer)viewer).getLabelProvider(propertyIndex) != null) {\r
+ CellLabelProvider clp = ((TableViewer)viewer).getLabelProvider(propertyIndex);\r
+ if (clp instanceof ILabelProvider) {\r
+ ILabelProvider ilb = (ILabelProvider)clp;\r
+ name1 = ilb.getText(e1);\r
+ name2 = ilb.getText(e2);\r
+ }\r
+ }\r
+ if (name1 == null) {\r
+ if (prov instanceof ITableLabelProvider) {\r
+ ITableLabelProvider lprov = (ITableLabelProvider) prov;\r
+ name1 = lprov.getColumnText(e1,propertyIndex);\r
+ name2 = lprov.getColumnText(e2,propertyIndex);\r
+ } else if (prov instanceof ILabelProvider) {\r
+ ILabelProvider lprov = (ILabelProvider) prov;\r
+ name1 = lprov.getText(e1);\r
+ name2 = lprov.getText(e2);\r
+ } else {\r
+ name1 = e1.toString();\r
+ name2 = e2.toString();\r
+ }\r
+ }\r
+ }\r
+ if (name1 == null) {\r
+ name1 = "";//$NON-NLS-1$\r
+ }\r
+ if (name2 == null) {\r
+ name2 = "";//$NON-NLS-1$\r
+ }\r
+\r
+ // use the comparator to compare the strings\r
+ int rc = getComparator().compare(name1, name2);\r
+ if (direction != DESCENDING)\r
+ rc = -rc;\r
+ return rc;\r
+ }\r
+ \r
+}\r
+\r
--- /dev/null
+package org.simantics.interop.utils;\r
+\r
+import org.eclipse.jface.viewers.TableViewer;\r
+import org.eclipse.jface.viewers.TableViewerColumn;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.events.SelectionAdapter;\r
+import org.eclipse.swt.events.SelectionEvent;\r
+import org.eclipse.swt.widgets.TableColumn;\r
+\r
+public class TableUtils {\r
+ public static TableViewerColumn addColumn(final TableViewer viewer, String text, boolean resize, boolean sort, int width) {\r
+ final TableViewerColumn twc = new TableViewerColumn(viewer, SWT.NONE);\r
+ final TableColumn tc = twc.getColumn();\r
+ //final TableColumn tc = new TableColumn(viewer.getTable(), SWT.NONE);\r
+ tc.setText(text);\r
+ tc.setResizable(resize);\r
+ tc.setWidth(width);\r
+ if (sort) {\r
+ tc.addSelectionListener(new SelectionAdapter() {\r
+ @Override\r
+ public void widgetSelected(SelectionEvent e) {\r
+ StringColumnComparator comparator = (StringColumnComparator)viewer.getComparator();\r
+ //TableColumn tc = twc.getColumn();\r
+ TableColumn tcs[] = viewer.getTable().getColumns();\r
+ int index = -1;\r
+ for (int i = 0; i <tcs.length; i++) {\r
+ if (tcs[i].equals(tc)) {\r
+ index = i;\r
+ break;\r
+ }\r
+ }\r
+ if (index == -1)\r
+ return;\r
+ comparator.setColumnt(index);\r
+ \r
+ int dir = viewer.getTable().getSortDirection();\r
+ if (viewer.getTable().getSortColumn() == tc) {\r
+ dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;\r
+ } else {\r
+ \r
+ dir = SWT.DOWN;\r
+ }\r
+ viewer.getTable().setSortDirection(dir);\r
+ viewer.getTable().setSortColumn(tc);\r
+ viewer.refresh();\r
+ }\r
+ });\r
+ }\r
+ return twc;\r
+ }\r
+}\r