1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2012 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.browsing.ui.swt;
\r
14 import java.net.URL;
\r
16 import org.eclipse.core.runtime.Platform;
\r
17 import org.eclipse.jface.resource.ImageDescriptor;
\r
18 import org.osgi.framework.Bundle;
\r
19 import org.simantics.Simantics;
\r
20 import org.simantics.browsing.ui.swt.stubs.BrowsingResource;
\r
21 import org.simantics.db.ReadGraph;
\r
22 import org.simantics.db.Resource;
\r
23 import org.simantics.db.exception.DatabaseException;
\r
24 import org.simantics.db.request.Read;
\r
25 import org.simantics.utils.datastructures.Pair;
\r
28 * @author Antti Villberg
\r
30 public class BundleIcon implements ModelledIcon {
\r
32 private final Resource configuration;
\r
33 private Pair<String, String> location;
\r
35 public BundleIcon(ReadGraph graph, Resource configuration) throws DatabaseException {
\r
36 this.configuration = configuration;
\r
37 this.location = graph.syncRequest(new Location(configuration));
\r
41 public ImageDescriptor create() throws DatabaseException {
\r
42 Pair<String, String> bundleAndPath = Simantics.getSession().syncRequest(new Location(configuration));
\r
43 if (bundleAndPath == null)
\r
46 Bundle bundle = Platform.getBundle(bundleAndPath.first);
\r
49 URL url = bundle.getEntry(bundleAndPath.second);
\r
50 return ImageDescriptor.createFromURL(url);
\r
54 public String toString() {
\r
55 return super.toString() + "[" + location + "]";
\r
58 static class Location implements Read<Pair<String, String>> {
\r
59 Resource configuration;
\r
60 public Location(Resource configuration) {
\r
61 this.configuration = configuration;
\r
64 public Pair<String, String> perform(ReadGraph graph) throws DatabaseException {
\r
65 BrowsingResource BRO = BrowsingResource.getInstance(graph);
\r
66 String bundle = graph.getPossibleRelatedValue(configuration, BRO.BundleIcon_Bundle);
\r
69 String path = graph.getPossibleRelatedValue(configuration, BRO.BundleIcon_Path);
\r
72 return Pair.make(bundle, path);
\r