]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.document.linking.ui/src/org/simantics/document/linking/report/templates/CompleteStructureWriter.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.document.linking.ui / src / org / simantics / document / linking / report / templates / CompleteStructureWriter.java
index 7cf01f887f2d7527b635a186aa1a6966a21cb003..dd4de82204f125e6cd02b36e2bf7407cffe2f663 100644 (file)
-package org.simantics.document.linking.report.templates;\r
-\r
-import java.util.Collections;\r
-import java.util.Comparator;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.utils.NameUtils;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.document.DocumentResource;\r
-import org.simantics.document.linking.ontology.DocumentLink;\r
-import org.simantics.document.linking.report.Document;\r
-import org.simantics.document.linking.report.DocumentTitlePage;\r
-import org.simantics.document.linking.report.RowContentProvider;\r
-import org.simantics.document.linking.report.Table;\r
-import org.simantics.document.linking.report.TableOfContents;\r
-import org.simantics.document.linking.report.TextItem;\r
-import org.simantics.document.linking.utils.SourceLinkUtil;\r
-\r
-/**\r
- *  ? Configuration folder 1\r
- *    \95 Diagram 1\r
- *        o Link1: Document information\r
- *        o Link2: Document information\r
- *        o Link3: Document information\r
- *        o Module 1\r
- *            ? Link4: Document information\r
- *            ? Link5: Document information\r
- *            ? Attribute 1\r
- *                ? Link6: Document information\r
- *            ? Attribute 2\r
- *                ? Link7: Document information\r
- *                ? Link8: Document information\r
- *        o Module 2\r
- *            ? Link9: Document information\r
- *            \r
- * @author Marko Luukkainen <marko.luukkainen@vtt.fi>\r
- *\r
- */\r
-public class CompleteStructureWriter extends IndexQueryReport {\r
-               ReadGraph graph;\r
-               Resource model;\r
-               Map<Object, Object> context;\r
-               DocumentLink sl;\r
-               DocumentResource doc;\r
-               ResourceNameComparator parentComparator;\r
-               Comparator<Resource> hierarchyComparator;\r
-               \r
-               @Override\r
-               public String getName() {\r
-                       return "Complete Structure";\r
-               }\r
-               \r
-               @Override\r
-               public void sort(List<Resource> list) throws DatabaseException{\r
-                       Collections.sort(list, parentComparator);\r
-               }\r
-               \r
-               @Override\r
-               public void start(final ReadGraph graph, final Resource model, Document writer, Map<Object, Object> context) throws Exception{\r
-                       super.start(graph, model, writer, context);\r
-                       this.context = context;\r
-                       DocumentTitlePage titlePage = writer.newElement(DocumentTitlePage.class);\r
-                       titlePage.writeTitle(graph, context);\r
-                       writer.newElement(TableOfContents.class);\r
-                       Table table = writer.newElement(Table.class,Document.TOC);\r
-                       \r
-                       table.addColumn("Name", 0.2);\r
-                       table.addColumn("Attribute", 0.2);\r
-                       table.addColumn("Value", 0.15);\r
-                       table.addColumn("Document", 0.2);\r
-                       table.addColumn("Comment", 0.25);\r
-                       \r
-                       //lineWriter.nextPage();\r
-                       \r
-                       this.graph = graph;\r
-                       this.sl = DocumentLink.getInstance(graph);\r
-                       this.doc = DocumentResource.getInstance(graph);\r
-                       this.model = model;\r
-                       \r
-                       \r
-                       \r
-                       parentComparator = new SourceParentHierarchyWithPropComparator(graph,model);\r
-                       hierarchyComparator = new SourceParentDiagramComparator(graph,model);\r
-                               \r
-                       clearProviders();\r
-                       addLineProvider(new HierarchyProvider());\r
-                       addCellProvider(new LinkCellProvider());\r
-                       \r
-               }\r
-               \r
-               private class HierarchyProvider implements RowContentProvider<Resource> {\r
-                       \r
-                       @Override\r
-                       public void setText(Document writer, Resource previous, Resource current, Resource next, TextItem[] row) throws Exception {\r
-                               boolean writeHierarchy = false;\r
-                               if (previous == null)\r
-                                       writeHierarchy = true;\r
-                               else  {\r
-                                       if (hierarchyComparator.compare(previous, current) != 0)\r
-                                               writeHierarchy = true;\r
-                               }\r
-                               if (writeHierarchy) {\r
-                                       Resource obj = graph.getPossibleObject(current, sl.hasSource_Inverse);\r
-                                       Table table = writer.getCurrentElement(Table.class);\r
-\r
-                                       if (writer.getCurrentLine() > 2) {\r
-                                               writer.nextPage();\r
-                                               table = writer.nextElement(Table.class,Document.TOC);\r
-                                       }\r
-                                       \r
-                                       if (obj != null) {\r
-                                               String text = "";\r
-                                               List<Resource> path = SourceLinkUtil.getDiagramPath(graph, model, obj);\r
-                                               \r
-                                               if (path == null) {\r
-                                                       path = parentComparator.getPath(obj);\r
-                                                       for (int i = 0 ; i < path.size()-1; i++) {\r
-                                                               Resource r = path.get(i);\r
-                                                               text += parentComparator.getText(r);\r
-                                                               if (i < path.size()-2)\r
-                                                                       text += "/";\r
-                                                       }\r
-                                               } else {\r
-                                                       for (int i = 0 ; i < path.size(); i++) {\r
-                                                               Resource r = path.get(i);\r
-                                                               text += parentComparator.getText(r);\r
-                                                               if (i < path.size()-1)\r
-                                                                       text += "/";\r
-                                                       }\r
-                                               }\r
-                                               //row[0] = text;\r
-                                               table.setTitle(text);\r
-                                               \r
-                                               TableOfContents toc = writer.getCurrentElement(TableOfContents.class);\r
-                                               toc.addTocElement(text, table);\r
-                                       } else {\r
-                                               //row[0] =  "Hierarchy missing";\r
-                                               table.setTitle("Hierarchy missing");\r
-                                       }\r
-                               }\r
-                       }\r
-               }\r
-               \r
-               private class LinkCellProvider implements RowContentProvider<Resource> {\r
-                       @Override\r
-                       public void setText(Document writer, Resource previous, Resource source, Resource next, TextItem[] text)\r
-                                       throws Exception {\r
-                               Resource holder = graph.getSingleObject(source, sl.hasSource_Inverse);\r
-                               String holderName = NameUtils.getSafeLabel(graph, holder);\r
-                               if (holderName.length() == 0)\r
-                                       holderName = NameUtils.getSafeName(graph, holder);\r
-                               if (previous == null || !graph.getSingleObject(previous, sl.hasSource_Inverse).equals(graph.getSingleObject(source, sl.hasSource_Inverse))) {\r
-                                       text[0] = writer.newItem(TextItem.class);\r
-                                       text[0].setText(holderName);\r
-                               }\r
-                               if (graph.isInstanceOf(source, sl.FunctionalSource)) {\r
-                                       Resource relation = graph.getPossibleObject(source, sl.consernsRelation);\r
-                                       text[1] = writer.newItem(TextItem.class);\r
-                                       if (relation != null) {\r
-                                               String relationName = NameUtils.getSafeLabel(graph, relation);\r
-                                               if (relationName.length() == 0)\r
-                                                       relationName = NameUtils.getSafeName(graph, relation);\r
-                                               Object value = graph.getPossibleRelatedValue(holder, relation);\r
-                                               text[1].setText(relationName);\r
-                                               if (value != null) {\r
-                                                       text[2] = writer.newItem(TextItem.class);\r
-                                                       text[2].setText(SourceLinkUtil.getValueString(value));\r
-                                               }\r
-                                       } else {\r
-                                               text[1].setText("Error in property reference");\r
-                                       }\r
-                               }\r
-                               Resource document = SourceLinkUtil.getReferredDocument(graph, source);\r
-                               if (document != null) {\r
-                                       text[3] = getDocumentItem(document);\r
-                               } else {\r
-                                       text[3] = getNonExistingDocumentItem();\r
-                               }\r
-                               \r
-                               String comment = graph.getPossibleRelatedValue(source, sl.hasSourceComment);\r
-                               if (comment != null) {\r
-                                       text[4] = writer.newItem(TextItem.class);\r
-                                       text[4].setText(comment);\r
-                               }\r
-\r
-                       }\r
-               }\r
+package org.simantics.document.linking.report.templates;
+
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.utils.NameUtils;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.document.DocumentResource;
+import org.simantics.document.linking.ontology.DocumentLink;
+import org.simantics.document.linking.report.Document;
+import org.simantics.document.linking.report.DocumentTitlePage;
+import org.simantics.document.linking.report.RowContentProvider;
+import org.simantics.document.linking.report.Table;
+import org.simantics.document.linking.report.TableOfContents;
+import org.simantics.document.linking.report.TextItem;
+import org.simantics.document.linking.utils.SourceLinkUtil;
+
+/**
+ *  ? Configuration folder 1
+ *    \95 Diagram 1
+ *        o Link1: Document information
+ *        o Link2: Document information
+ *        o Link3: Document information
+ *        o Module 1
+ *            ? Link4: Document information
+ *            ? Link5: Document information
+ *            ? Attribute 1
+ *                ? Link6: Document information
+ *            ? Attribute 2
+ *                ? Link7: Document information
+ *                ? Link8: Document information
+ *        o Module 2
+ *            ? Link9: Document information
+ *            
+ * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
+ *
+ */
+public class CompleteStructureWriter extends IndexQueryReport {
+               ReadGraph graph;
+               Resource model;
+               Map<Object, Object> context;
+               DocumentLink sl;
+               DocumentResource doc;
+               ResourceNameComparator parentComparator;
+               Comparator<Resource> hierarchyComparator;
+               
+               @Override
+               public String getName() {
+                       return "Complete Structure";
+               }
+               
+               @Override
+               public void sort(List<Resource> list) throws DatabaseException{
+                       Collections.sort(list, parentComparator);
+               }
+               
+               @Override
+               public void start(final ReadGraph graph, final Resource model, Document writer, Map<Object, Object> context) throws Exception{
+                       super.start(graph, model, writer, context);
+                       this.context = context;
+                       DocumentTitlePage titlePage = writer.newElement(DocumentTitlePage.class);
+                       titlePage.writeTitle(graph, context);
+                       writer.newElement(TableOfContents.class);
+                       Table table = writer.newElement(Table.class,Document.TOC);
+                       
+                       table.addColumn("Name", 0.2);
+                       table.addColumn("Attribute", 0.2);
+                       table.addColumn("Value", 0.15);
+                       table.addColumn("Document", 0.2);
+                       table.addColumn("Comment", 0.25);
+                       
+                       //lineWriter.nextPage();
+                       
+                       this.graph = graph;
+                       this.sl = DocumentLink.getInstance(graph);
+                       this.doc = DocumentResource.getInstance(graph);
+                       this.model = model;
+                       
+                       
+                       
+                       parentComparator = new SourceParentHierarchyWithPropComparator(graph,model);
+                       hierarchyComparator = new SourceParentDiagramComparator(graph,model);
+                               
+                       clearProviders();
+                       addLineProvider(new HierarchyProvider());
+                       addCellProvider(new LinkCellProvider());
+                       
+               }
+               
+               private class HierarchyProvider implements RowContentProvider<Resource> {
+                       
+                       @Override
+                       public void setText(Document writer, Resource previous, Resource current, Resource next, TextItem[] row) throws Exception {
+                               boolean writeHierarchy = false;
+                               if (previous == null)
+                                       writeHierarchy = true;
+                               else  {
+                                       if (hierarchyComparator.compare(previous, current) != 0)
+                                               writeHierarchy = true;
+                               }
+                               if (writeHierarchy) {
+                                       Resource obj = graph.getPossibleObject(current, sl.hasSource_Inverse);
+                                       Table table = writer.getCurrentElement(Table.class);
+
+                                       if (writer.getCurrentLine() > 2) {
+                                               writer.nextPage();
+                                               table = writer.nextElement(Table.class,Document.TOC);
+                                       }
+                                       
+                                       if (obj != null) {
+                                               String text = "";
+                                               List<Resource> path = SourceLinkUtil.getDiagramPath(graph, model, obj);
+                                               
+                                               if (path == null) {
+                                                       path = parentComparator.getPath(obj);
+                                                       for (int i = 0 ; i < path.size()-1; i++) {
+                                                               Resource r = path.get(i);
+                                                               text += parentComparator.getText(r);
+                                                               if (i < path.size()-2)
+                                                                       text += "/";
+                                                       }
+                                               } else {
+                                                       for (int i = 0 ; i < path.size(); i++) {
+                                                               Resource r = path.get(i);
+                                                               text += parentComparator.getText(r);
+                                                               if (i < path.size()-1)
+                                                                       text += "/";
+                                                       }
+                                               }
+                                               //row[0] = text;
+                                               table.setTitle(text);
+                                               
+                                               TableOfContents toc = writer.getCurrentElement(TableOfContents.class);
+                                               toc.addTocElement(text, table);
+                                       } else {
+                                               //row[0] =  "Hierarchy missing";
+                                               table.setTitle("Hierarchy missing");
+                                       }
+                               }
+                       }
+               }
+               
+               private class LinkCellProvider implements RowContentProvider<Resource> {
+                       @Override
+                       public void setText(Document writer, Resource previous, Resource source, Resource next, TextItem[] text)
+                                       throws Exception {
+                               Resource holder = graph.getSingleObject(source, sl.hasSource_Inverse);
+                               String holderName = NameUtils.getSafeLabel(graph, holder);
+                               if (holderName.length() == 0)
+                                       holderName = NameUtils.getSafeName(graph, holder);
+                               if (previous == null || !graph.getSingleObject(previous, sl.hasSource_Inverse).equals(graph.getSingleObject(source, sl.hasSource_Inverse))) {
+                                       text[0] = writer.newItem(TextItem.class);
+                                       text[0].setText(holderName);
+                               }
+                               if (graph.isInstanceOf(source, sl.FunctionalSource)) {
+                                       Resource relation = graph.getPossibleObject(source, sl.consernsRelation);
+                                       text[1] = writer.newItem(TextItem.class);
+                                       if (relation != null) {
+                                               String relationName = NameUtils.getSafeLabel(graph, relation);
+                                               if (relationName.length() == 0)
+                                                       relationName = NameUtils.getSafeName(graph, relation);
+                                               Object value = graph.getPossibleRelatedValue(holder, relation);
+                                               text[1].setText(relationName);
+                                               if (value != null) {
+                                                       text[2] = writer.newItem(TextItem.class);
+                                                       text[2].setText(SourceLinkUtil.getValueString(value));
+                                               }
+                                       } else {
+                                               text[1].setText("Error in property reference");
+                                       }
+                               }
+                               Resource document = SourceLinkUtil.getReferredDocument(graph, source);
+                               if (document != null) {
+                                       text[3] = getDocumentItem(document);
+                               } else {
+                                       text[3] = getNonExistingDocumentItem();
+                               }
+                               
+                               String comment = graph.getPossibleRelatedValue(source, sl.hasSourceComment);
+                               if (comment != null) {
+                                       text[4] = writer.newItem(TextItem.class);
+                                       text[4].setText(comment);
+                               }
+
+                       }
+               }
        }
\ No newline at end of file