]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.ui/src/org/simantics/ui/icons/GraphOrBundleImageDescriptorProvider.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.ui / src / org / simantics / ui / icons / GraphOrBundleImageDescriptorProvider.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.ui.icons;\r
13 \r
14 import org.eclipse.jface.resource.ImageDescriptor;\r
15 import org.osgi.framework.Bundle;\r
16 import org.simantics.db.ReadGraph;\r
17 import org.simantics.db.Resource;\r
18 import org.simantics.utils.datastructures.cache.ProvisionException;\r
19 import org.simantics.utils.ui.BundleUtils;\r
20 \r
21 /**\r
22  * FIXME: http://www.simantics.org/Layer0-1.0/HasModelledIcon no longer exists!\r
23  */\r
24 public class GraphOrBundleImageDescriptorProvider implements ImageDescriptorProvider {\r
25 \r
26     private final Bundle    bundle;\r
27     private final String    path;\r
28     private ImageDescriptor desc;\r
29 \r
30     public GraphOrBundleImageDescriptorProvider(ReadGraph graph, final Resource resource, Bundle bundle, String path) {\r
31         assert bundle != null;\r
32         assert path != null;\r
33         this.bundle = bundle;\r
34         this.path = path;\r
35         //System.out.println("new bundle image descriptor: " + bundle + ", " + path);\r
36     }\r
37 \r
38     @Override\r
39     public ImageDescriptor get() throws ProvisionException {\r
40         if (desc == null) {\r
41             desc = BundleUtils.getImageDescriptorFromBundle(bundle, path);\r
42             if (desc == null)\r
43                 throw new ProvisionException("Could not find image in bundle '" + bundle + "' at path + '" + path + "'");\r
44             // desc = ImageDescriptor.getMissingImageDescriptor();\r
45         }\r
46         return desc;\r
47     }\r
48 \r
49 }\r