X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.browsing.ui.common%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fcommon%2Finternal%2FIGECache.java;fp=bundles%2Forg.simantics.browsing.ui.common%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fcommon%2Finternal%2FIGECache.java;h=0503ba13f16771576b7ede7e738d50a1321b89e6;hp=0000000000000000000000000000000000000000;hb=969bd23cab98a79ca9101af33334000879fb60c5;hpb=866dba5cd5a3929bbeae85991796acb212338a08 diff --git a/bundles/org.simantics.browsing.ui.common/src/org/simantics/browsing/ui/common/internal/IGECache.java b/bundles/org.simantics.browsing.ui.common/src/org/simantics/browsing/ui/common/internal/IGECache.java new file mode 100644 index 000000000..0503ba13f --- /dev/null +++ b/bundles/org.simantics.browsing.ui.common/src/org/simantics/browsing/ui/common/internal/IGECache.java @@ -0,0 +1,122 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.browsing.ui.common.internal; + +import gnu.trove.set.hash.THashSet; + +import java.util.Collection; +import java.util.Set; + +import org.simantics.browsing.ui.NodeContext; +import org.simantics.browsing.ui.NodeContext.CacheKey; + +public interface IGECache { + + interface IGECacheEntry { + Object getValue(); + void setValue(Object value); +// Collection getDependencies(); +// void addDependency(NodeQueryUpdater caller); + NodeContext getContext(); + CacheKey getKey(); + Collection getDependencies(); + void addDependency(IGECacheEntry caller); + void reset(); + } + + class GECacheEntry implements IGECacheEntry { + + private Object result; + final private NodeContext context; + final private CacheKey key; + private Set callers = new THashSet(2); + + public GECacheEntry(NodeContext context, CacheKey key, T result) { + this.context = context; + this.key = key; + this.result = result; + } + @Override + public Collection getDependencies() { + return callers; + } + @Override + public Object getValue() { + return result; + } + @Override + public void addDependency(IGECacheEntry caller) { + assert(caller != null); + callers.add(caller); + } + @Override + public void setValue(Object value) { + result = value; + } + @Override + public NodeContext getContext() { + return context; + } + @Override + public CacheKey getKey() { + return key; + } + @Override + public void reset() { + callers = new THashSet(2); + } + + @Override + public int hashCode() { + return 31 * context.hashCode() | key.hashCode(); + } + + @Override + public boolean equals(Object object) { + + if (this == object) + return true; + else if (object == null) + return false; + else if (getClass() != object.getClass()) + return false; + + GECacheEntry i = (GECacheEntry)object; + + return key.equals(i.key) && context.equals(i.context); + + } + +// @Override +// public String toString() { +// return "GECacheEntry[" + result + ", " + context + ", " + key + "]"; +// } + + } + + IGECacheEntry getEntry(NodeContext context, CacheKey key); + + IGECacheEntry put(NodeContext context, CacheKey key, T value); + void putTreeReference(NodeContext context, CacheKey key, UIElementReference reference); + + T get(NodeContext context, CacheKey key); + Set getTreeReference(NodeContext context, CacheKey key); + + void remove(NodeContext context, CacheKey key); + Set removeTreeReference(NodeContext context, CacheKey key); + + boolean isShown(NodeContext context); + void incRef(NodeContext context); + void decRef(NodeContext context); + + void dispose(); +}