]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.document.ui/src/org/simantics/document/ui/function/All.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.document.ui / src / org / simantics / document / ui / function / All.java
diff --git a/bundles/org.simantics.document.ui/src/org/simantics/document/ui/function/All.java b/bundles/org.simantics.document.ui/src/org/simantics/document/ui/function/All.java
new file mode 100644 (file)
index 0000000..20b8d3d
--- /dev/null
@@ -0,0 +1,819 @@
+/*******************************************************************************\r
+ * Copyright (c) 2012 Association for Decentralized Information Management in\r
+ * 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
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.document.ui.function;\r
+\r
+import java.util.TreeMap;\r
+\r
+import org.eclipse.jface.viewers.ISelectionProvider;\r
+import org.eclipse.jface.viewers.StructuredSelection;\r
+import org.eclipse.swt.graphics.FontData;\r
+import org.eclipse.swt.graphics.Point;\r
+import org.eclipse.swt.graphics.RGB;\r
+import org.eclipse.swt.widgets.Display;\r
+import org.eclipse.swt.widgets.Event;\r
+import org.eclipse.swt.widgets.FontDialog;\r
+import org.eclipse.swt.widgets.TreeItem;\r
+import org.eclipse.ui.PartInitException;\r
+import org.eclipse.ui.PlatformUI;\r
+import org.simantics.Simantics;\r
+import org.simantics.browsing.ui.BuiltinKeys;\r
+import org.simantics.browsing.ui.NodeContext;\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.ReadRequest;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.common.utils.Logger;\r
+import org.simantics.db.common.utils.NameUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.adapter.Instances;\r
+import org.simantics.db.layer0.request.PossibleModel;\r
+import org.simantics.db.layer0.util.RemoverUtil;\r
+import org.simantics.db.layer0.variable.RVI;\r
+import org.simantics.db.layer0.variable.Variable;\r
+import org.simantics.document.DocumentResource;\r
+import org.simantics.document.DocumentUtils;\r
+import org.simantics.document.ui.CSSEditor;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.scenegraph.INode;\r
+import org.simantics.scenegraph.loader.ScenegraphLoaderProcess;\r
+import org.simantics.scenegraph.loader.ScenegraphLoaderUtils;\r
+import org.simantics.scenegraph.loader.ScenegraphLoaderUtils.ScenegraphPropertyReference;\r
+import org.simantics.scl.reflection.annotations.SCLValue;\r
+import org.simantics.scl.runtime.function.FunctionImpl1;\r
+import org.simantics.scl.runtime.function.FunctionImpl3;\r
+import org.simantics.ui.workbench.ResourceEditorInput2;\r
+import org.simantics.utils.threads.SWTThread;\r
+import org.simantics.utils.ui.workbench.WorkbenchUtils;\r
+\r
+\r
+public class All {\r
+\r
+       private static boolean createDocument(WriteGraph graph, Resource resource, Resource model) throws DatabaseException {\r
+\r
+               Layer0 L0 = Layer0.getInstance(graph);\r
+               DocumentResource DOC = DocumentResource.getInstance(graph);\r
+\r
+               if(graph.hasStatement(resource, DOC.HasDocumentation)) return true;\r
+               \r
+               Instances query = graph.adapt(DOC.DocumentTypeBinding, Instances.class);\r
+               \r
+               TreeMap<Double, Resource> bindings = new TreeMap<Double, Resource>();\r
+               for(Resource binding : query.find(graph, model)) {\r
+                       double priority = graph.getRelatedValue2(binding, DOC.DocumentTypeBinding_priority, Bindings.DOUBLE);\r
+                       Resource type = graph.getSingleObject(binding, DOC.DocumentTypeBinding_HasType);\r
+                       if(graph.isInstanceOf(resource, type)) {\r
+                               bindings.put(priority, binding);\r
+                       }\r
+               }\r
+               \r
+               if(bindings.isEmpty()) return false;\r
+               \r
+               Resource binding = bindings.lastEntry().getValue();\r
+                               \r
+               Resource documentType = graph.getSingleObject(binding, DOC.DocumentTypeBinding_HasDocumentType);\r
+               Resource document = graph.newResource();\r
+               graph.claim(document, L0.InstanceOf, null, DOC.ScenegraphDocument);\r
+               graph.claimLiteral(document, L0.HasName, "Documentation");\r
+               graph.claim(resource, DOC.HasDocumentation, document);\r
+               graph.claim(document, L0.PartOf, resource);\r
+\r
+               Resource scenegraph = graph.newResource();\r
+               graph.claim(scenegraph, L0.InstanceOf, null, documentType);\r
+               graph.claimLiteral(scenegraph, L0.HasName, "Scenegraph");\r
+               graph.claim(scenegraph, L0.PartOf, document);\r
+               graph.claim(document, DOC.ScenegraphDocument_scenegraph, scenegraph);\r
+\r
+               return true;\r
+               \r
+       }\r
+\r
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> b")\r
+    public static Object onCreateDocumentButton(ReadGraph graph, Resource resource, final Variable context) throws DatabaseException {\r
+\r
+       return new FunctionImpl1<Object, Object>() {\r
+\r
+                       @Override\r
+                       public Object apply(Object _o) {\r
+                               \r
+                               Simantics.async(new ReadRequest() {\r
+\r
+                                       @Override\r
+                                       public void run(ReadGraph graph) throws DatabaseException {\r
+                                               \r
+                                       Variable selection = ScenegraphLoaderUtils.getPossibleVariableSelection(graph, context);\r
+                                       if(selection == null) return;\r
+                                       \r
+                                               final Resource input = selection.getRepresents(graph);\r
+                                       if(input == null) return;\r
+                                               \r
+                                       graph.async(new WriteRequest() {\r
+\r
+                                                       @Override\r
+                                                       public void perform(WriteGraph graph) throws DatabaseException {\r
+                                                               \r
+                                                               Resource model = graph.sync(new PossibleModel(input));\r
+                                                               if(model == null) return;\r
+                                                               createDocument(graph, input, model);\r
+                                                               \r
+                                                       }\r
+                                               \r
+                                       });\r
+                                       \r
+                                       }\r
+                                       \r
+                               });\r
+                               \r
+                               return true;\r
+                               \r
+                       }\r
+                       \r
+               };\r
+        \r
+    }\r
+\r
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> b")\r
+    public static Object onDeleteDocumentButton(ReadGraph graph, Resource resource, final Variable context) throws DatabaseException {\r
+\r
+       return new FunctionImpl1<Object, Object>() {\r
+\r
+                       @Override\r
+                       public Object apply(Object _o) {\r
+                               \r
+                               Simantics.async(new ReadRequest() {\r
+\r
+                                       @Override\r
+                                       public void run(ReadGraph graph) throws DatabaseException {\r
+                                               \r
+                                       Variable selection = ScenegraphLoaderUtils.getPossibleVariableSelection(graph, context);\r
+                                       if(selection == null) return;\r
+                                       \r
+                                               final Resource input = selection.getRepresents(graph);\r
+                                       if(input == null) return;\r
+                                       \r
+                                               DocumentResource DOC = DocumentResource.getInstance(graph);\r
+                                               if(!graph.hasStatement(input, DOC.HasDocumentation)) return;\r
+                                               \r
+                                       graph.async(new WriteRequest() {\r
+\r
+                                                       @Override\r
+                                                       public void perform(WriteGraph graph) throws DatabaseException {\r
+                                                               \r
+                                                               DocumentResource DOC = DocumentResource.getInstance(graph);\r
+                                                               Resource document = graph.getPossibleObject(input, DOC.HasDocumentation);\r
+                                                               if(document == null) return;\r
+                                                               \r
+                                                               RemoverUtil.remove(graph, document);\r
+                                                               \r
+                                                       }\r
+                                               \r
+                                       });\r
+                                       \r
+                                       }\r
+                                       \r
+                               });\r
+                               \r
+                               return true;\r
+                               \r
+                       }\r
+                       \r
+               };\r
+        \r
+    }\r
+    \r
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> a")\r
+    public static Object editorLoaded(ReadGraph graph, final Resource resource, final Variable context) throws DatabaseException {\r
+       \r
+       return new FunctionImpl3<WriteGraph, Variable, Variable, Boolean>() {\r
+\r
+                       @Override\r
+                       public Boolean apply(WriteGraph graph, Variable editor, Variable input) {\r
+\r
+//                             try {\r
+//                                     return createDocument(graph, input);\r
+//                             } catch (DatabaseException e) {\r
+//                                     Logger.defaultLogError(e);\r
+//                             }\r
+\r
+                               return true;\r
+                               \r
+                       }\r
+               \r
+       };\r
+       \r
+    }\r
+\r
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> Boolean")\r
+    public static Boolean hasDocument(ReadGraph graph, final Resource resource, final Variable context) throws DatabaseException {\r
+       \r
+               DocumentResource DOC = DocumentResource.getInstance(graph);\r
+               \r
+       Variable selection = ScenegraphLoaderUtils.getPossibleVariableSelection(graph, context);\r
+       if(selection == null) return false;\r
+       \r
+               Resource input = selection.getRepresents(graph);\r
+       if(input == null) return null;\r
+       \r
+               return graph.hasStatement(input, DOC.HasDocumentation);\r
+       \r
+    }\r
+\r
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> a")\r
+    public static Object viewInputChanged(ReadGraph graph, final Resource resource, final Variable context) throws DatabaseException {\r
+       \r
+       return new FunctionImpl1<Variable, Boolean>() {\r
+\r
+                       @Override\r
+                       public Boolean apply(final Variable viewVariable) {\r
+                               return true;\r
+                       }\r
+               \r
+       };\r
+       \r
+    }\r
+    \r
+       \r
+    @SCLValue(type = "ReadGraph -> Variable -> Boolean")\r
+    public static Boolean isWikitext(ReadGraph graph, Variable context) throws DatabaseException {\r
+       Layer0 L0 = Layer0.getInstance(graph);\r
+       DocumentResource DOC = DocumentResource.getInstance(graph);\r
+       Resource p = context.getPossiblePredicateResource(graph);\r
+       if (p == null)\r
+           return Boolean.FALSE;\r
+       Resource range = graph.getPossibleObject(p, L0.HasRange);\r
+       return DOC.WikiDocument_WikiText.equals(range);\r
+    }\r
+    \r
+    private static Variable getDefaultSelection(ReadGraph graph, Variable context) throws DatabaseException {\r
+       \r
+               DocumentResource DOC = DocumentResource.getInstance(graph);\r
+       Variable sel = ScenegraphLoaderUtils.getVariableSelection(graph, context);\r
+       \r
+       Resource represents = sel.getRepresents(graph);\r
+       Resource doc = graph.getSingleObject(represents, DOC.HasDocument);\r
+       Resource scenegraph = graph.getSingleObject(doc, DOC.ScenegraphDocument_scenegraph);\r
+       \r
+       Variable runtime = ScenegraphLoaderUtils.getRuntimeVariable(graph, context);\r
+               INode root = runtime.adapt(graph, INode.class);\r
+\r
+       Variable result = ScenegraphLoaderProcess.getVariable(graph, null, scenegraph, ScenegraphLoaderUtils.getRuntime(graph, context), root);\r
+       if(result != null) {\r
+               Variable userDoc = result.getPossibleProperty(graph, "UserDocumentation");\r
+               if(userDoc != null) return userDoc;\r
+       }\r
+       \r
+       return null;\r
+       \r
+    }\r
+    \r
+    private static Variable resolveEditSelection(ReadGraph graph, Variable context, String path) throws DatabaseException {\r
+       \r
+               final ScenegraphPropertyReference<Variable> selectionReference = \r
+                               ScenegraphLoaderUtils.getRelativePropertyReference(SWTThread.getThreadAccess(), graph, context, path);\r
+               \r
+               Variable editSelection = selectionReference.getExternalValue(graph);\r
+               if(editSelection == null) editSelection = getDefaultSelection(graph, context);\r
+               \r
+               return editSelection;\r
+       \r
+    }\r
+\r
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> a")\r
+    public static Object wikitextModifier(ReadGraph graph, final Resource resource, final Variable context) throws DatabaseException {\r
+       \r
+               final ScenegraphPropertyReference<String> textReference = ScenegraphLoaderUtils.getRelativePropertyReference(SWTThread.getThreadAccess(), graph, context, ".../TextContainer/Text#text");\r
+       \r
+       return new FunctionImpl1<Object, Object>() {\r
+\r
+                       @Override\r
+                       public Object apply(final Object event) {\r
+           \r
+                               final String value = textReference.getValue();\r
+\r
+                               try {\r
+                                       Simantics.getSession().sync(new WriteRequest() {\r
+\r
+                                               @Override\r
+                                               public void perform(WriteGraph graph) throws DatabaseException {\r
+                                                       \r
+                                                       Variable selection = resolveEditSelection(graph, context, "..../Scroll/Browser#edited");\r
+                                                       if (selection != null)\r
+                                                           selection.setValue(graph, (String)value, Bindings.STRING);\r
+                                                       else {\r
+                                                               System.err.println("no selection for resource : " + resource + ", Variable context : " + context + ", value : " + value);\r
+                                                       }\r
+                                               }\r
+                                               \r
+                                       });\r
+                               } catch (DatabaseException e) {\r
+                                       e.printStackTrace();\r
+                               }\r
+                               return null;\r
+                       }\r
+               \r
+       };\r
+    }\r
+    \r
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> String")\r
+    public static String wikitext(ReadGraph graph, Resource resource, Variable context) throws DatabaseException {\r
+       Variable selection = ScenegraphLoaderUtils.getVariableSelection(graph, context);\r
+       return selection.getValue(graph);\r
+    }\r
+\r
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> String")\r
+    public static String selectedDocumentPart(ReadGraph graph, Resource resource, Variable context) throws DatabaseException {\r
+\r
+               Variable selection = resolveEditSelection(graph, context, ".../Scroll/Browser#edited");\r
+               if(selection == null) return null;\r
+\r
+       return selection.getValue(graph);\r
+       \r
+    }\r
+    \r
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> b")\r
+    public static Object documentStructureSelected(ReadGraph graph, Resource resource, Variable context) throws DatabaseException {\r
+       \r
+       return new FunctionImpl1<Object, Boolean>() {\r
+               \r
+           @Override\r
+           public Boolean apply(Object _event) {\r
+               \r
+               Event event = (Event)_event;\r
+               \r
+               final TreeItem item = (TreeItem)event.item;\r
+               NodeContext context = (NodeContext)item.getData();\r
+               final Variable entry = (Variable)context.getConstant(BuiltinKeys.INPUT);\r
+               \r
+               ISelectionProvider provider = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart().getSite().getSelectionProvider();\r
+               provider.setSelection(new StructuredSelection(entry));\r
+               \r
+               return null;\r
+               \r
+           }\r
+               \r
+       };\r
+        \r
+    }\r
+\r
+    abstract static class WikiButtonModifier extends FunctionImpl1<Object, Object> {\r
+\r
+               final ScenegraphPropertyReference<String> textReference;\r
+               final ScenegraphPropertyReference<Point> selectionReference;\r
+\r
+       public WikiButtonModifier(ReadGraph graph, Variable context) throws DatabaseException {\r
+               textReference = ScenegraphLoaderUtils.getRelativePropertyReference(SWTThread.getThreadAccess(), graph, context, ".../TextContainer/Text#text");\r
+               selectionReference = ScenegraphLoaderUtils.getRelativePropertyReference(SWTThread.getThreadAccess(), graph, context, ".../TextContainer/Text#selection");\r
+       }\r
+       \r
+       abstract void perform(String before, String selected, String after, Point selection);\r
+       \r
+           @Override\r
+           public Object apply(Object _event) {\r
+               String text = textReference.getValue();\r
+               Point selection = selectionReference.getValue(); \r
+               String before = text.substring(0, selection.x);\r
+               String selected = text.substring(selection.x, selection.y);\r
+               String after = text.substring(selection.y);\r
+               perform(before, selected, after, selection);\r
+               return null;\r
+           }\r
+\r
+    }\r
+    \r
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> b")\r
+    public static Object boldModifier(ReadGraph graph, Resource resource, final Variable context) throws DatabaseException {\r
+\r
+       return new WikiButtonModifier(graph, context) {\r
+                       \r
+                       @Override\r
+                       void perform(String before, String selected, String after, Point selection) {\r
+\r
+                               if(selected.isEmpty()) {\r
+                                       textReference.setValue(before + "'''bold text'''" + after);\r
+                               } else {\r
+                                       textReference.setValue(before + "'''" + selected + "'''" + after);      \r
+                               }\r
+                               \r
+                       }\r
+                       \r
+               };\r
+        \r
+    }\r
+\r
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> b")\r
+    public static Object italicModifier(ReadGraph graph, Resource resource, final Variable context) throws DatabaseException {\r
+\r
+       return new WikiButtonModifier(graph, context) {\r
+                       \r
+                       @Override\r
+                       void perform(String before, String selected, String after, Point selection) {\r
+\r
+                               if(selected.isEmpty()) {\r
+                                       textReference.setValue(before + "''italic text''" + after);\r
+                               } else {\r
+                                       textReference.setValue(before + "''" + selected + "''" + after);        \r
+                               }\r
+                               \r
+                       }\r
+                       \r
+               };\r
+        \r
+    }\r
+    \r
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> b")\r
+    public static Object strikethroughModifier(ReadGraph graph, Resource resource, final Variable context) throws DatabaseException {\r
+\r
+       return new WikiButtonModifier(graph, context) {\r
+                       \r
+                       @Override\r
+                       void perform(String before, String selected, String after, Point selection) {\r
+\r
+                               if(selected.isEmpty()) {\r
+                                       textReference.setValue(before + "<span style=\"text-decoration:line-through;\">strikethrough text</span>" + after);\r
+                               } else {\r
+                                       textReference.setValue(before + "<span style=\"text-decoration:line-through;\">" + selected + "</span>" + after);       \r
+                               }\r
+                               \r
+                       }\r
+                       \r
+               };\r
+        \r
+    }\r
+\r
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> b")\r
+    public static Object underlineModifier(ReadGraph graph, Resource resource, final Variable context) throws DatabaseException {\r
+\r
+       return new WikiButtonModifier(graph, context) {\r
+                       \r
+                       @Override\r
+                       void perform(String before, String selected, String after, Point selection) {\r
+\r
+                               if(selected.isEmpty()) {\r
+                                       textReference.setValue(before + "<span style=\"text-decoration:underline;\">strikethrough text</span>" + after);\r
+                               } else {\r
+                                       textReference.setValue(before + "<span style=\"text-decoration:underline;\">" + selected + "</span>" + after);  \r
+                               }\r
+                               \r
+                       }\r
+                       \r
+               };\r
+        \r
+    }\r
+\r
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> b")\r
+    public static Object horizontalRulerModifier(ReadGraph graph, Resource resource, final Variable context) throws DatabaseException {\r
+\r
+       return new WikiButtonModifier(graph, context) {\r
+                       \r
+                       @Override\r
+                       void perform(String before, String selected, String after, Point selection) {\r
+\r
+                               textReference.setValue(before + "\r\n<hr/>\r\n" + selected + after);\r
+                               \r
+                       }\r
+                       \r
+               };\r
+        \r
+    }\r
+    \r
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> b")\r
+    public static Object indentModifier(ReadGraph graph, Resource resource, final Variable context) throws DatabaseException {\r
+\r
+       return new WikiButtonModifier(graph, context) {\r
+                       \r
+                       @Override\r
+                       void perform(String before, String selected, String after, Point selection) {\r
+\r
+                               textReference.setValue(before + ":" + selected + after);\r
+                               \r
+                       }\r
+                       \r
+               };\r
+        \r
+    }\r
+\r
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> b")\r
+    public static Object fontModifier(ReadGraph graph, Resource resource, final Variable context) throws DatabaseException {\r
+\r
+       return new WikiButtonModifier(graph, context) {\r
+                       \r
+               private String hex2(int value) {\r
+                       String result = Integer.toHexString(value);\r
+                       if(result.length() == 1) result = "0" + result;\r
+                       return result;\r
+               }\r
+               \r
+                       @Override\r
+                       void perform(String before, String selected, String after, Point selection) {\r
+\r
+                               FontDialog dialog = new FontDialog(Display.getCurrent().getActiveShell()); \r
+                               FontData data = dialog.open();\r
+                               if(data == null) return;\r
+\r
+                               String family = data.getName();\r
+                               int size = data.getHeight();\r
+                               \r
+                               RGB rgb = dialog.getRGB();\r
+                               String hex = hex2(rgb.red) + hex2(rgb.green) + hex2(rgb.blue);\r
+\r
+                               if(selected.isEmpty()) {\r
+                                       textReference.setValue(before + "<font style=\"font-size:" + size + ";color: #" + hex + ";font-family:" + family + ";\" >formatted text</font>" + selected + after);\r
+                               } else {\r
+                                       textReference.setValue(before + "<font style=\"font-size:" + size + ";color: #" + hex + ";font-family:" + family + ";\" >" + selected + "</font>" + after);\r
+                               }\r
+                               \r
+                       }\r
+                       \r
+               };\r
+        \r
+    }\r
+\r
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> b")\r
+    public static Object imageModifier(ReadGraph graph, Resource resource, final Variable context) throws DatabaseException {\r
+\r
+       return new WikiButtonModifier(graph, context) {\r
+               \r
+                       @Override\r
+                       void perform(String before, String selected, String after, Point selection) {\r
+\r
+                               textReference.setValue(before + "[[Image:root://Library/image.png|100px]]" + selected + after);\r
+                               \r
+                       }\r
+                       \r
+               };\r
+        \r
+    }\r
+    \r
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> b")\r
+    public static Object header1Modifier(ReadGraph graph, Resource resource, final Variable context) throws DatabaseException {\r
+\r
+       return new WikiButtonModifier(graph, context) {\r
+                       \r
+                       @Override\r
+                       void perform(String before, String selected, String after, Point selection) {\r
+\r
+                               textReference.setValue(before + "\r\n= Header 1 =\r\n" + selected + after);\r
+                               \r
+                       }\r
+                       \r
+               };\r
+        \r
+    }\r
+\r
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> b")\r
+    public static Object header2Modifier(ReadGraph graph, Resource resource, final Variable context) throws DatabaseException {\r
+\r
+       return new WikiButtonModifier(graph, context) {\r
+                       \r
+                       @Override\r
+                       void perform(String before, String selected, String after, Point selection) {\r
+\r
+                               textReference.setValue(before + "\r\n== Header 2 ==\r\n" + selected + after);\r
+                               \r
+                       }\r
+                       \r
+               };\r
+        \r
+    }\r
+\r
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> b")\r
+    public static Object header3Modifier(ReadGraph graph, Resource resource, final Variable context) throws DatabaseException {\r
+\r
+       return new WikiButtonModifier(graph, context) {\r
+                       \r
+                       @Override\r
+                       void perform(String before, String selected, String after, Point selection) {\r
+\r
+                               textReference.setValue(before + "\r\n=== Header 3 ===\r\n" + selected + after);\r
+                               \r
+                       }\r
+                       \r
+               };\r
+        \r
+    }\r
+    \r
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> b")\r
+    public static Object header4Modifier(ReadGraph graph, Resource resource, final Variable context) throws DatabaseException {\r
+\r
+       return new WikiButtonModifier(graph, context) {\r
+                       \r
+                       @Override\r
+                       void perform(String before, String selected, String after, Point selection) {\r
+\r
+                               textReference.setValue(before + "\r\n==== Header 4 ====\r\n" + selected + after);\r
+                               \r
+                       }\r
+                       \r
+               };\r
+        \r
+    }\r
+    \r
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> b")\r
+    public static Object numberedListModifier(ReadGraph graph, Resource resource, final Variable context) throws DatabaseException {\r
+\r
+       return new WikiButtonModifier(graph, context) {\r
+                       \r
+                       @Override\r
+                       void perform(String before, String selected, String after, Point selection) {\r
+\r
+                               textReference.setValue(before + "\r\n" +\r
+                                               "# Item1\r\n" + \r
+                                               "# Item2\r\n" + \r
+                                               "## Item2.1\r\n" + \r
+                                               "# Item3\r\n" + selected + after);\r
+                               \r
+                       }\r
+                       \r
+               };\r
+        \r
+    }\r
+\r
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> b")\r
+    public static Object bulletListModifier(ReadGraph graph, Resource resource, final Variable context) throws DatabaseException {\r
+\r
+       return new WikiButtonModifier(graph, context) {\r
+                       \r
+                       @Override\r
+                       void perform(String before, String selected, String after, Point selection) {\r
+\r
+                               textReference.setValue(before + "\r\n" +\r
+                                               "* Item1\r\n" + \r
+                                               "* Item2\r\n" + \r
+                                               "** Item2.1\r\n" + \r
+                                               "* Item3\r\n" + selected + after);\r
+                               \r
+                       }\r
+                       \r
+               };\r
+        \r
+    }\r
+    \r
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> b")\r
+    public static Object tableModifier(ReadGraph graph, Resource resource, final Variable context) throws DatabaseException {\r
+\r
+       return new WikiButtonModifier(graph, context) {\r
+                       \r
+                       @Override\r
+                       void perform(String before, String selected, String after, Point selection) {\r
+\r
+                               textReference.setValue(before + "\r\n" +\r
+                                               "{| border=\"1\"\r\n" + \r
+                                               "! header\r\n" +\r
+                                               "! header2 \r\n" +\r
+                                               "|-\r\n" +\r
+                                               "| cell || cell2\r\n" + \r
+                                               "|-\r\n" +\r
+                                               "| cell3\r\n" + \r
+                                               "| cell4\r\n" + \r
+                                               "|}\r\n"  + selected + after);\r
+                               \r
+                       }\r
+                       \r
+               };\r
+        \r
+    }\r
+\r
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> b")\r
+    public static Object linkModifier(ReadGraph graph, Resource resource, final Variable context) throws DatabaseException {\r
+\r
+       return new WikiButtonModifier(graph, context) {\r
+                       \r
+                       @Override\r
+                       void perform(String before, String selected, String after, Point selection) {\r
+\r
+                               textReference.setValue(before + "\r\n" +\r
+                                               "[http://www.simantics.org External Website Link]\r\n"  + selected + after);\r
+                               \r
+                       }\r
+                       \r
+               };\r
+        \r
+    }\r
+    \r
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> b")\r
+    public static Object styleModifier(ReadGraph graph, Resource resource, final Variable context) throws DatabaseException {\r
+\r
+       return new WikiButtonModifier(graph, context) {\r
+                       \r
+                       @Override\r
+                       void perform(String before, String selected, String after, Point selection) {\r
+\r
+                               Simantics.getSession().asyncRequest(new ReadRequest() {\r
+\r
+                                       @Override\r
+                                       public void run(ReadGraph graph) throws DatabaseException {\r
+\r
+                                       Variable sel = ScenegraphLoaderUtils.getVariableSelection(graph, context);\r
+                                       Resource root = sel.getIndexRoot(graph);\r
+                                       String editorId = CSSEditor.EDITOR_ID;\r
+                               RVI rvi = null;\r
+\r
+                               PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {\r
+                                       \r
+                                   @Override\r
+                                   public void run() {\r
+\r
+                                                   try {\r
+                                                                       WorkbenchUtils.openEditor(editorId, new ResourceEditorInput2(editorId, root, root, rvi));\r
+                                                               } catch (PartInitException e) {\r
+                                                                       Logger.defaultLogError(e);\r
+                                                               }\r
+                                       \r
+                                   }\r
+                                   \r
+                               });\r
+\r
+                                       }\r
+                                       \r
+                               });\r
+                               \r
+                       }\r
+                       \r
+               };\r
+        \r
+    }\r
+    \r
+    \r
+//    @SCLValue(type = "ReadGraph -> Resource -> Variable -> a")\r
+//    public static Object navigate(ReadGraph graph, Resource resource, final Variable context) throws DatabaseException {\r
+//     \r
+//     return new FunctionImpl1<String, Boolean>() {\r
+//\r
+//                     @Override\r
+//                     public Boolean apply(final String path) {\r
+//                             \r
+//                             Simantics.getSession().asyncRequest(new ReadRequest() {\r
+//\r
+//                                     @Override\r
+//                                     public void run(ReadGraph graph) throws DatabaseException {\r
+//                                             \r
+//                                             DocumentResource DOC = DocumentResource.getInstance(graph);\r
+//                                     Variable sel = ScenegraphLoaderUtils.getVariableSelection(graph, context);\r
+//                                     \r
+//                                     Resource represents = sel.getRepresents(graph);\r
+//                                     Resource doc = graph.getSingleObject(represents, DOC.HasDocument);\r
+//                                     Resource scenegraph = graph.getSingleObject(doc, DOC.ScenegraphDocument_scenegraph);\r
+//                                     \r
+//                                     Variable runtime = ScenegraphLoaderUtils.getRuntimeVariable(graph, context);\r
+//                                             INode root = runtime.adapt(graph, INode.class);\r
+//                                     \r
+//                                     Variable result = ScenegraphLoaderProcess.getVariable(graph, null, scenegraph, ScenegraphLoaderUtils.getRuntime(graph, context), root);\r
+//                                     Variable location = result.browse(graph, path);\r
+//                                             \r
+//                                             ScenegraphPropertyReference<Variable> editReference = ScenegraphLoaderUtils.getRelativePropertyReference(SWTThread.getThreadAccess(), graph, context, ".#edited");\r
+//                                             editReference.setValue(location);\r
+//                                             \r
+//                                     }\r
+//                                     \r
+//                             });\r
+//                             \r
+//                             return null;\r
+//                             \r
+//                     }\r
+//             \r
+//     };\r
+//     \r
+//    }\r
+\r
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> String")\r
+    public static String noDocumentText(ReadGraph graph, final Resource resource, final Variable context) throws DatabaseException {\r
+               \r
+       Variable selection = ScenegraphLoaderUtils.getPossibleVariableSelection(graph, context);\r
+       if(selection == null) return "<no input>";\r
+       \r
+               Resource input = selection.getRepresents(graph);\r
+       if(input == null) return "<no input>";\r
+       \r
+       String path = DocumentUtils.indexRootPath(graph, selection);\r
+       if(!path.isEmpty()) {\r
+               return "for " + path + selection.getName(graph);\r
+       }\r
+       \r
+               return "for " + NameUtils.getSafeLabel(graph, input);\r
+       \r
+    }\r
+\r
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> Boolean")\r
+    public static Boolean canCreateDocument(ReadGraph graph, final Resource resource, final Variable context) throws DatabaseException {\r
+               \r
+       Variable selection = ScenegraphLoaderUtils.getPossibleVariableSelection(graph, context);\r
+       if(selection == null) return false;\r
+       \r
+               Resource input = selection.getRepresents(graph);\r
+       if(input == null) return false;\r
+       \r
+       return true;\r
+       \r
+    }\r
+    \r
+}\r