diff options
Diffstat (limited to 'core/org.eclipse.cdt.core/templateengine/org/eclipse')
4 files changed, 170 insertions, 38 deletions
diff --git a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/TemplateCategory.java b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/TemplateCategory.java new file mode 100644 index 00000000000..265ee19d3a4 --- /dev/null +++ b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/TemplateCategory.java @@ -0,0 +1,44 @@ +/*******************************************************************************
+ * Copyright (c) 2012 Wind River Systems 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:
+ * Doug Schaefer - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.core.templateengine;
+
+import java.util.List;
+
+/**
+ * @author Doug Schaefer
+ * @since 5.4
+ */
+public class TemplateCategory {
+
+ private final String id;
+ private String label;
+ private List<String> parentCategoryIds;
+
+ public TemplateCategory(String id, String label, List<String> parentCategoryIds) {
+ this.id = id;
+ this.label = label;
+ this.parentCategoryIds = parentCategoryIds;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public List<String> getParentCategoryIds() {
+ return parentCategoryIds;
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/TemplateEngine.java b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/TemplateEngine.java index 54b8589731f..1ffac0e36e3 100644 --- a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/TemplateEngine.java +++ b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/TemplateEngine.java @@ -53,13 +53,15 @@ public class TemplateEngine { /** * This is a Map <WizardID, TemplateInfo>. */ - private Map<String, List<TemplateInfo>> templateInfoMap; + private Map<String, List<TemplateInfo>> templateInfoMap = new LinkedHashMap<String, List<TemplateInfo>>(); + + Map<String, TemplateCategory> categoryMap = new HashMap<String, TemplateCategory>(); + /** * TemplateEngine constructor, create and initialise SharedDefaults. */ - private TemplateEngine() { - templateInfoMap = new LinkedHashMap<String, List<TemplateInfo>>(); + TemplateEngine() { initializeTemplateInfoMap(); } @@ -190,7 +192,7 @@ public class TemplateEngine { */ public static TemplateEngine getDefault() { if(TEMPLATE_ENGINE==null) { - TEMPLATE_ENGINE = new TemplateEngine(); + TEMPLATE_ENGINE = new TemplateEngine2(); } return TEMPLATE_ENGINE; } @@ -201,48 +203,62 @@ public class TemplateEngine { * extension point "templates" */ private void initializeTemplateInfoMap() { - String templateId = null; - String location = null; - String pluginId = null; - String projectType = null; - String filterPattern = null; - boolean isCategory = false; - IExtension[] extensions = Platform.getExtensionRegistry().getExtensionPoint(TEMPLATES_EXTENSION_ID).getExtensions(); for(int i=0; i<extensions.length; i++) { IExtension extension = extensions[i]; IConfigurationElement[] configElements = extension.getConfigurationElements(); - pluginId = extension.getNamespaceIdentifier(); // Plug-in id of the extending plug-in. + String pluginId = extension.getNamespaceIdentifier(); // Plug-in id of the extending plug-in. for(int j=0; j<configElements.length; j++) { - Object /*IPagesAfterTemplateSelectionProvider*/ extraPagesProvider = null; IConfigurationElement config = configElements[j]; - templateId = config.getAttribute(TemplateEngineHelper.ID); - location = config.getAttribute(TemplateEngineHelper.LOCATION); - projectType = config.getAttribute(TemplateEngineHelper.PROJECT_TYPE); - filterPattern = config.getAttribute(TemplateEngineHelper.FILTER_PATTERN); - isCategory = Boolean.valueOf(config.getAttribute(TemplateEngineHelper.IS_CATEGORY)).booleanValue(); - String providerAttribute = config.getAttribute(TemplateEngineHelper.EXTRA_PAGES_PROVIDER); - if (providerAttribute != null) { - try { - extraPagesProvider = config.createExecutableExtension(TemplateEngineHelper.EXTRA_PAGES_PROVIDER); - } catch (CoreException e) { - CCorePlugin.log(CCorePlugin.createStatus("Unable to create extra pages for "+providerAttribute,e)); //$NON-NLS-1$ - } - } + String configName = config.getName(); + if (configName.equals("template")) { //$NON-NLS-1$ + Object /*IPagesAfterTemplateSelectionProvider*/ extraPagesProvider = null; + String templateId = config.getAttribute(TemplateEngineHelper.ID); + String location = config.getAttribute(TemplateEngineHelper.LOCATION); + String projectType = config.getAttribute(TemplateEngineHelper.PROJECT_TYPE); + if (projectType == null || projectType.isEmpty()) + projectType = TemplateEngine2.NEW_TEMPLATE; + String filterPattern = config.getAttribute(TemplateEngineHelper.FILTER_PATTERN); + boolean isCategory = Boolean.valueOf(config.getAttribute(TemplateEngineHelper.IS_CATEGORY)).booleanValue(); + String providerAttribute = config.getAttribute(TemplateEngineHelper.EXTRA_PAGES_PROVIDER); + if (providerAttribute != null) { + try { + extraPagesProvider = config.createExecutableExtension(TemplateEngineHelper.EXTRA_PAGES_PROVIDER); + } catch (CoreException e) { + CCorePlugin.log(CCorePlugin.createStatus("Unable to create extra pages for "+providerAttribute,e)); //$NON-NLS-1$ + } + } + + IConfigurationElement[] toolChainConfigs = config.getChildren(TemplateEngineHelper.TOOL_CHAIN); + Set<String> toolChainIdSet = new LinkedHashSet<String>(); + for (IConfigurationElement toolChainConfig : toolChainConfigs) + toolChainIdSet.add(toolChainConfig.getAttribute(TemplateEngineHelper.ID)); + + IConfigurationElement[] parentCategoryConfigs = config.getChildren("parentCategory"); //$NON-NLS-1$ + List<String> parentCategoryIds = new ArrayList<String>(); + for (IConfigurationElement parentCategoryConfig : parentCategoryConfigs) + parentCategoryIds.add(parentCategoryConfig.getAttribute("id")); //$NON-NLS-1$ + + TemplateInfo templateInfo = new TemplateInfo2(templateId, projectType, filterPattern, location, + pluginId, toolChainIdSet, + extraPagesProvider, isCategory, parentCategoryIds); + if (!templateInfoMap.containsKey(projectType)) { + templateInfoMap.put(projectType, new ArrayList<TemplateInfo>()); + } + (templateInfoMap.get(projectType)).add(templateInfo); + } else if (configName.equals("category")) { //$NON-NLS-1$ + String id = config.getAttribute("id"); //$NON-NLS-1$ + if (!id.contains(".")) //$NON-NLS-1$ + id = pluginId + "." + id; //$NON-NLS-1$ + String label = config.getAttribute("label"); //$NON-NLS-1$ + + IConfigurationElement[] parentCategoryConfigs = config.getChildren("parentCategory"); //$NON-NLS-1$ + List<String> parentCategoryIds = new ArrayList<String>(); + for (IConfigurationElement parentCategoryConfig : parentCategoryConfigs) + parentCategoryIds.add(parentCategoryConfig.getAttribute("id")); //$NON-NLS-1$ - IConfigurationElement[] toolChainConfigs = config.getChildren(TemplateEngineHelper.TOOL_CHAIN); - Set<String> toolChainIdSet = new LinkedHashSet<String>(); - for (int k=0; k < toolChainConfigs.length; k++) { - toolChainIdSet.add(toolChainConfigs[k].getAttribute(TemplateEngineHelper.ID)); - } - - TemplateInfo templateInfo = new TemplateInfo(templateId, projectType, filterPattern, location, - pluginId, toolChainIdSet, - extraPagesProvider, isCategory); - if (!templateInfoMap.containsKey(projectType)) { - templateInfoMap.put(projectType, new ArrayList<TemplateInfo>()); + categoryMap.put(id, new TemplateCategory(id, label, parentCategoryIds)); } - (templateInfoMap.get(projectType)).add(templateInfo); } } // Check for tool Chains added to the templates outside template info definition diff --git a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/TemplateEngine2.java b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/TemplateEngine2.java new file mode 100644 index 00000000000..1e172ca620c --- /dev/null +++ b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/TemplateEngine2.java @@ -0,0 +1,33 @@ +/*******************************************************************************
+ * Copyright (c) 2012 Wind River Systems 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:
+ * Doug Schaefer - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.core.templateengine;
+
+/**
+ * @author Doug Schaefer
+ * @since 5.4
+ */
+public class TemplateEngine2 extends TemplateEngine {
+
+ /**
+ * Project type for new templates. Default if not set in extension.
+ */
+ public static final String NEW_TEMPLATE = "newTemplate"; //$NON-NLS-1$
+
+ public static TemplateEngine2 getDefault() {
+ return (TemplateEngine2)TemplateEngine.getDefault();
+ }
+
+ public TemplateCategory getCategory(String id) {
+ return categoryMap.get(id);
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/TemplateInfo2.java b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/TemplateInfo2.java new file mode 100644 index 00000000000..478e0cf2618 --- /dev/null +++ b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/TemplateInfo2.java @@ -0,0 +1,39 @@ +/*******************************************************************************
+ * Copyright (c) 2012 Wind River Systems 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:
+ * Doug Schaefer - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.core.templateengine;
+
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Template info extended to include new stuff for new new project wizard UI.
+ *
+ * @author Doug Schaefer
+ * @since 5.4
+ */
+public class TemplateInfo2 extends TemplateInfo {
+
+ private List<String> parentCategoryIds;
+
+ public TemplateInfo2(String templateId, String projectTypeId, String filterPattern,
+ String templatePath, String pluginId, Set<String> toolChainIdSet,
+ Object extraPagesProvider, boolean isCategory, List<String> parentCategoryIds) {
+ super(templateId, projectTypeId, filterPattern, templatePath, pluginId, toolChainIdSet,
+ extraPagesProvider, isCategory);
+ this.parentCategoryIds = parentCategoryIds;
+ }
+
+ public List<String> getParentCategoryIds() {
+ return parentCategoryIds;
+ }
+
+}
|