Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 0a045bcc0ba0dd93554b09ffd0239d6127e3e197 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*******************************************************************************
 * Copyright (c) 2000, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.help.ui.internal.views;

import org.eclipse.core.runtime.*;
import org.eclipse.help.internal.search.*;
import org.eclipse.help.internal.search.federated.*;
import org.eclipse.help.ui.*;
import org.eclipse.help.ui.internal.*;
import org.eclipse.jface.preference.*;
import org.eclipse.jface.resource.*;
import org.eclipse.swt.graphics.*;

/**
 * Descriptor for a federated search engine participant.
 */
public class EngineDescriptor {
	private IConfigurationElement config;
	private Image image;
	private ISearchEngine engine;
	private ISearchScopeFactory factory;
	/**
	 * 
	 */
	public EngineDescriptor(IConfigurationElement config) {
		this.config = config;
	}
	public IConfigurationElement getConfig() {
		return config;
	}
	public IConfigurationElement [] getPages() {
		return config.getChildren("subpage");
	}
	
	public String getLabel() {
		return config.getAttribute(IHelpUIConstants.ATT_LABEL);		
	}
	public String getId() {
		return config.getAttribute(IHelpUIConstants.ATT_ID);
	}
	public boolean isEnabled() {
		String enabled = config.getAttribute(IHelpUIConstants.ATT_ENABLED);
		if (enabled!=null)
			return enabled.equals("true");
		return false;
	}
	public Image getIconImage() {
		if (image!=null)
			return image;
		String icon = config.getAttribute(IHelpUIConstants.ATT_ICON);
		if (icon!=null)
			image = HelpUIResources.getImage(icon);
		else
			image = HelpUIResources.getImage(IHelpUIConstants.IMAGE_HELP_SEARCH);
		return image;
	}
	public String getDescription() {
		String desc = null;
		IConfigurationElement [] children = config.getChildren(IHelpUIConstants.EL_DESC);
		if (children.length==1) 
			desc = children[0].getValue();
		return desc;
	}
	public ImageDescriptor getImageDescriptor() {
		ImageDescriptor desc=null;
		String icon = config.getAttribute(IHelpUIConstants.ATT_ICON);
		if (icon!=null)
			desc = HelpUIResources.getImageDescriptor(icon);
		else
			desc = HelpUIResources.getImageDescriptor(IHelpUIConstants.IMAGE_HELP_SEARCH);
		return desc;
	}
	public RootScopePage createRootPage(String scopeSetName) {
		try {
			Object obj = config.createExecutableExtension(IHelpUIConstants.ATT_PAGE_CLASS);
			if (obj instanceof RootScopePage) {
				RootScopePage page = (RootScopePage)obj;
				page.init(getId(), scopeSetName);
				return page;
			}
			else
				return null;
		}
		catch (CoreException e) {
			return null;
		}
	}
	public ISearchEngine getEngine() {
		if (engine==null) {
			String eclass = config.getAttribute(IHelpUIConstants.ATT_CLASS);
			if (eclass!=null) {
				try {
					Object obj = config.createExecutableExtension(IHelpUIConstants.ATT_CLASS);
					if (obj instanceof ISearchEngine) {
						engine = (ISearchEngine)obj;
					}
				}
				catch (CoreException e) {
					HelpUIPlugin.logWarning("Engine " + eclass + " cannot be instantiated");
				}
			}
		}
		return engine;
	}
	
	public ISearchScope createSearchScope(IPreferenceStore store) {
		if (factory==null) {
			String fclass = config.getAttribute(IHelpUIConstants.ATT_SCOPE_FACTORY);
			if (fclass!=null) {
				try {
					Object obj = config.createExecutableExtension(IHelpUIConstants.ATT_SCOPE_FACTORY);
					if (obj instanceof ISearchScopeFactory) {
						factory = (ISearchScopeFactory)obj;
					}
				}
				catch (CoreException e) {
                    HelpUIPlugin.logWarning("Scope factory " + fclass + " cannot be instantiated");
				}
			}
		}
		if (factory!=null)
			return factory.createSearchScope(store);
		else
			return null;
	}
}

Back to the top