]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.debug.browser/src/org/simantics/debug/browser/internal/rewriters/RawStatementsCreator.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.debug.browser / src / org / simantics / debug / browser / internal / rewriters / RawStatementsCreator.java
diff --git a/bundles/org.simantics.debug.browser/src/org/simantics/debug/browser/internal/rewriters/RawStatementsCreator.java b/bundles/org.simantics.debug.browser/src/org/simantics/debug/browser/internal/rewriters/RawStatementsCreator.java
new file mode 100644 (file)
index 0000000..5908fd3
--- /dev/null
@@ -0,0 +1,55 @@
+/*******************************************************************************\r
+ * Copyright (c) 2016 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     THTH ry - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.debug.browser.internal.rewriters;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.Statement;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.debug.browser.content.ResourceBrowserContent;\r
+import org.simantics.debug.browser.content.ResourceBrowserRewriter;\r
+import org.simantics.debug.browser.sections.PageHeaderSection;\r
+import org.simantics.debug.browser.sections.RawStatementsSection;\r
+\r
+public enum RawStatementsCreator implements ResourceBrowserRewriter {\r
+    INSTANCE;\r
+\r
+    @Override\r
+    public void rewrite(ReadGraph graph, ResourceBrowserContent content) throws DatabaseException {\r
+        RawStatementsSection section = new RawStatementsSection();\r
+        section.resource = content.resource;\r
+        for(Resource predicate : graph.getPredicates(content.resource)) {\r
+            Collection<Statement> statements = graph.getStatements(content.resource, predicate);\r
+            ArrayList<Statement> filteredStatements = new ArrayList<Statement>(statements.size());\r
+            for(Statement statement : statements)\r
+                if(statement.getPredicate().equals(predicate))\r
+                    filteredStatements.add(statement);\r
+            section.statementsByPredicates.put(predicate, filteredStatements);\r
+        }\r
+        content.putSection(RawStatementsSection.class, section);\r
+\r
+        // Add custom CSS to header\r
+        PageHeaderSection hdr = content.getSection(PageHeaderSection.class);\r
+        hdr.getHeadWriter().println("<link rel=\"stylesheet\" type=\"text/css\" href=\"/css/lookupSection.css\" />");\r
+        hdr.getHeadWriter().println("<link rel=\"stylesheet\" type=\"text/css\" href=\"/css/rawStatements.css\" />");\r
+        hdr.getHeadWriter().println("<link rel=\"stylesheet\" type=\"text/css\" href=\"/css/blue/style.css\" />");\r
+    }\r
+\r
+    @Override\r
+    public double getPriority() {\r
+        return 0;\r
+    }\r
+\r
+}\r