]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.ui/src/org/simantics/ui/icons/BundleImageDescriptorProvider.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.ui / src / org / simantics / ui / icons / BundleImageDescriptorProvider.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.utils.datastructures.cache.ProvisionException;\r
17 import org.simantics.utils.ui.BundleUtils;\r
18 \r
19 public class BundleImageDescriptorProvider implements ImageDescriptorProvider {\r
20 \r
21     private final Bundle    bundle;\r
22     private final String    path;\r
23     private ImageDescriptor desc;\r
24 \r
25     public BundleImageDescriptorProvider(Bundle bundle, String path) {\r
26         assert bundle != null;\r
27         assert path != null;\r
28         this.bundle = bundle;\r
29         this.path = path;\r
30         //System.out.println("new bundle image descriptor: " + bundle + ", " + path);\r
31     }\r
32 \r
33     @Override\r
34     public ImageDescriptor get() throws ProvisionException {\r
35         if (desc == null) {\r
36             desc = BundleUtils.getImageDescriptorFromBundle(bundle, path);\r
37             if (desc == null)\r
38                 throw new ProvisionException("Could not find image in bundle '" + bundle + "' at path + '" + path + "'");\r
39             // desc = ImageDescriptor.getMissingImageDescriptor();\r
40         }\r
41         return desc;\r
42     }\r
43 \r
44 }\r