KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.util.Hashtable JavaDoc;
15
16 import org.eclipse.core.runtime.IConfigurationElement;
17 import org.eclipse.help.search.*;
18 import org.eclipse.help.ui.*;
19 import org.eclipse.help.ui.internal.IHelpUIConstants;
20 import org.eclipse.jface.preference.IPreferenceStore;
21 import org.eclipse.jface.resource.ImageDescriptor;
22 import org.eclipse.swt.graphics.Image;
23
24 /**
25  * Descriptor for a federated search engine participant.
26  */

27 public class EngineDescriptor implements IEngineDescriptor {
28     public static final String JavaDoc P_MASTER = "__enabled__"; //$NON-NLS-1$
29

30     private ISearchEngine engine;
31
32     private IConfigurationElement config;
33     
34     private EngineDescriptorManager manager;
35
36     private EngineTypeDescriptor etdesc;
37
38     private Hashtable JavaDoc parameters;
39
40     //private boolean removable;
41

42     //private boolean enabled;
43

44     private String JavaDoc id;
45
46     private String JavaDoc label;
47
48     private String JavaDoc desc;
49
50     private boolean userDefined;
51
52     /**
53      *
54      */

55     public EngineDescriptor(IConfigurationElement config) {
56         this.config = config;
57     }
58     
59     public EngineDescriptor(EngineDescriptorManager manager) {
60         this.manager = manager;
61     }
62
63     public void setEngineType(EngineTypeDescriptor etdesc) {
64         this.etdesc = etdesc;
65     }
66     
67     public void setEngineDescriptorManager(EngineDescriptorManager manager) {
68         this.manager = manager;
69     }
70
71     public IConfigurationElement getConfig() {
72         return config;
73     }
74
75     public String JavaDoc getLabel() {
76         if (label != null)
77             return label;
78         String JavaDoc clabel = null;
79         if (config != null)
80             clabel = config.getAttribute(IHelpUIConstants.ATT_LABEL);
81         if (clabel == null)
82             clabel = etdesc.getLabel();
83         return clabel;
84     }
85
86     public String JavaDoc getId() {
87         if (id != null)
88             return id;
89         return config.getAttribute(IHelpUIConstants.ATT_ID);
90     }
91
92     public String JavaDoc getEngineTypeId() {
93         if (etdesc != null)
94             return etdesc.getId();
95         return config.getAttribute(IHelpUIConstants.ATT_ENGINE_TYPE_ID);
96     }
97
98     public boolean isEnabled() {
99         if (userDefined)
100             return true;
101         String JavaDoc aenabled = config.getAttribute(IHelpUIConstants.ATT_ENABLED);
102         if (aenabled != null)
103             return aenabled.equals("true"); //$NON-NLS-1$
104
return false;
105     }
106
107     public Image getIconImage() {
108         return etdesc.getIconImage();
109     }
110
111     public String JavaDoc getDescription() {
112         if (desc != null)
113             return desc;
114         String JavaDoc cdesc = null;
115         if (config != null) {
116             IConfigurationElement[] children = config
117                     .getChildren(IHelpUIConstants.TAG_DESC);
118             if (children.length == 1)
119                 cdesc = children[0].getValue();
120         }
121         if (cdesc == null)
122             return etdesc.getDescription();
123         return cdesc;
124     }
125
126     public IConfigurationElement[] getPages() {
127         return etdesc.getPages();
128     }
129
130     public ImageDescriptor getImageDescriptor() {
131         return etdesc.getImageDescriptor();
132     }
133
134     public RootScopePage createRootPage(String JavaDoc scopeSetName) {
135         RootScopePage page = etdesc.createRootPage(scopeSetName);
136         if (page != null) {
137             //Dictionary parameters = getParameters();
138
page.init(this, scopeSetName);
139         }
140         return page;
141     }
142
143     public Dictionary JavaDoc getParameters() {
144         if (parameters != null)
145             return parameters;
146         parameters = new Hashtable JavaDoc();
147         parameters.put(P_MASTER, isEnabled() ? Boolean.TRUE : Boolean.FALSE);
148         if (config != null) {
149             IConfigurationElement[] params = config.getChildren("param"); //$NON-NLS-1$
150
for (int i = 0; i < params.length; i++) {
151                 IConfigurationElement param = params[i];
152                 String JavaDoc name = param.getAttribute(IHelpUIConstants.ATT_NAME);
153                 String JavaDoc value = param.getAttribute(IHelpUIConstants.ATT_VALUE);
154                 if (name != null && value != null)
155                     parameters.put(name, value);
156             }
157         }
158         return parameters;
159     }
160
161     public ISearchEngine getEngine() {
162         if (engine == null) {
163             engine = etdesc.createEngine();
164         }
165         return engine;
166     }
167
168     public ISearchScope createSearchScope(IPreferenceStore store) {
169         return etdesc.createSearchScope(store, getId(), getParameters());
170     }
171
172     void setId(String JavaDoc id) {
173         this.id = id;
174     }
175
176     public void setLabel(String JavaDoc label) {
177         if (isUserDefined()) {
178             this.label = label;
179             if (manager!=null)
180                 manager.notifyPropertyChange(this);
181         }
182     }
183
184     public void setDescription(String JavaDoc desc) {
185         if (isUserDefined()) {
186             this.desc = desc;
187             if (manager!=null)
188                 manager.notifyPropertyChange(this);
189         }
190     }
191
192     public boolean isUserDefined() {
193         return userDefined;
194     }
195
196     public void setUserDefined(boolean userDefined) {
197         this.userDefined = userDefined;
198     }
199 }
200
Popular Tags