KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > mapping > presentation > MappingUIPlugin


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2002-2004 IBM Corporation and others.
5  * All rights reserved. This program and the accompanying materials
6  * are made available under the terms of the Eclipse Public License v1.0
7  * which accompanies this distribution, and is available at
8  * http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Contributors:
11  * IBM - Initial API and implementation
12  *
13  * </copyright>
14  *
15  * $Id: MappingUIPlugin.java,v 1.3 2005/06/08 06:23:57 nickb Exp $
16  */

17 package org.eclipse.emf.mapping.presentation;
18
19
20 import java.net.MalformedURLException JavaDoc;
21 import java.net.URL JavaDoc;
22 import java.text.MessageFormat JavaDoc;
23
24 import org.eclipse.core.runtime.Platform;
25 import org.eclipse.jface.resource.ImageDescriptor;
26 import org.eclipse.jface.resource.ImageRegistry;
27 import org.eclipse.swt.graphics.Image;
28 import org.eclipse.ui.plugin.AbstractUIPlugin;
29
30 import org.eclipse.emf.mapping.MappingFactory;
31 import org.eclipse.emf.mapping.MappingRoot;
32
33
34 /**
35  * This is the central singleton for the emf.mapping plugin.
36  */

37 public class MappingUIPlugin extends AbstractUIPlugin
38 {
39   /**
40    * Get the singleton instance.
41    */

42   public static MappingUIPlugin getPlugin()
43   {
44     return instance;
45   }
46
47   /**
48    * Keep track of the singleton.
49    */

50   protected static MappingUIPlugin instance;
51
52   /**
53    * Create the instance.
54    */

55   public MappingUIPlugin()
56   {
57     super();
58
59     // Remember the static instance.
60
//
61
instance = this;
62   }
63
64   /**
65    * Create a new sample model.
66    */

67   MappingRoot createInitialModel()
68   {
69     MappingRoot mappingRoot = MappingFactory.eINSTANCE.createMappingRoot();
70     return mappingRoot;
71   }
72
73   public String JavaDoc getString(String JavaDoc key)
74   {
75     return Platform.getResourceBundle(getBundle()).getString(key);
76   }
77
78   public String JavaDoc getString(String JavaDoc key, Object JavaDoc s1)
79   {
80     return MessageFormat.format(getString(key), new Object JavaDoc [] { s1 });
81   }
82
83   public String JavaDoc getString(String JavaDoc key, Object JavaDoc s1, Object JavaDoc s2)
84   {
85     return MessageFormat.format(getString(key), new Object JavaDoc [] { s1, s2 });
86   }
87
88   /**
89    * This gets a .gif from the icons folder.
90    */

91   public ImageDescriptor getImageDescriptor(String JavaDoc key)
92   {
93     try
94     {
95       ImageDescriptor imageDescriptor = ImageDescriptor.createFromURL(new URL JavaDoc(getBundle().getEntry("/"), "icons/" + key + ".gif"));
96       return imageDescriptor;
97     }
98     catch (MalformedURLException JavaDoc exception)
99     {
100       System.out.println("Failed to load image for '" + key + "'");
101       exception.printStackTrace();
102     }
103
104     return null;
105   }
106
107   /**
108    * This get a .gif from the image registry, which caches the icons folder.
109    */

110   public Image getImage(String JavaDoc key)
111   {
112     ImageRegistry imageRegistry = getImageRegistry();
113     Image image = imageRegistry.get(key);
114     if (image == null)
115     {
116       imageRegistry.put(key, getImageDescriptor(key));
117       image = imageRegistry.get(key);
118     }
119
120     return image;
121   }
122 }
123
Popular Tags