1 12 package org.eclipse.jsch.internal.ui; 13 14 import java.net.URL ; 15 import java.util.Hashtable ; 16 17 import org.eclipse.core.runtime.*; 18 import org.eclipse.jface.preference.IPreferenceStore; 19 import org.eclipse.jface.resource.ImageDescriptor; 20 import org.eclipse.jsch.core.IJSchService; 21 import org.eclipse.ui.plugin.AbstractUIPlugin; 22 import org.osgi.framework.BundleContext; 23 import org.osgi.util.tracker.ServiceTracker; 24 25 public class JSchUIPlugin extends AbstractUIPlugin{ 26 public static final String ID="org.eclipse.jsch.ui"; public static final String DECORATOR_ID="org.eclipse.jsch.ui.decorator"; 29 private static Hashtable imageDescriptors=new Hashtable (20); 30 33 private static JSchUIPlugin plugin; 34 private ServiceTracker tracker; 35 36 public JSchUIPlugin(){ 37 super(); 38 plugin=this; 39 } 40 41 46 public static JSchUIPlugin getPlugin(){ 47 return plugin; 48 } 49 50 56 public static ImageDescriptor getImageDescriptor(String id){ 57 return (ImageDescriptor)imageDescriptors.get(id); 58 } 59 60 63 protected void createImageDescriptor(String id){ 64 URL url=FileLocator.find(JSchUIPlugin.getPlugin().getBundle(), new Path( 65 IUIConstants.ICON_PATH+id), null); 66 ImageDescriptor desc=ImageDescriptor.createFromURL(url); 67 imageDescriptors.put(id, desc); 68 } 69 70 77 public static ImageDescriptor getImageDescriptorFromExtension(IExtension extension, String subdirectoryAndFilename) { 78 URL fullPathString = FileLocator.find(Platform.getBundle(extension.getNamespaceIdentifier()), new Path(subdirectoryAndFilename), null); 79 return ImageDescriptor.createFromURL(fullPathString); 80 } 81 82 85 private void initializeImages() { 86 132 133 createImageDescriptor(IUIConstants.IMG_KEY_LOCK); 134 135 146 } 147 148 151 public void start(BundleContext context) throws Exception { 152 super.start(context); 153 154 initializeImages(); 155 156 IPreferenceStore store = getPreferenceStore(); 157 if (store.getBoolean(IUIConstants.PREF_FIRST_STARTUP)) { 158 store.setValue(IUIConstants.PREF_FIRST_STARTUP, false); 159 } 160 161 tracker = new ServiceTracker(getBundle().getBundleContext(),IJSchService.class.getName(), null); 162 tracker.open(); 163 } 164 165 public void stop(BundleContext context) throws Exception { 166 super.stop(context); 167 tracker.close(); 168 } 169 170 public IJSchService getJSchService() { 171 return (IJSchService)tracker.getService(); 172 } 173 174 175 public URL getImageUrl(String relative){ 176 return FileLocator.find(Platform.getBundle(ID), new Path(IUIConstants.ICON_PATH + relative), null); 177 } 178 179 } 180 | Popular Tags |