Skip to main content
summaryrefslogtreecommitdiffstats
blob: 79c02832cc872d454f69b425e4b3797606193b45 (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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*******************************************************************************
 * Copyright (c) 2000, 2016 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.help.ui.internal.views;

import java.util.Dictionary;
import java.util.Hashtable;

import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.help.search.ISearchEngine;
import org.eclipse.help.search.ISearchScope;
import org.eclipse.help.ui.IEngineDescriptor;
import org.eclipse.help.ui.RootScopePage;
import org.eclipse.help.ui.internal.IHelpUIConstants;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;

/**
 * Descriptor for a federated search engine participant.
 */
public class EngineDescriptor implements IEngineDescriptor {
	public static final String P_MASTER = "__enabled__"; //$NON-NLS-1$

	private ISearchEngine engine;

	private IConfigurationElement config;

	private EngineDescriptorManager manager;

	private EngineTypeDescriptor etdesc;

	private Hashtable<String, Object> parameters;

	//private boolean removable;

	//private boolean enabled;

	private String id;

	private String label;

	private String desc;

	private boolean userDefined;

	/**
	 *
	 */
	public EngineDescriptor(IConfigurationElement config) {
		this.config = config;
	}

	public EngineDescriptor(EngineDescriptorManager manager) {
		this.manager = manager;
	}

	public void setEngineType(EngineTypeDescriptor etdesc) {
		this.etdesc = etdesc;
	}

	public void setEngineDescriptorManager(EngineDescriptorManager manager) {
		this.manager = manager;
	}

	public IConfigurationElement getConfig() {
		return config;
	}

	@Override
	public String getLabel() {
		if (label != null)
			return label;
		String clabel = null;
		if (config != null)
			clabel = config.getAttribute(IHelpUIConstants.ATT_LABEL);
		if (clabel == null)
			clabel = etdesc.getLabel();
		return clabel;
	}

	@Override
	public String getId() {
		if (id != null)
			return id;
		return config.getAttribute(IHelpUIConstants.ATT_ID);
	}

	@Override
	public String getEngineTypeId() {
		if (etdesc != null)
			return etdesc.getId();
		return config.getAttribute(IHelpUIConstants.ATT_ENGINE_TYPE_ID);
	}

	public boolean isEnabled() {
		if (userDefined)
			return true;
		String aenabled = config.getAttribute(IHelpUIConstants.ATT_ENABLED);
		if (aenabled != null)
			return aenabled.equals("true"); //$NON-NLS-1$
		return false;
	}

	public Image getIconImage() {
		return etdesc.getIconImage();
	}

	@Override
	public String getDescription() {
		if (desc != null)
			return desc;
		String cdesc = null;
		if (config != null) {
			IConfigurationElement[] children = config
					.getChildren(IHelpUIConstants.TAG_DESC);
			if (children.length == 1)
				cdesc = children[0].getValue();
		}
		if (cdesc == null)
			return etdesc.getDescription();
		return cdesc;
	}

	public IConfigurationElement[] getPages() {
		return etdesc.getPages();
	}

	public ImageDescriptor getImageDescriptor() {
		return etdesc.getImageDescriptor();
	}

	public RootScopePage createRootPage(String scopeSetName) {
		RootScopePage page = etdesc.createRootPage(scopeSetName);
		if (page != null) {
			//Dictionary parameters = getParameters();
			page.init(this, scopeSetName);
		}
		return page;
	}

	@Override
	public Dictionary<String, Object> getParameters() {
		if (parameters != null)
			return parameters;
		parameters = new Hashtable<>();
		parameters.put(P_MASTER, isEnabled() ? Boolean.TRUE : Boolean.FALSE);
		if (config != null) {
			IConfigurationElement[] params = config.getChildren("param"); //$NON-NLS-1$
			for (int i = 0; i < params.length; i++) {
				IConfigurationElement param = params[i];
				String name = param.getAttribute(IHelpUIConstants.ATT_NAME);
				String value = param.getAttribute(IHelpUIConstants.ATT_VALUE);
				if (name != null && value != null)
					parameters.put(name, value);
			}
		}
		return parameters;
	}

	public ISearchEngine getEngine() {
		if (engine == null) {
			engine = etdesc.createEngine();
		}
		return engine;
	}

	public ISearchScope createSearchScope(IPreferenceStore store) {
		return etdesc.createSearchScope(store, getId(), getParameters());
	}

	void setId(String id) {
		this.id = id;
	}

	@Override
	public void setLabel(String label) {
		if (isUserDefined()) {
			this.label = label;
			if (manager!=null)
				manager.notifyPropertyChange(this);
		}
	}

	@Override
	public void setDescription(String desc) {
		if (isUserDefined()) {
			this.desc = desc;
			if (manager!=null)
				manager.notifyPropertyChange(this);
		}
	}

	@Override
	public boolean isUserDefined() {
		return userDefined;
	}

	public void setUserDefined(boolean userDefined) {
		this.userDefined = userDefined;
	}
}

Back to the top