--- /dev/null
+/*******************************************************************************\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.function;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+import java.util.Hashtable;\r
+import java.util.Map;\r
+import java.util.Set;\r
+\r
+import org.simantics.document.WikiDocumentNode;\r
+import org.simantics.scenegraph.INode;\r
+import org.simantics.scenegraph.ParentNode;\r
+import org.simantics.scenegraph.ScenegraphUtils;\r
+import org.simantics.scl.runtime.function.Function1;\r
+import org.simantics.scl.runtime.function.Function2;\r
+\r
+abstract public class WikiDocumentNodeImpl extends ParentNode<WikiDocumentNode> implements WikiDocumentNode {\r
+\r
+ public Boolean printInPDF = false;\r
+ public String editText = null;\r
+ \r
+ private static final long serialVersionUID = 3394059912639648935L;\r
+\r
+ class M implements Map<String, WikiDocumentNode> {\r
+ \r
+ ArrayList<WikiDocumentNode> list = new ArrayList<WikiDocumentNode>();\r
+ Hashtable<String, WikiDocumentNode> table = new Hashtable<String, WikiDocumentNode>();\r
+ \r
+ @Override\r
+ public void clear() {\r
+ table.clear();\r
+ list.clear();\r
+ }\r
+ @Override\r
+ public boolean containsKey(Object arg0) {\r
+ return table.containsKey(arg0);\r
+ }\r
+ @Override\r
+ public boolean containsValue(Object arg0) {\r
+ return table.containsValue(arg0);\r
+ }\r
+ @Override\r
+ public Set<java.util.Map.Entry<String, WikiDocumentNode>> entrySet() {\r
+ return table.entrySet();\r
+ }\r
+ @Override\r
+ public WikiDocumentNode get(Object arg0) {\r
+ return table.get(arg0);\r
+ }\r
+ @Override\r
+ public boolean isEmpty() {\r
+ return table.isEmpty();\r
+ }\r
+ @Override\r
+ public Set<String> keySet() {\r
+ return table.keySet();\r
+ }\r
+ @Override\r
+ public WikiDocumentNode put(String arg0, WikiDocumentNode arg1) {\r
+ WikiDocumentNode exist = table.put(arg0, arg1);\r
+ if(exist != null) list.remove(exist);\r
+ list.add(arg1);\r
+ return exist;\r
+ }\r
+ @Override\r
+ public void putAll(Map<? extends String, ? extends WikiDocumentNode> arg0) {\r
+ for(Map.Entry<? extends String, ? extends WikiDocumentNode> entry : arg0.entrySet())\r
+ put(entry.getKey(), entry.getValue());\r
+ }\r
+ @Override\r
+ public WikiDocumentNode remove(Object arg0) {\r
+ WikiDocumentNode node = table.remove(arg0);\r
+ if(node != null) list.remove(node);\r
+ return node;\r
+ }\r
+ @Override\r
+ public int size() {\r
+ return table.size();\r
+ }\r
+ @Override\r
+ public Collection<WikiDocumentNode> values() {\r
+ return list;\r
+ }\r
+ \r
+ }\r
+ \r
+ @Override\r
+ final public void asyncRemoveNode(INode node) {\r
+ throw new Error();\r
+ }\r
+ \r
+ @Override\r
+ protected Map<String, WikiDocumentNode> createChildMap() {\r
+ return new M();\r
+ }\r
+ \r
+ @Override\r
+ public Function1<Object, Boolean> getPropertyFunction(String propertyName) {\r
+ return ScenegraphUtils.getMethodPropertyFunction(null, this, propertyName);\r
+ }\r
+ \r
+ @Override\r
+ public <T> T getProperty(String propertyName) {\r
+ return null;\r
+ }\r
+ \r
+ @Override\r
+ public void setPropertyCallback(Function2<String, Object, Boolean> callback) {\r
+ }\r
+\r
+ protected void createChildren(StringBuilder b, boolean isPDF) {\r
+ for(WikiDocumentNode node : children.values()) node.create(b, isPDF);\r
+ }\r
+ \r
+ public void synchronizePrintInPDF(Boolean value) {\r
+ this.printInPDF = value;\r
+ }\r
+ \r
+ protected String getName() {\r
+ for(String id : parent.getNodeIds()) {\r
+ if(parent.getNode(id) == this) return id;\r
+ }\r
+ return "err";\r
+ }\r
+ \r
+ public String getPath() {\r
+ if(parent instanceof WikiDocumentNodeImpl) {\r
+ // Do not include root\r
+ if(parent.getParent() == null) return "";\r
+ else return ((WikiDocumentNodeImpl)parent).getPath() + "/" + getName(); \r
+ } else {\r
+ return "";\r
+ }\r
+ }\r
+ \r
+ public void synchronizeEditText(String editText) {\r
+ this.editText = editText;\r
+ }\r
+ \r
+}\r