1 /*******************************************************************************
2 * Copyright (c) 2012 Association for Decentralized Information Management in
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.document.function;
14 import java.util.ArrayList;
15 import java.util.Collection;
16 import java.util.Hashtable;
20 import org.simantics.document.WikiDocumentNode;
21 import org.simantics.scenegraph.INode;
22 import org.simantics.scenegraph.ParentNode;
23 import org.simantics.scenegraph.ScenegraphUtils;
24 import org.simantics.scl.runtime.function.Function1;
25 import org.simantics.scl.runtime.function.Function2;
27 abstract public class WikiDocumentNodeImpl extends ParentNode<WikiDocumentNode> implements WikiDocumentNode {
29 public Boolean printInPDF = false;
30 public String editText = null;
32 private static final long serialVersionUID = 3394059912639648935L;
34 class M implements Map<String, WikiDocumentNode> {
36 ArrayList<WikiDocumentNode> list = new ArrayList<WikiDocumentNode>();
37 Hashtable<String, WikiDocumentNode> table = new Hashtable<String, WikiDocumentNode>();
45 public boolean containsKey(Object arg0) {
46 return table.containsKey(arg0);
49 public boolean containsValue(Object arg0) {
50 return table.containsValue(arg0);
53 public Set<java.util.Map.Entry<String, WikiDocumentNode>> entrySet() {
54 return table.entrySet();
57 public WikiDocumentNode get(Object arg0) {
58 return table.get(arg0);
61 public boolean isEmpty() {
62 return table.isEmpty();
65 public Set<String> keySet() {
66 return table.keySet();
69 public WikiDocumentNode put(String arg0, WikiDocumentNode arg1) {
70 WikiDocumentNode exist = table.put(arg0, arg1);
71 if(exist != null) list.remove(exist);
76 public void putAll(Map<? extends String, ? extends WikiDocumentNode> arg0) {
77 for(Map.Entry<? extends String, ? extends WikiDocumentNode> entry : arg0.entrySet())
78 put(entry.getKey(), entry.getValue());
81 public WikiDocumentNode remove(Object arg0) {
82 WikiDocumentNode node = table.remove(arg0);
83 if(node != null) list.remove(node);
91 public Collection<WikiDocumentNode> values() {
98 final public void asyncRemoveNode(INode node) {
103 protected Map<String, WikiDocumentNode> createChildMap() {
108 public Function1<Object, Boolean> getPropertyFunction(String propertyName) {
109 return ScenegraphUtils.getMethodPropertyFunction(null, this, propertyName);
113 public <T> T getProperty(String propertyName) {
118 public void setPropertyCallback(Function2<String, Object, Boolean> callback) {
121 protected void createChildren(StringBuilder b, boolean isPDF) {
122 for(WikiDocumentNode node : children.values()) node.create(b, isPDF);
125 public void synchronizePrintInPDF(Boolean value) {
126 this.printInPDF = value;
129 protected String getName() {
130 for(String id : parent.getNodeIds()) {
131 if(parent.getNode(id) == this) return id;
136 public String getPath() {
137 if(parent instanceof WikiDocumentNodeImpl) {
138 // Do not include root
139 if(parent.getParent() == null) return "";
140 else return ((WikiDocumentNodeImpl)parent).getPath() + "/" + getName();
146 public void synchronizeEditText(String editText) {
147 this.editText = editText;