+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 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
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.browsing.ui.common.internal;\r
+\r
+import gnu.trove.set.hash.THashSet;\r
+\r
+import java.util.Collection;\r
+import java.util.Set;\r
+\r
+import org.simantics.browsing.ui.NodeContext;\r
+import org.simantics.browsing.ui.NodeContext.CacheKey;\r
+\r
+public interface IGECache {\r
+\r
+ interface IGECacheEntry {\r
+ Object getValue();\r
+ void setValue(Object value);\r
+// Collection<NodeQueryUpdater> getDependencies();\r
+// void addDependency(NodeQueryUpdater caller);\r
+ NodeContext getContext();\r
+ CacheKey<?> getKey();\r
+ Collection<IGECacheEntry> getDependencies();\r
+ void addDependency(IGECacheEntry caller);\r
+ void reset();\r
+ }\r
+\r
+ class GECacheEntry implements IGECacheEntry {\r
+\r
+ private Object result;\r
+ final private NodeContext context;\r
+ final private CacheKey<?> key;\r
+ private Set<IGECacheEntry> callers = new THashSet<IGECacheEntry>(2);\r
+\r
+ public <T> GECacheEntry(NodeContext context, CacheKey<T> key, T result) {\r
+ this.context = context;\r
+ this.key = key;\r
+ this.result = result;\r
+ }\r
+ @Override\r
+ public Collection<IGECacheEntry> getDependencies() {\r
+ return callers;\r
+ }\r
+ @Override\r
+ public Object getValue() {\r
+ return result;\r
+ }\r
+ @Override\r
+ public void addDependency(IGECacheEntry caller) {\r
+ assert(caller != null);\r
+ callers.add(caller);\r
+ }\r
+ @Override\r
+ public void setValue(Object value) {\r
+ result = value;\r
+ }\r
+ @Override\r
+ public NodeContext getContext() {\r
+ return context;\r
+ }\r
+ @Override\r
+ public CacheKey<?> getKey() {\r
+ return key;\r
+ }\r
+ @Override\r
+ public void reset() {\r
+ callers = new THashSet<IGECacheEntry>(2);\r
+ }\r
+\r
+ @Override\r
+ public int hashCode() {\r
+ return 31 * context.hashCode() | key.hashCode();\r
+ }\r
+\r
+ @Override\r
+ public boolean equals(Object object) {\r
+\r
+ if (this == object)\r
+ return true;\r
+ else if (object == null)\r
+ return false;\r
+ else if (getClass() != object.getClass())\r
+ return false;\r
+\r
+ GECacheEntry i = (GECacheEntry)object;\r
+\r
+ return key.equals(i.key) && context.equals(i.context);\r
+\r
+ }\r
+\r
+// @Override\r
+// public String toString() {\r
+// return "GECacheEntry[" + result + ", " + context + ", " + key + "]";\r
+// }\r
+\r
+ }\r
+\r
+ <T> IGECacheEntry getEntry(NodeContext context, CacheKey<T> key);\r
+\r
+ <T> IGECacheEntry put(NodeContext context, CacheKey<T> key, T value);\r
+ <T> void putTreeReference(NodeContext context, CacheKey<T> key, UIElementReference reference);\r
+\r
+ <T> T get(NodeContext context, CacheKey<T> key);\r
+ <T> Set<UIElementReference> getTreeReference(NodeContext context, CacheKey<T> key);\r
+\r
+ <T> void remove(NodeContext context, CacheKey<T> key);\r
+ <T> Set<UIElementReference> removeTreeReference(NodeContext context, CacheKey<T> key);\r
+ \r
+ boolean isShown(NodeContext context);\r
+ void incRef(NodeContext context);\r
+ void decRef(NodeContext context);\r
+ \r
+ void dispose();\r
+}\r