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