X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.browsing.ui.graph.impl%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fgraph%2Fimpl%2Fcontribution%2FFinalImagerContributionImpl.java;h=b4d233e0882289b59862157d11f872871376e52f;hp=aa3f203be2656f92ada49966c966b509dc3ed057;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/FinalImagerContributionImpl.java b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/FinalImagerContributionImpl.java index aa3f203be..b4d233e08 100644 --- a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/FinalImagerContributionImpl.java +++ b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/FinalImagerContributionImpl.java @@ -1,133 +1,133 @@ -/******************************************************************************* - * 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.graph.impl.contribution; - -import java.util.Collections; -import java.util.Map; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.simantics.browsing.ui.BuiltinKeys; -import org.simantics.browsing.ui.BuiltinKeys.ImagerKey; -import org.simantics.browsing.ui.DataSource; -import org.simantics.browsing.ui.NodeContext; -import org.simantics.browsing.ui.PrimitiveQueryUpdater; -import org.simantics.browsing.ui.content.Imager; -import org.simantics.browsing.ui.graph.impl.request.ResourceQuery; -import org.simantics.db.ReadGraph; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.exception.PendingVariableException; -import org.simantics.db.procedure.Listener; -import org.simantics.db.procedure.Procedure; -import org.simantics.utils.ui.ErrorLogger; - -public abstract class FinalImagerContributionImpl implements Imager { - - private final static Map PENDING = Collections.emptyMap(); - - protected final PrimitiveQueryUpdater updater; - private final ResourceQuery> imagerQuery; - - protected final NodeContext context; - private final BuiltinKeys.ImagerKey key; - - protected Map content = null; - - public Object getIdentity(ImagerKey key) { - return key; - } - - public FinalImagerContributionImpl(final PrimitiveQueryUpdater updater, final NodeContext context, final ImagerKey key) { - - this.updater = updater; - this.context = context; - this.key = key; - - imagerQuery = new ResourceQuery>(getIdentity(key), context) { - - @Override - public Map perform(ReadGraph graph) throws DatabaseException { - try { - return getDescriptors(graph, context); - } catch (PendingVariableException e) { - return PENDING; - } catch (DatabaseException e) { - throw e; - } catch (Throwable t) { - ErrorLogger.defaultLogError("LazyGraphLabeler.labelQuery produced unexpected exception.", t); - return null; - } - } - - @Override - public String toString() { - return FinalImagerContributionImpl.this + " with context " + context; - } - - }; - - } - - protected Procedure> createProcedure() { - - return new Procedure>() { - - @Override - public void execute(Map result) { - replaceResult(result); - } - - @Override - public void exception(Throwable t) { - ErrorLogger.defaultLogError("FinalImagerContributionImpl.imagerQuery failed, see exception for details.", t); - } - - }; - - } - - protected void replaceResult(Map desc) { - content = desc; - updater.scheduleReplace(context, key, this); - } - - @SuppressWarnings("unchecked") - @Override - public ImageDescriptor getImage(String key) { - - if (content == null) { - - content = PENDING; - - final DataSource source = updater.getDataSource(ReadGraph.class); - assert(source != null); - - final Procedure> procedure = createProcedure(); - source.schedule(graph -> { - if(procedure instanceof Listener) - graph.asyncRequest(imagerQuery, (Listener>)procedure); - else - graph.asyncRequest(imagerQuery, procedure); - }); - - return null; - - } - - ImageDescriptor descriptor = content.get(key); - return descriptor; - } - - // OVERRIDE - - public abstract Map getDescriptors(ReadGraph graph, NodeContext context) throws DatabaseException; - -} +/******************************************************************************* + * 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.graph.impl.contribution; + +import java.util.Collections; +import java.util.Map; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.simantics.browsing.ui.BuiltinKeys; +import org.simantics.browsing.ui.BuiltinKeys.ImagerKey; +import org.simantics.browsing.ui.DataSource; +import org.simantics.browsing.ui.NodeContext; +import org.simantics.browsing.ui.PrimitiveQueryUpdater; +import org.simantics.browsing.ui.content.Imager; +import org.simantics.browsing.ui.graph.impl.request.ResourceQuery; +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.exception.PendingVariableException; +import org.simantics.db.procedure.Listener; +import org.simantics.db.procedure.Procedure; +import org.simantics.utils.ui.ErrorLogger; + +public abstract class FinalImagerContributionImpl implements Imager { + + private final static Map PENDING = Collections.emptyMap(); + + protected final PrimitiveQueryUpdater updater; + private final ResourceQuery> imagerQuery; + + protected final NodeContext context; + private final BuiltinKeys.ImagerKey key; + + protected Map content = null; + + public Object getIdentity(ImagerKey key) { + return key; + } + + public FinalImagerContributionImpl(final PrimitiveQueryUpdater updater, final NodeContext context, final ImagerKey key) { + + this.updater = updater; + this.context = context; + this.key = key; + + imagerQuery = new ResourceQuery>(getIdentity(key), context) { + + @Override + public Map perform(ReadGraph graph) throws DatabaseException { + try { + return getDescriptors(graph, context); + } catch (PendingVariableException e) { + return PENDING; + } catch (DatabaseException e) { + throw e; + } catch (Throwable t) { + ErrorLogger.defaultLogError("LazyGraphLabeler.labelQuery produced unexpected exception.", t); + return null; + } + } + + @Override + public String toString() { + return FinalImagerContributionImpl.this + " with context " + context; + } + + }; + + } + + protected Procedure> createProcedure() { + + return new Procedure>() { + + @Override + public void execute(Map result) { + replaceResult(result); + } + + @Override + public void exception(Throwable t) { + ErrorLogger.defaultLogError("FinalImagerContributionImpl.imagerQuery failed, see exception for details.", t); + } + + }; + + } + + protected void replaceResult(Map desc) { + content = desc; + updater.scheduleReplace(context, key, this); + } + + @SuppressWarnings("unchecked") + @Override + public ImageDescriptor getImage(String key) { + + if (content == null) { + + content = PENDING; + + final DataSource source = updater.getDataSource(ReadGraph.class); + assert(source != null); + + final Procedure> procedure = createProcedure(); + source.schedule(graph -> { + if(procedure instanceof Listener) + graph.asyncRequest(imagerQuery, (Listener>)procedure); + else + graph.asyncRequest(imagerQuery, procedure); + }); + + return null; + + } + + ImageDescriptor descriptor = content.get(key); + return descriptor; + } + + // OVERRIDE + + public abstract Map getDescriptors(ReadGraph graph, NodeContext context) throws DatabaseException; + +}