KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > ui > internal > views > EngineTypeDescriptor


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.help.ui.internal.views;
12
13 import java.util.Dictionary JavaDoc;
14
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.core.runtime.IConfigurationElement;
17 import org.eclipse.help.search.ISearchEngine;
18 import org.eclipse.help.search.ISearchScope;
19 import org.eclipse.help.ui.ISearchScopeFactory;
20 import org.eclipse.help.ui.RootScopePage;
21 import org.eclipse.help.ui.internal.HelpUIPlugin;
22 import org.eclipse.help.ui.internal.HelpUIResources;
23 import org.eclipse.help.ui.internal.IHelpUIConstants;
24 import org.eclipse.jface.preference.IPreferenceStore;
25 import org.eclipse.jface.resource.ImageDescriptor;
26 import org.eclipse.swt.graphics.Image;
27
28 /**
29  * Descriptor for a federated search engine participant.
30  */

31 public class EngineTypeDescriptor {
32     private IConfigurationElement config;
33     private Image image;
34     private ISearchScopeFactory factory;
35     /**
36      *
37      */

38     public EngineTypeDescriptor(IConfigurationElement config) {
39         this.config = config;
40     }
41     public IConfigurationElement getConfig() {
42         return config;
43     }
44     public IConfigurationElement [] getPages() {
45         return config.getChildren("subpage"); //$NON-NLS-1$
46
}
47     
48     public String JavaDoc getLabel() {
49         return config.getAttribute(IHelpUIConstants.ATT_LABEL);
50     }
51     public String JavaDoc getId() {
52         return config.getAttribute(IHelpUIConstants.ATT_ID);
53     }
54
55     public Image getIconImage() {
56         if (image!=null)
57             return image;
58         String JavaDoc icon = config.getAttribute(IHelpUIConstants.ATT_ICON);
59         if (icon!=null) {
60             String JavaDoc bundleId = config.getContributor().getName();
61             HelpUIResources.getImageDescriptor(bundleId, icon);
62             return HelpUIResources.getImage(icon);
63         }
64         image = HelpUIResources.getImage(IHelpUIConstants.IMAGE_HELP_SEARCH);
65         return image;
66     }
67     public String JavaDoc getDescription() {
68         String JavaDoc desc = null;
69         IConfigurationElement [] children = config.getChildren(IHelpUIConstants.TAG_DESC);
70         if (children.length==1)
71             desc = children[0].getValue();
72         return desc;
73     }
74     public ImageDescriptor getImageDescriptor() {
75         ImageDescriptor desc=null;
76         String JavaDoc icon = config.getAttribute(IHelpUIConstants.ATT_ICON);
77         if (icon!=null)
78             desc = HelpUIResources.getImageDescriptor(icon);
79         else
80             desc = HelpUIResources.getImageDescriptor(IHelpUIConstants.IMAGE_HELP_SEARCH);
81         return desc;
82     }
83     public RootScopePage createRootPage(String JavaDoc scopeSetName) {
84         try {
85             Object JavaDoc obj = config.createExecutableExtension(IHelpUIConstants.ATT_PAGE_CLASS);
86             if (obj instanceof RootScopePage) {
87                 RootScopePage page = (RootScopePage)obj;
88                 return page;
89             }
90             return null;
91         }
92         catch (CoreException e) {
93             return null;
94         }
95     }
96     public ISearchEngine createEngine() {
97         String JavaDoc eclass = config.getAttribute(IHelpUIConstants.ATT_CLASS);
98         if (eclass!=null) {
99             try {
100                 Object JavaDoc obj = config.createExecutableExtension(IHelpUIConstants.ATT_CLASS);
101                 if (obj instanceof ISearchEngine)
102                     return (ISearchEngine)obj;
103             }
104             catch (CoreException e) {
105                 HelpUIPlugin.logError("Engine " + eclass + " cannot be instantiated", null); //$NON-NLS-1$ //$NON-NLS-2$
106
}
107         }
108         return null;
109     }
110     
111     public ISearchScope createSearchScope(IPreferenceStore store, String JavaDoc engineId, Dictionary JavaDoc parameters) {
112         if (factory==null) {
113             String JavaDoc fclass = config.getAttribute(IHelpUIConstants.ATT_SCOPE_FACTORY);
114             if (fclass!=null) {
115                 try {
116                     Object JavaDoc obj = config.createExecutableExtension(IHelpUIConstants.ATT_SCOPE_FACTORY);
117                     if (obj instanceof ISearchScopeFactory) {
118                         factory = (ISearchScopeFactory)obj;
119                     }
120                 }
121                 catch (CoreException e) {
122                     HelpUIPlugin.logError("Scope factory " + fclass + " cannot be instantiated", null); //$NON-NLS-1$ //$NON-NLS-2$
123
}
124             }
125         }
126         if (factory!=null)
127             return factory.createSearchScope(store, engineId, parameters);
128         return null;
129     }
130 }
131
Popular Tags