X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.browsing.ui.swt%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fswt%2FBundleIcon.java;h=f3ac3d8af4110944c76c072ab6d7bfdc31f903d7;hb=HEAD;hp=a577d76ac12d44585835d5d3b98e3b98896245a4;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/BundleIcon.java b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/BundleIcon.java index a577d76ac..f3ac3d8af 100644 --- a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/BundleIcon.java +++ b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/BundleIcon.java @@ -1,76 +1,76 @@ -/******************************************************************************* - * Copyright (c) 2007, 2012 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.net.URL; - -import org.eclipse.core.runtime.Platform; -import org.eclipse.jface.resource.ImageDescriptor; -import org.osgi.framework.Bundle; -import org.simantics.Simantics; -import org.simantics.browsing.ui.swt.stubs.BrowsingResource; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.request.Read; -import org.simantics.utils.datastructures.Pair; - -/** - * @author Antti Villberg - */ -public class BundleIcon implements ModelledIcon { - - private final Resource configuration; - private Pair location; - - public BundleIcon(ReadGraph graph, Resource configuration) throws DatabaseException { - this.configuration = configuration; - this.location = graph.syncRequest(new Location(configuration)); - } - - @Override - public ImageDescriptor create() throws DatabaseException { - Pair bundleAndPath = Simantics.getSession().syncRequest(new Location(configuration)); - if (bundleAndPath == null) - return null; - - Bundle bundle = Platform.getBundle(bundleAndPath.first); - if (bundle == null) - return null; - URL url = bundle.getEntry(bundleAndPath.second); - return ImageDescriptor.createFromURL(url); - } - - @Override - public String toString() { - return super.toString() + "[" + location + "]"; - } - - static class Location implements Read> { - Resource configuration; - public Location(Resource configuration) { - this.configuration = configuration; - } - @Override - public Pair perform(ReadGraph graph) throws DatabaseException { - BrowsingResource BRO = BrowsingResource.getInstance(graph); - String bundle = graph.getPossibleRelatedValue(configuration, BRO.BundleIcon_Bundle); - if (bundle == null) - return null; - String path = graph.getPossibleRelatedValue(configuration, BRO.BundleIcon_Path); - if (path == null) - return null; - return Pair.make(bundle, path); - } - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2012 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.net.URL; + +import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.resource.ImageDescriptor; +import org.osgi.framework.Bundle; +import org.simantics.Simantics; +import org.simantics.browsing.ui.swt.stubs.BrowsingResource; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.utils.datastructures.Pair; + +/** + * @author Antti Villberg + */ +public class BundleIcon implements ModelledIcon { + + private final Resource configuration; + private Pair location; + + public BundleIcon(ReadGraph graph, Resource configuration) throws DatabaseException { + this.configuration = configuration; + this.location = graph.syncRequest(new Location(configuration)); + } + + @Override + public ImageDescriptor create() throws DatabaseException { + Pair bundleAndPath = Simantics.getSession().syncRequest(new Location(configuration)); + if (bundleAndPath == null) + return null; + + Bundle bundle = Platform.getBundle(bundleAndPath.first); + if (bundle == null) + return null; + URL url = bundle.getEntry(bundleAndPath.second); + return ImageDescriptor.createFromURL(url); + } + + @Override + public String toString() { + return super.toString() + "[" + location + "]"; + } + + static class Location implements Read> { + Resource configuration; + public Location(Resource configuration) { + this.configuration = configuration; + } + @Override + public Pair perform(ReadGraph graph) throws DatabaseException { + BrowsingResource BRO = BrowsingResource.getInstance(graph); + String bundle = graph.getPossibleRelatedValue(configuration, BRO.BundleIcon_Bundle); + if (bundle == null) + return null; + String path = graph.getPossibleRelatedValue(configuration, BRO.BundleIcon_Path); + if (path == null) + return null; + return Pair.make(bundle, path); + } + } + +}