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%2FFinalImageDecoratorContributionImpl.java;h=6acaffa43963f941dedb5d0d187e36807dc30a66;hp=3bb30909a99bfbe38962a12d49d6916dfba474ec;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/FinalImageDecoratorContributionImpl.java b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/FinalImageDecoratorContributionImpl.java index 3bb30909a..6acaffa43 100644 --- a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/FinalImageDecoratorContributionImpl.java +++ b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/FinalImageDecoratorContributionImpl.java @@ -1,137 +1,137 @@ -/******************************************************************************* - * 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 org.simantics.browsing.ui.BuiltinKeys.ImageDecoratorKey; -import org.simantics.browsing.ui.DataSource; -import org.simantics.browsing.ui.NodeContext; -import org.simantics.browsing.ui.PrimitiveQueryUpdater; -import org.simantics.browsing.ui.content.ImageDecorator; -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 FinalImageDecoratorContributionImpl implements ImageDecorator { - - final ImageDecorator FRESH = new ImageDecorator.Stub(); - final ImageDecorator PENDING = new ImageDecorator.Stub(); - final ImageDecorator NO_DECORATION = new ImageDecorator.Stub(); - - protected final PrimitiveQueryUpdater updater; - private final ResourceQuery imageQuery; - private final ImageDecoratorKey key; - - /** - * The current decorator result produced for this contribution. The value - * should never be null, but one of {@link #FRESH}, - * {@link #PENDING}, {@link #NO_DECORATION} instead. - */ - protected ImageDecorator decorator = FRESH; - - final protected NodeContext context; - - public Object getIdentity(ImageDecoratorKey key) { - return key; - } - - private void request() { - - final DataSource source = updater.getDataSource(ReadGraph.class); - assert(source != null); - - final Procedure procedure = createProcedure(); - - source.schedule(graph -> { - if(procedure instanceof Listener) - graph.asyncRequest(imageQuery, (Listener)procedure); - else - graph.asyncRequest(imageQuery, procedure); - }); - - } - - @Override - public Image decorateImage(Image image, String column, int itemIndex) { - if(FRESH == decorator) { - decorator = PENDING; - request(); - } - return decorator.decorateImage(image, column, itemIndex); - } - - public FinalImageDecoratorContributionImpl(final PrimitiveQueryUpdater updater, final NodeContext context, final ImageDecoratorKey key) { - - this.updater = updater; - this.context = context; - this.key = key; - - imageQuery = new ResourceQuery(getIdentity(key), context) { - - @Override - public ImageDecorator perform(ReadGraph graph) throws DatabaseException { - try { - return getDecorator(graph, context); - } catch (PendingVariableException e) { - return PENDING; - } catch (DatabaseException e) { - throw e; - } catch (Throwable t) { - ErrorLogger.defaultLogError("FinalImageDecoratorContributionImpl.imageQuery produced unexpected exception.", t); - return null; - } - } - - @Override - public String toString() { - return FinalImageDecoratorContributionImpl.this + " with context " + context; - } - - }; - - } - - protected Procedure createProcedure() { - - return new Procedure() { - - @Override - public void execute(ImageDecorator result) { - replaceResult(result); - } - - @Override - public void exception(Throwable t) { - ErrorLogger.defaultLogError("FinalImageDecoratorContributionImpl.imageQuery failed, see exception for details.", t); - } - - }; - - } - - protected void replaceResult(ImageDecorator result) { - // Never let decorator become null, use a stub decorator instead. - if (result == null) - result = NO_DECORATION; - - decorator = result; - updater.scheduleReplace(context, key, this); - } - - // OVERRIDE - - public abstract ImageDecorator getDecorator(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 org.simantics.browsing.ui.BuiltinKeys.ImageDecoratorKey; +import org.simantics.browsing.ui.DataSource; +import org.simantics.browsing.ui.NodeContext; +import org.simantics.browsing.ui.PrimitiveQueryUpdater; +import org.simantics.browsing.ui.content.ImageDecorator; +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 FinalImageDecoratorContributionImpl implements ImageDecorator { + + final ImageDecorator FRESH = new ImageDecorator.Stub(); + final ImageDecorator PENDING = new ImageDecorator.Stub(); + final ImageDecorator NO_DECORATION = new ImageDecorator.Stub(); + + protected final PrimitiveQueryUpdater updater; + private final ResourceQuery imageQuery; + private final ImageDecoratorKey key; + + /** + * The current decorator result produced for this contribution. The value + * should never be null, but one of {@link #FRESH}, + * {@link #PENDING}, {@link #NO_DECORATION} instead. + */ + protected ImageDecorator decorator = FRESH; + + final protected NodeContext context; + + public Object getIdentity(ImageDecoratorKey key) { + return key; + } + + private void request() { + + final DataSource source = updater.getDataSource(ReadGraph.class); + assert(source != null); + + final Procedure procedure = createProcedure(); + + source.schedule(graph -> { + if(procedure instanceof Listener) + graph.asyncRequest(imageQuery, (Listener)procedure); + else + graph.asyncRequest(imageQuery, procedure); + }); + + } + + @Override + public Image decorateImage(Image image, String column, int itemIndex) { + if(FRESH == decorator) { + decorator = PENDING; + request(); + } + return decorator.decorateImage(image, column, itemIndex); + } + + public FinalImageDecoratorContributionImpl(final PrimitiveQueryUpdater updater, final NodeContext context, final ImageDecoratorKey key) { + + this.updater = updater; + this.context = context; + this.key = key; + + imageQuery = new ResourceQuery(getIdentity(key), context) { + + @Override + public ImageDecorator perform(ReadGraph graph) throws DatabaseException { + try { + return getDecorator(graph, context); + } catch (PendingVariableException e) { + return PENDING; + } catch (DatabaseException e) { + throw e; + } catch (Throwable t) { + ErrorLogger.defaultLogError("FinalImageDecoratorContributionImpl.imageQuery produced unexpected exception.", t); + return null; + } + } + + @Override + public String toString() { + return FinalImageDecoratorContributionImpl.this + " with context " + context; + } + + }; + + } + + protected Procedure createProcedure() { + + return new Procedure() { + + @Override + public void execute(ImageDecorator result) { + replaceResult(result); + } + + @Override + public void exception(Throwable t) { + ErrorLogger.defaultLogError("FinalImageDecoratorContributionImpl.imageQuery failed, see exception for details.", t); + } + + }; + + } + + protected void replaceResult(ImageDecorator result) { + // Never let decorator become null, use a stub decorator instead. + if (result == null) + result = NO_DECORATION; + + decorator = result; + updater.scheduleReplace(context, key, this); + } + + // OVERRIDE + + public abstract ImageDecorator getDecorator(ReadGraph graph, NodeContext context) throws DatabaseException; + +}