-
Notifications
You must be signed in to change notification settings - Fork 192
/
TemplateExtension.java
88 lines (74 loc) · 2.63 KB
/
TemplateExtension.java
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
/*******************************************************************************
* Copyright (c) 2016 QNX Software Systems and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.tools.templates.ui.internal;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.osgi.framework.FrameworkUtil;
//FIXME: AF: reimplement as a service
public class TemplateExtension {
private Map<String, Template> templates;
private Map<String, Tag> tags;
private void init() {
if (templates != null)
return;
templates = new HashMap<>();
tags = new HashMap<>();
IExtensionRegistry registry = Platform.getExtensionRegistry();
IExtensionPoint point = registry.getExtensionPoint(FrameworkUtil.getBundle(getClass()).getSymbolicName(),
"templates"); //$NON-NLS-1$
// tags
Tag allTag = new Tag(Tag.ALL_ID, Messages.TemplateExtension_tag_all);
tags.put(allTag.getId(), allTag);
for (IConfigurationElement element : point.getConfigurationElements()) {
if (element.getName().equals("tag")) { //$NON-NLS-1$
Tag tag = new Tag(element);
tags.put(tag.getId(), tag);
}
}
// templates
for (IConfigurationElement element : point.getConfigurationElements()) {
if (element.getName().equals("template")) { //$NON-NLS-1$
Template template = new Template(this, element);
templates.put(template.getId(), template);
template.addTag(allTag);
}
}
// template extensions
for (IConfigurationElement element : point.getConfigurationElements()) {
if (element.getName().equals("templateExtension")) { //$NON-NLS-1$
String templateId = element.getAttribute("templateId"); //$NON-NLS-1$
Template template = templates.get(templateId);
if (template != null) {
for (IConfigurationElement tagRef : element.getChildren("tagReference")) { //$NON-NLS-1$
String tagId = tagRef.getAttribute("id"); //$NON-NLS-1$
Tag tag = tags.get(tagId);
if (tag != null) {
template.addTag(tag);
}
}
}
}
}
}
public Collection<Template> getTemplates() {
init();
return templates.values();
}
public Tag getTag(String id) {
init();
return tags.get(id);
}
}