1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in 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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.browsing.ui.common.internal;
\r
14 import gnu.trove.set.hash.THashSet;
\r
16 import java.util.Collection;
\r
17 import java.util.Set;
\r
19 import org.simantics.browsing.ui.NodeContext;
\r
20 import org.simantics.browsing.ui.NodeContext.CacheKey;
\r
22 public interface IGECache {
\r
24 interface IGECacheEntry {
\r
26 void setValue(Object value);
\r
27 // Collection<NodeQueryUpdater> getDependencies();
\r
28 // void addDependency(NodeQueryUpdater caller);
\r
29 NodeContext getContext();
\r
30 CacheKey<?> getKey();
\r
31 Collection<IGECacheEntry> getDependencies();
\r
32 void addDependency(IGECacheEntry caller);
\r
36 class GECacheEntry implements IGECacheEntry {
\r
38 private Object result;
\r
39 final private NodeContext context;
\r
40 final private CacheKey<?> key;
\r
41 private Set<IGECacheEntry> callers = new THashSet<IGECacheEntry>(2);
\r
43 public <T> GECacheEntry(NodeContext context, CacheKey<T> key, T result) {
\r
44 this.context = context;
\r
46 this.result = result;
\r
49 public Collection<IGECacheEntry> getDependencies() {
\r
53 public Object getValue() {
\r
57 public void addDependency(IGECacheEntry caller) {
\r
58 assert(caller != null);
\r
59 callers.add(caller);
\r
62 public void setValue(Object value) {
\r
66 public NodeContext getContext() {
\r
70 public CacheKey<?> getKey() {
\r
74 public void reset() {
\r
75 callers = new THashSet<IGECacheEntry>(2);
\r
79 public int hashCode() {
\r
80 return 31 * context.hashCode() | key.hashCode();
\r
84 public boolean equals(Object object) {
\r
88 else if (object == null)
\r
90 else if (getClass() != object.getClass())
\r
93 GECacheEntry i = (GECacheEntry)object;
\r
95 return key.equals(i.key) && context.equals(i.context);
\r
100 // public String toString() {
\r
101 // return "GECacheEntry[" + result + ", " + context + ", " + key + "]";
\r
106 <T> IGECacheEntry getEntry(NodeContext context, CacheKey<T> key);
\r
108 <T> IGECacheEntry put(NodeContext context, CacheKey<T> key, T value);
\r
109 <T> void putTreeReference(NodeContext context, CacheKey<T> key, UIElementReference reference);
\r
111 <T> T get(NodeContext context, CacheKey<T> key);
\r
112 <T> Set<UIElementReference> getTreeReference(NodeContext context, CacheKey<T> key);
\r
114 <T> void remove(NodeContext context, CacheKey<T> key);
\r
115 <T> Set<UIElementReference> removeTreeReference(NodeContext context, CacheKey<T> key);
\r
117 boolean isShown(NodeContext context);
\r
118 void incRef(NodeContext context);
\r
119 void decRef(NodeContext context);
\r