]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.document/src/org/simantics/document/function/WikiDocumentNodeImpl.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.document / src / org / simantics / document / function / WikiDocumentNodeImpl.java
1 /*******************************************************************************\r
2  * Copyright (c) 2012 Association for Decentralized Information Management in\r
3  * Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.document.function;\r
13 \r
14 import java.util.ArrayList;\r
15 import java.util.Collection;\r
16 import java.util.Hashtable;\r
17 import java.util.Map;\r
18 import java.util.Set;\r
19 \r
20 import org.simantics.document.WikiDocumentNode;\r
21 import org.simantics.scenegraph.INode;\r
22 import org.simantics.scenegraph.ParentNode;\r
23 import org.simantics.scenegraph.ScenegraphUtils;\r
24 import org.simantics.scl.runtime.function.Function1;\r
25 import org.simantics.scl.runtime.function.Function2;\r
26 \r
27 abstract public class WikiDocumentNodeImpl extends ParentNode<WikiDocumentNode> implements WikiDocumentNode {\r
28 \r
29         public Boolean printInPDF = false;\r
30         public String editText = null;\r
31         \r
32         private static final long serialVersionUID = 3394059912639648935L;\r
33 \r
34         class M implements Map<String, WikiDocumentNode> {\r
35                 \r
36                 ArrayList<WikiDocumentNode> list = new ArrayList<WikiDocumentNode>();\r
37                 Hashtable<String, WikiDocumentNode> table = new Hashtable<String, WikiDocumentNode>();\r
38                 \r
39                 @Override\r
40                 public void clear() {\r
41                         table.clear();\r
42                         list.clear();\r
43                 }\r
44                 @Override\r
45                 public boolean containsKey(Object arg0) {\r
46                         return table.containsKey(arg0);\r
47                 }\r
48                 @Override\r
49                 public boolean containsValue(Object arg0) {\r
50                         return table.containsValue(arg0);\r
51                 }\r
52                 @Override\r
53                 public Set<java.util.Map.Entry<String, WikiDocumentNode>> entrySet() {\r
54                         return table.entrySet();\r
55                 }\r
56                 @Override\r
57                 public WikiDocumentNode get(Object arg0) {\r
58                         return table.get(arg0);\r
59                 }\r
60                 @Override\r
61                 public boolean isEmpty() {\r
62                         return table.isEmpty();\r
63                 }\r
64                 @Override\r
65                 public Set<String> keySet() {\r
66                         return table.keySet();\r
67                 }\r
68                 @Override\r
69                 public WikiDocumentNode put(String arg0, WikiDocumentNode arg1) {\r
70                         WikiDocumentNode exist = table.put(arg0, arg1);\r
71                         if(exist != null) list.remove(exist);\r
72                         list.add(arg1);\r
73                         return exist;\r
74                 }\r
75                 @Override\r
76                 public void putAll(Map<? extends String, ? extends WikiDocumentNode> arg0) {\r
77                         for(Map.Entry<? extends String, ? extends WikiDocumentNode> entry : arg0.entrySet())\r
78                                 put(entry.getKey(), entry.getValue());\r
79                 }\r
80                 @Override\r
81                 public WikiDocumentNode remove(Object arg0) {\r
82                         WikiDocumentNode node = table.remove(arg0);\r
83                         if(node != null) list.remove(node);\r
84                         return node;\r
85                 }\r
86                 @Override\r
87                 public int size() {\r
88                         return table.size();\r
89                 }\r
90                 @Override\r
91                 public Collection<WikiDocumentNode> values() {\r
92                         return list;\r
93                 }\r
94                 \r
95         }\r
96         \r
97         @Override\r
98         final public void asyncRemoveNode(INode node) {\r
99         throw new Error();\r
100         }\r
101         \r
102         @Override\r
103         protected Map<String, WikiDocumentNode> createChildMap() {\r
104                 return new M();\r
105         }\r
106         \r
107         @Override\r
108         public Function1<Object, Boolean> getPropertyFunction(String propertyName) {\r
109                 return ScenegraphUtils.getMethodPropertyFunction(null, this, propertyName);\r
110         }\r
111         \r
112         @Override\r
113         public <T> T getProperty(String propertyName) {\r
114                 return null;\r
115         }\r
116         \r
117         @Override\r
118         public void setPropertyCallback(Function2<String, Object, Boolean> callback) {\r
119         }\r
120 \r
121         protected void createChildren(StringBuilder b, boolean isPDF) {\r
122                 for(WikiDocumentNode node : children.values()) node.create(b, isPDF);\r
123         }\r
124         \r
125         public void synchronizePrintInPDF(Boolean value) {\r
126                 this.printInPDF = value;\r
127         }\r
128         \r
129         protected String getName() {\r
130                 for(String id : parent.getNodeIds()) {\r
131                         if(parent.getNode(id) == this) return id;\r
132                 }\r
133                 return "err";\r
134         }\r
135         \r
136         public String getPath() {\r
137                 if(parent instanceof WikiDocumentNodeImpl) {\r
138                         // Do not include root\r
139                         if(parent.getParent() == null) return "";\r
140                         else return ((WikiDocumentNodeImpl)parent).getPath() + "/" + getName(); \r
141                 } else {\r
142                         return "";\r
143                 }\r
144         }\r
145         \r
146         public void synchronizeEditText(String editText) {\r
147                 this.editText = editText;\r
148         }\r
149         \r
150 }\r