KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jsch > internal > ui > JSchUIPlugin


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * Atsuhiko Yamanaka, JCraft,Inc. - initial API and implementation.
10  * IBM Corporation - ongoing maintenance
11  *******************************************************************************/

12 package org.eclipse.jsch.internal.ui;
13
14 import java.net.URL JavaDoc;
15 import java.util.Hashtable JavaDoc;
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 JavaDoc ID="org.eclipse.jsch.ui"; //$NON-NLS-1$
27
public static final String JavaDoc DECORATOR_ID="org.eclipse.jsch.ui.decorator"; //$NON-NLS-1$
28

29   private static Hashtable JavaDoc imageDescriptors=new Hashtable JavaDoc(20);
30   /**
31    * The singleton plug-in instance
32    */

33   private static JSchUIPlugin plugin;
34   private ServiceTracker tracker;
35
36   public JSchUIPlugin(){
37     super();
38     plugin=this;
39   }
40
41   /**
42    * Returns the singleton plug-in instance.
43    *
44    * @return the plugin instance
45    */

46   public static JSchUIPlugin getPlugin(){
47     return plugin;
48   }
49
50   /**
51    * Returns the image descriptor for the given image ID.
52    * Returns null if there is no such image.
53    * @param id the id of the image descriptor
54    * @return the image descriptor
55    */

56   public static ImageDescriptor getImageDescriptor(String JavaDoc id){
57     return (ImageDescriptor)imageDescriptors.get(id);
58   }
59
60   /**
61    * Creates an image and places it in the image registry.
62    */

63   protected void createImageDescriptor(String JavaDoc id){
64     URL JavaDoc 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   /**
71    * Convenience method to get an image descriptor for an extension
72    *
73    * @param extension the extension declaring the image
74    * @param subdirectoryAndFilename the path to the image
75    * @return the image
76    */

77   public static ImageDescriptor getImageDescriptorFromExtension(IExtension extension, String JavaDoc subdirectoryAndFilename) {
78     URL JavaDoc fullPathString = FileLocator.find(Platform.getBundle(extension.getNamespaceIdentifier()), new Path(subdirectoryAndFilename), null);
79     return ImageDescriptor.createFromURL(fullPathString);
80   }
81
82   /**
83    * Initializes the table of images used in this plugin.
84    */

85   private void initializeImages() {
86     /*
87     // objects
88     createImageDescriptor(IUIConstants.IMG_REPOSITORY);
89     createImageDescriptor(IUIConstants.IMG_REFRESH);
90     createImageDescriptor(IUIConstants.IMG_REFRESH_ENABLED);
91     createImageDescriptor(IUIConstants.IMG_REFRESH_DISABLED);
92     createImageDescriptor(IUIConstants.IMG_LINK_WITH_EDITOR);
93     createImageDescriptor(IUIConstants.IMG_LINK_WITH_EDITOR_ENABLED);
94     createImageDescriptor(IUIConstants.IMG_COLLAPSE_ALL);
95     createImageDescriptor(IUIConstants.IMG_COLLAPSE_ALL_ENABLED);
96     createImageDescriptor(IUIConstants.IMG_NEWLOCATION);
97     createImageDescriptor(IUIConstants.IMG_CVSLOGO);
98     createImageDescriptor(IUIConstants.IMG_TAG);
99     createImageDescriptor(IUIConstants.IMG_MODULE);
100     createImageDescriptor(IUIConstants.IMG_CLEAR);
101     createImageDescriptor(IUIConstants.IMG_CLEAR_ENABLED);
102     createImageDescriptor(IUIConstants.IMG_CLEAR_DISABLED);
103     createImageDescriptor(IUIConstants.IMG_BRANCHES_CATEGORY);
104     createImageDescriptor(IUIConstants.IMG_VERSIONS_CATEGORY);
105     createImageDescriptor(IUIConstants.IMG_DATES_CATEGORY);
106     createImageDescriptor(IUIConstants.IMG_PROJECT_VERSION);
107     createImageDescriptor(IUIConstants.IMG_WIZBAN_MERGE);
108     createImageDescriptor(IUIConstants.IMG_WIZBAN_SHARE);
109     createImageDescriptor(IUIConstants.IMG_WIZBAN_DIFF);
110     createImageDescriptor(IUIConstants.IMG_WIZBAN_KEYWORD);
111     createImageDescriptor(IUIConstants.IMG_WIZBAN_NEW_LOCATION);
112     createImageDescriptor(IUIConstants.IMG_WIZBAN_IMPORT);
113     createImageDescriptor(IUIConstants.IMG_MERGEABLE_CONFLICT);
114     createImageDescriptor(IUIConstants.IMG_QUESTIONABLE);
115     createImageDescriptor(IUIConstants.IMG_MERGED);
116     createImageDescriptor(IUIConstants.IMG_EDITED);
117     createImageDescriptor(IUIConstants.IMG_NO_REMOTEDIR);
118     createImageDescriptor(IUIConstants.IMG_CVS_CONSOLE);
119     createImageDescriptor(IUIConstants.IMG_DATE);
120     createImageDescriptor(IUIConstants.IMG_CHANGELOG);
121     createImageDescriptor(IUIConstants.IMG_FILTER_HISTORY);
122     createImageDescriptor(IUIConstants.IMG_LOCALMODE);
123     createImageDescriptor(IUIConstants.IMG_LOCALREMOTE_MODE);
124     createImageDescriptor(IUIConstants.IMG_REMOTEMODE);
125     createImageDescriptor(IUIConstants.IMG_LOCALMODE_DISABLED);
126     createImageDescriptor(IUIConstants.IMG_LOCALREMOTE_MODE_DISABLED);
127     createImageDescriptor(IUIConstants.IMG_REMOTEMODE_DISABLED);
128     createImageDescriptor(IUIConstants.IMG_LOCALREVISION_TABLE);
129     createImageDescriptor(IUIConstants.IMG_REMOTEREVISION_TABLE);
130     createImageDescriptor(IUIConstants.IMG_COMPARE_VIEW);
131     */

132     
133     createImageDescriptor(IUIConstants.IMG_KEY_LOCK);
134
135     /*
136     // special
137     createImageDescriptor("glyphs/glyph1.gif"); //$NON-NLS-1$
138     createImageDescriptor("glyphs/glyph2.gif"); //$NON-NLS-1$
139     createImageDescriptor("glyphs/glyph3.gif"); //$NON-NLS-1$
140     createImageDescriptor("glyphs/glyph4.gif"); //$NON-NLS-1$
141     createImageDescriptor("glyphs/glyph5.gif"); //$NON-NLS-1$
142     createImageDescriptor("glyphs/glyph6.gif"); //$NON-NLS-1$
143     createImageDescriptor("glyphs/glyph7.gif"); //$NON-NLS-1$
144     createImageDescriptor("glyphs/glyph8.gif"); //$NON-NLS-1$
145     */

146   }
147   
148   /**
149    * @see Plugin#start(BundleContext)
150    */

151   public void start(BundleContext context) throws Exception JavaDoc {
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 JavaDoc{
166     super.stop(context);
167     tracker.close();
168   }
169   
170   public IJSchService getJSchService() {
171     return (IJSchService)tracker.getService();
172   }
173   
174
175   public URL JavaDoc getImageUrl(String JavaDoc relative){
176     return FileLocator.find(Platform.getBundle(ID), new Path(IUIConstants.ICON_PATH + relative), null);
177   }
178
179 }
180
Popular Tags