X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.browsing.ui.swt%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fswt%2FOldAdapterImagerFactory.java;h=e03251efe8f73b7f3e6a6cf9bb1323264e7a85d7;hp=aaabad36418c69f9bd2eeb2e9223fa82d01f918c;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/OldAdapterImagerFactory.java b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/OldAdapterImagerFactory.java index aaabad364..e03251efe 100644 --- a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/OldAdapterImagerFactory.java +++ b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/OldAdapterImagerFactory.java @@ -1,102 +1,102 @@ -/******************************************************************************* - * 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.swt; - -import java.util.HashMap; -import java.util.function.Consumer; - -import org.eclipse.core.runtime.IAdaptable; -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.common.EvaluatorData.Transformer; -import org.simantics.browsing.ui.common.imagers.ContainerImager; -import org.simantics.browsing.ui.content.Imager; -import org.simantics.browsing.ui.content.ImagerFactory; -import org.simantics.browsing.ui.graph.impl.MissingImageDescriptor; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.exception.DatabaseException; -import org.simantics.ui.icons.ImageUtil; -import org.simantics.utils.datastructures.cache.ProvisionException; -import org.simantics.utils.ui.ErrorLogger; - -/** - * @deprecated favor {@link AdapterImagerFactory} instead - */ -@Deprecated -public class OldAdapterImagerFactory implements ImagerFactory { - - private final Transformer transformer; - private final HashMap constants; - private final String resourceColumn; - - public OldAdapterImagerFactory() { - this(null); - } - - public OldAdapterImagerFactory(Transformer transformer) { - this(transformer, null, new HashMap(4)); - } - - public OldAdapterImagerFactory(Transformer transformer, - String resourceColumn, HashMap constants) { - this.transformer = transformer; - this.constants = constants; - this.resourceColumn = resourceColumn; - } - - private Resource getInputResource(final NodeContext context) { - Object input = context.getConstant(BuiltinKeys.INPUT); - if (transformer != null) { - input = transformer.transform(input); - } - - if (input instanceof Resource) - return (Resource) input; - else if (input instanceof IAdaptable) - return (Resource) (((IAdaptable) input).getAdapter(Resource.class)); - return null; - } - - @SuppressWarnings("unchecked") - @Override - public Imager create(final PrimitiveQueryUpdater updater, final NodeContext context, final ImagerKey key) { - @SuppressWarnings("rawtypes") - final ContainerImager result = new ContainerImager((HashMap) constants.clone()); - result.setImage(resourceColumn, MissingImageDescriptor.getInstance()); - - final DataSource source = updater.getDataSource(ReadGraph.class); - final Resource inputResource = getInputResource(context); - - source.schedule(new Consumer() { - @Override - public void accept(ReadGraph source) { - try { - ImageDescriptor descriptor = ImageUtil.adaptImageDescriptor(source, inputResource); - result.setImage(resourceColumn, descriptor); - updater.scheduleReplace(context, key, result); - } catch (ProvisionException e) { - ErrorLogger.defaultLogError(e); - } catch (DatabaseException e) { - ErrorLogger.defaultLogError(e); - } - } - }); - - return result; - } - -} +/******************************************************************************* + * 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.swt; + +import java.util.HashMap; +import java.util.function.Consumer; + +import org.eclipse.core.runtime.IAdaptable; +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.common.EvaluatorData.Transformer; +import org.simantics.browsing.ui.common.imagers.ContainerImager; +import org.simantics.browsing.ui.content.Imager; +import org.simantics.browsing.ui.content.ImagerFactory; +import org.simantics.browsing.ui.graph.impl.MissingImageDescriptor; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.ui.icons.ImageUtil; +import org.simantics.utils.datastructures.cache.ProvisionException; +import org.simantics.utils.ui.ErrorLogger; + +/** + * @deprecated favor {@link AdapterImagerFactory} instead + */ +@Deprecated +public class OldAdapterImagerFactory implements ImagerFactory { + + private final Transformer transformer; + private final HashMap constants; + private final String resourceColumn; + + public OldAdapterImagerFactory() { + this(null); + } + + public OldAdapterImagerFactory(Transformer transformer) { + this(transformer, null, new HashMap(4)); + } + + public OldAdapterImagerFactory(Transformer transformer, + String resourceColumn, HashMap constants) { + this.transformer = transformer; + this.constants = constants; + this.resourceColumn = resourceColumn; + } + + private Resource getInputResource(final NodeContext context) { + Object input = context.getConstant(BuiltinKeys.INPUT); + if (transformer != null) { + input = transformer.transform(input); + } + + if (input instanceof Resource) + return (Resource) input; + else if (input instanceof IAdaptable) + return (Resource) (((IAdaptable) input).getAdapter(Resource.class)); + return null; + } + + @SuppressWarnings("unchecked") + @Override + public Imager create(final PrimitiveQueryUpdater updater, final NodeContext context, final ImagerKey key) { + @SuppressWarnings("rawtypes") + final ContainerImager result = new ContainerImager((HashMap) constants.clone()); + result.setImage(resourceColumn, MissingImageDescriptor.getInstance()); + + final DataSource source = updater.getDataSource(ReadGraph.class); + final Resource inputResource = getInputResource(context); + + source.schedule(new Consumer() { + @Override + public void accept(ReadGraph source) { + try { + ImageDescriptor descriptor = ImageUtil.adaptImageDescriptor(source, inputResource); + result.setImage(resourceColumn, descriptor); + updater.scheduleReplace(context, key, result); + } catch (ProvisionException e) { + ErrorLogger.defaultLogError(e); + } catch (DatabaseException e) { + ErrorLogger.defaultLogError(e); + } + } + }); + + return result; + } + +}