diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/plugin.xml b/build/org.eclipse.cdt.managedbuilder.core.tests/plugin.xml
index 42bb3e9f404..9e0a06463ee 100644
--- a/build/org.eclipse.cdt.managedbuilder.core.tests/plugin.xml
+++ b/build/org.eclipse.cdt.managedbuilder.core.tests/plugin.xml
@@ -6741,45 +6741,81 @@
+ projectType="org.eclipse.cdt.managedbuilder.core.tests.projectType">
+
+
+
+ projectType="org.eclipse.cdt.managedbuilder.core.tests.projectType">
+
+
+
+ projectType="org.eclipse.cdt.managedbuilder.core.tests.projectType">
+
+
+
+ projectType="org.eclipse.cdt.managedbuilder.core.tests.projectType">
+
+
+
+ projectType="org.eclipse.cdt.managedbuilder.core.tests.projectType">
+
+
+
+ projectType="org.eclipse.cdt.managedbuilder.core.tests.projectType">
+
+
+
+ projectType="org.eclipse.cdt.managedbuilder.core.tests.projectType">
+
+
+
+ projectType="org.eclipse.cdt.managedbuilder.core.tests.projectType">
+
+
+
+
+
diff --git a/build/org.eclipse.cdt.managedbuilder.gnu.ui/templates/projecttemplates/MakefileHelloWorldCCProject/template.properties b/build/org.eclipse.cdt.managedbuilder.gnu.ui/templates/projecttemplates/MakefileHelloWorldCCProject/template.properties
index aa80740199b..9dae7663857 100644
--- a/build/org.eclipse.cdt.managedbuilder.gnu.ui/templates/projecttemplates/MakefileHelloWorldCCProject/template.properties
+++ b/build/org.eclipse.cdt.managedbuilder.gnu.ui/templates/projecttemplates/MakefileHelloWorldCCProject/template.properties
@@ -10,8 +10,8 @@
###############################################################################
#Template Default Values
-MakefileHelloWorld.CCtemplate.label=Hello World C++ Project
-MakefileHelloWorld.CCtemplate.description=A Hello World C++ Project
+MakefileHelloWorld.CCtemplate.label=Hello World C++ Makefile Project
+MakefileHelloWorld.CCtemplate.description=A Hello World C++ Makefile Project
MakefileHelloWorld.basics.label=Basic Settings
MakefileHelloWorld.basics.description=Basic properties of a project
MakefileHelloWorld.author.label=Author
diff --git a/core/org.eclipse.cdt.core.tests/plugin.xml b/core/org.eclipse.cdt.core.tests/plugin.xml
index bec9aaf4b73..019bccf959b 100644
--- a/core/org.eclipse.cdt.core.tests/plugin.xml
+++ b/core/org.eclipse.cdt.core.tests/plugin.xml
@@ -82,6 +82,9 @@
isCategory="true"
location="resources/templateengine/AddFile.xml"
projectType="org.eclipse.cdt.core.tests.projectType">
+
+
+
+
+
+
+ projectType="org.eclipse.cdt.core.tests.projectType">
+
+
+
+ projectType="org.eclipse.cdt.core.tests.projectType">
+
+
+
+ projectType="org.eclipse.cdt.core.tests.projectType">
+
+
+
+ projectType="org.eclipse.cdt.core.tests.projectType">
+
+
+
+ projectType="org.eclipse.cdt.core.tests.projectType">
+
+
+
+
+
diff --git a/core/org.eclipse.cdt.core/schema/templates.exsd b/core/org.eclipse.cdt.core/schema/templates.exsd
index e5965ee056b..3c0b5750384 100644
--- a/core/org.eclipse.cdt.core/schema/templates.exsd
+++ b/core/org.eclipse.cdt.core/schema/templates.exsd
@@ -1,201 +1,245 @@
-
-
-
-
-
-
-
-
- This templates extension point facilitates the users to contribute their Template XMLs to the Template Engine plug-in.
-
-
-
-
-
-
- Extension point added to Template Engine plugin. Any plugin, which intends to contribute XML templates to the Template Engine must extend this extension point, and add the template element.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Id for the extension in the extender plugin.
-
-
-
-
-
-
- Optional name attribute.
-
-
-
-
-
-
-
-
-
-
-
-
- By adding the templates extension point the users can contribute their Template XMLs to the Template Engine plugin.
-
-
-
-
-
-
-
-
-
- A unique identifier for this template contribution. This does not need to be the same as the id of the template (as defined in template.xml) it is contributing. This allows contributing the same template.xml more than once (for example for multiple project types, or with alternate page sequences).
-
-
-
-
-
-
- The path of template.xml (relative to the base of the containing plug-in). For example "templates/TemplateOne/template.xml". This attribute is mandatory.
-
-
-
-
-
-
-
-
-
- This attribute is a project type id referring to the cdt project type that the template will be associated with. Project types are contributed to the org.eclipse.cdt.managedbuilder.core.buildDefinitions extension-point.
-This attribute is mandatory. CDT pre-defines the following values of the build artifact type property:
-<ul>
-<li>"org.eclipse.cdt.build.core.buildArtefactType.exe" - to represent executable
-<li>"org.eclipse.cdt.build.core.buildArtefactType.staticLib" - to represent static library
-<li>"org.eclipse.cdt.build.core.buildArtefactType.sharedLib" - to represent shared library
-<li>ISVs can define their own custom build artifact values by contributing to the org.eclipse.cdt.managedbuilder.core.buildProperties extension point.
-</ul>
-
-
-
-
-
-
- If true this template contribution should appear as a folder. Defaults to false.
-
-
-
-
-
-
- filterPattern is a java.util.regex.Pattern format string which is used to match against build configuration ids. This is an optional attribute, if absent will all configurations will match.
-
-
-
-
-
-
- A class that implements org.eclipse.cdt.templateengine.IPagesAfterTemplateSelectionProvider interface to create pages that will be appended to the pages returned from TemplatesChoiceWizard.getPagesAfterTemplateSelection().
-
-
-
-
-
-
-
-
-
-
-
-
- This element is used to reference an existing toolchain by its unique identifier.
-
-
-
-
-
-
- The unique identifier of a toolchain contributed to the org.eclipse.cdt.managedbuilder.core.buildDefinitions extension point.
-
-
-
-
-
-
-
-
-
-
-
- This extension point was added in CDT 4.0
-
-
-
-
-
-
-
-
- The following is an example of the extension point usage:
-<p>
-<pre>
- <extension point="org.eclipse.cdt.core.templates">
- <template
- id="org.foobar.templates.MyExampleTemplate"
- location="templates/MyExampleTemplate/template.xml"
- projectType="org.eclipse.cdt.build.core.buildArtefactType.exe"
- filterPattern=".*">
- </template>
- </extension>
-</pre>
-
-For more details on how to define your own templates, please check examples provided under <samp>org.eclipse.cdt.ui.templateengine</samp>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- An implementation of this extension point is supplied in <samp>org.eclipse.cdt.templateengine</samp>
-
-
-
-
-
-
-
-
- Copyright (c) 2007 Symbian Software Limited 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:
-Symbian - Initial API and implementation
-
-
-
-
+
+
+
+
+
+
+
+
+ This templates extension point facilitates the users to contribute their Template XMLs to the Template Engine plug-in.
+
+
+
+
+
+
+
+
+
+ Extension point added to Template Engine plugin. Any plugin, which intends to contribute XML templates to the Template Engine must extend this extension point, and add the template element.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Id for the extension in the extender plugin.
+
+
+
+
+
+
+ Optional name attribute.
+
+
+
+
+
+
+
+
+
+
+
+
+ By adding the templates extension point the users can contribute their Template XMLs to the Template Engine plugin.
+
+
+
+
+
+
+
+
+
+
+ A unique identifier for this template contribution. This does not need to be the same as the id of the template (as defined in template.xml) it is contributing. This allows contributing the same template.xml more than once (for example for multiple project types, or with alternate page sequences).
+
+
+
+
+
+
+ The path of template.xml (relative to the base of the containing plug-in). For example "templates/TemplateOne/template.xml". This attribute is mandatory.
+
+
+
+
+
+
+
+
+
+ This attribute is a project type id referring to the cdt project type that the template will be associated with. Project types are contributed to the org.eclipse.cdt.managedbuilder.core.buildDefinitions extension-point.
+This attribute is mandatory. CDT pre-defines the following values of the build artifact type property:
+<ul>
+<li>"org.eclipse.cdt.build.core.buildArtefactType.exe" - to represent executable
+<li>"org.eclipse.cdt.build.core.buildArtefactType.staticLib" - to represent static library
+<li>"org.eclipse.cdt.build.core.buildArtefactType.sharedLib" - to represent shared library
+<li>ISVs can define their own custom build artifact values by contributing to the org.eclipse.cdt.managedbuilder.core.buildProperties extension point.
+</ul>
+It's no longer manditory since templates are no longer organized by project type. Template catogories replace that functionality.
+
+
+
+
+
+
+ If true this template contribution should appear as a folder. Defaults to false.
+
+
+
+
+
+
+ filterPattern is a java.util.regex.Pattern format string which is used to match against build configuration ids. This is an optional attribute, if absent will all configurations will match.
+
+
+
+
+
+
+ A class that implements org.eclipse.cdt.templateengine.IPagesAfterTemplateSelectionProvider interface to create pages that will be appended to the pages returned from TemplatesChoiceWizard.getPagesAfterTemplateSelection().
+
+
+
+
+
+
+
+
+
+
+
+
+ This element is used to reference an existing toolchain by its unique identifier.
+
+
+
+
+
+
+ The unique identifier of a toolchain contributed to the org.eclipse.cdt.managedbuilder.core.buildDefinitions extension point.
+
+
+
+
+
+
+
+
+
+ Used to arrange templates in a hierarchy in the UI.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ id of parent category.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ This extension point was added in CDT 4.0
+
+
+
+
+
+
+
+
+ The following is an example of the extension point usage:
+<p>
+<pre>
+ <extension point="org.eclipse.cdt.core.templates">
+ <template
+ id="org.foobar.templates.MyExampleTemplate"
+ location="templates/MyExampleTemplate/template.xml"
+ projectType="org.eclipse.cdt.build.core.buildArtefactType.exe"
+ filterPattern=".*">
+ </template>
+ </extension>
+</pre>
+
+For more details on how to define your own templates, please check examples provided under <samp>org.eclipse.cdt.ui.templateengine</samp>
+
+
+
+
+
+
+
+
+ An implementation of this extension point is supplied in <samp>org.eclipse.cdt.templateengine</samp>
+
+
+
+
+
+
+
+
+ Copyright (c) 2007 Symbian Software Limited 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:
+Symbian - Initial API and implementation
+
+
+
+
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 parentCategoryIds;
+
+ public TemplateCategory(String id, String label, List parentCategoryIds) {
+ this.id = id;
+ this.label = label;
+ this.parentCategoryIds = parentCategoryIds;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public List 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 .
*/
- private Map> templateInfoMap;
+ private Map> templateInfoMap = new LinkedHashMap>();
+
+ Map categoryMap = new HashMap();
+
/**
* TemplateEngine constructor, create and initialise SharedDefaults.
*/
- private TemplateEngine() {
- templateInfoMap = new LinkedHashMap>();
+ 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 toolChainIdSet = new LinkedHashSet();
+ for (IConfigurationElement toolChainConfig : toolChainConfigs)
+ toolChainIdSet.add(toolChainConfig.getAttribute(TemplateEngineHelper.ID));
+
+ IConfigurationElement[] parentCategoryConfigs = config.getChildren("parentCategory"); //$NON-NLS-1$
+ List parentCategoryIds = new ArrayList();
+ 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());
+ }
+ (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 parentCategoryIds = new ArrayList();
+ for (IConfigurationElement parentCategoryConfig : parentCategoryConfigs)
+ parentCategoryIds.add(parentCategoryConfig.getAttribute("id")); //$NON-NLS-1$
- IConfigurationElement[] toolChainConfigs = config.getChildren(TemplateEngineHelper.TOOL_CHAIN);
- Set toolChainIdSet = new LinkedHashSet();
- for (int k=0; k < toolChainConfigs.length; k++) {
- toolChainIdSet.add(toolChainConfigs[k].getAttribute(TemplateEngineHelper.ID));
+ categoryMap.put(id, new TemplateCategory(id, label, parentCategoryIds));
}
-
- TemplateInfo templateInfo = new TemplateInfo(templateId, projectType, filterPattern, location,
- pluginId, toolChainIdSet,
- extraPagesProvider, isCategory);
- if (!templateInfoMap.containsKey(projectType)) {
- templateInfoMap.put(projectType, new ArrayList());
- }
- (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 parentCategoryIds;
+
+ public TemplateInfo2(String templateId, String projectTypeId, String filterPattern,
+ String templatePath, String pluginId, Set toolChainIdSet,
+ Object extraPagesProvider, boolean isCategory, List parentCategoryIds) {
+ super(templateId, projectTypeId, filterPattern, templatePath, pluginId, toolChainIdSet,
+ extraPagesProvider, isCategory);
+ this.parentCategoryIds = parentCategoryIds;
+ }
+
+ public List getParentCategoryIds() {
+ return parentCategoryIds;
+ }
+
+}
diff --git a/core/org.eclipse.cdt.ui.tests/plugin.xml b/core/org.eclipse.cdt.ui.tests/plugin.xml
index b281c1f38cf..0d2e6d193f1 100644
--- a/core/org.eclipse.cdt.ui.tests/plugin.xml
+++ b/core/org.eclipse.cdt.ui.tests/plugin.xml
@@ -113,12 +113,22 @@
location="resources/projectTemplates/testExtraPages/template.xml"
pagesAfterTemplateSelectionProvider="org.eclipse.cdt.ui.tests.templateengine.TestExtraPagesProvider"
projectType="org.eclipse.cdt.build.core.buildArtefactType.exe">
+
+
+
+
+
+
diff --git a/core/org.eclipse.cdt.ui/plugin.properties b/core/org.eclipse.cdt.ui/plugin.properties
index b1c9591dfa4..87d10a5f7ee 100644
--- a/core/org.eclipse.cdt.ui/plugin.properties
+++ b/core/org.eclipse.cdt.ui/plugin.properties
@@ -630,4 +630,4 @@ RefreshExclusionContributor.name = Resources
extension-point.name = Refresh Exclusion Contributor
# New New Project Wizard
-newProjectWizard.name = C/C++ Project (new)
+newProjectWizard.name = C/C++ Project (prototype)
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/TemplateSelectionPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/TemplateSelectionPage.java
index 7ca68f75895..049d2de04f8 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/TemplateSelectionPage.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/TemplateSelectionPage.java
@@ -11,22 +11,77 @@
package org.eclipse.cdt.ui.wizards;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.List;
+import org.eclipse.cdt.core.templateengine.TemplateCategory;
+import org.eclipse.cdt.core.templateengine.TemplateEngine2;
+import org.eclipse.cdt.core.templateengine.TemplateInfo2;
+import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.templateengine.Template;
import org.eclipse.cdt.ui.templateengine.TemplateEngineUI;
/**
- * @author Dad
+ * @author Doug Schaefer
* @since 5.4
*/
public class TemplateSelectionPage extends WizardPage {
+ private static class Node {
+ private final Object object;
+ private final Node parent;
+ private final List children = new LinkedList();
+
+ public Node(Node parent, Object object) {
+ this.parent = parent;
+ this.object = object;
+
+ if (parent != null)
+ parent.addChild(this);
+ }
+
+ private void addChild(Node child) {
+ children.add(child);
+ }
+
+ public Node getChild(Object child) {
+ for (Node childNode : children)
+ if (childNode.getObject().equals(child))
+ return childNode;
+ return null;
+ }
+
+ public Object getObject() {
+ return object;
+ }
+
+ public Node getParent() {
+ return parent;
+ }
+
+ public List getChildren() {
+ return children;
+ }
+ }
+
+ private final Node tree = new Node(null, null);
+ private final TemplateEngine2 coreEngine = TemplateEngine2.getDefault();
+ private final TemplateEngineUI uiEngine = TemplateEngineUI.getDefault();
+
public TemplateSelectionPage() {
super("templateSelection"); //$NON-NLS-1$
}
@@ -36,13 +91,82 @@ public class TemplateSelectionPage extends WizardPage {
Composite comp = new Composite(parent, SWT.NONE);
comp.setLayout(new GridLayout(1, false));
- List templateList = new List(comp, SWT.BORDER);
- templateList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-
- Template[] templates = TemplateEngineUI.getDefault().getTemplates();
- for (Template template : templates) {
- templateList.add(template.getLabel());
- }
+ TreeViewer templateTree = new TreeViewer(comp);
+ templateTree.getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ templateTree.setContentProvider(new ITreeContentProvider() {
+ @Override
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ @Override
+ public void dispose() {
+ }
+
+ @Override
+ public boolean hasChildren(Object element) {
+ if (element instanceof Node)
+ return !((Node)element).getChildren().isEmpty();
+ return false;
+ }
+
+ @Override
+ public Object getParent(Object element) {
+ if (element instanceof Node)
+ return ((Node)element).getParent();
+ return null;
+ }
+
+ @Override
+ public Object[] getElements(Object inputElement) {
+ if (inputElement instanceof Node)
+ return ((Node)inputElement).getChildren().toArray();
+ return null;
+ }
+
+ @Override
+ public Object[] getChildren(Object parentElement) {
+ if (parentElement instanceof Node)
+ return ((Node)parentElement).getChildren().toArray();
+ return null;
+ }
+ });
+ templateTree.setLabelProvider(new ILabelProvider() {
+ @Override
+ public void removeListener(ILabelProviderListener listener) {
+ }
+
+ @Override
+ public boolean isLabelProperty(Object element, String property) {
+ return false;
+ }
+
+ @Override
+ public void dispose() {
+ }
+
+ @Override
+ public void addListener(ILabelProviderListener listener) {
+ }
+
+ @Override
+ public String getText(Object element) {
+ if (element instanceof Node) {
+ Object object = ((Node)element).getObject();
+ if (object instanceof TemplateCategory)
+ return ((TemplateCategory)object).getLabel();
+ else if (object instanceof Template)
+ return ((Template)object).getLabel();
+ }
+ return element.toString();
+ }
+
+ @Override
+ public Image getImage(Object element) {
+ return null;
+ }
+ });
+ buildTree();
+ templateTree.setInput(tree);
setControl(comp);
}
@@ -52,4 +176,68 @@ public class TemplateSelectionPage extends WizardPage {
return true;
}
+ private void buildTree() {
+ Template[] templates = uiEngine.getTemplates();
+ for (Template template : templates) {
+ List parentCategoryIds = ((TemplateInfo2)template.getTemplateInfo()).getParentCategoryIds();
+ boolean inTree = false;
+ if (!parentCategoryIds.isEmpty()) {
+ for (String parentCategoryId : parentCategoryIds) {
+ List parents = getParents(parentCategoryId);
+ if (!parents.isEmpty()) {
+ for (Node parent : parents)
+ new Node(parent, template);
+ inTree = true;
+ }
+ }
+ }
+
+ if (!inTree) {
+ // no parents
+ new Node(tree, template);
+ }
+ }
+ }
+
+ private List getParents(String parentCategoryId) {
+ List nodes = new LinkedList();
+
+ TemplateCategory category = coreEngine.getCategory(parentCategoryId);
+ if (category == null) {
+ // undefined, log it
+ CUIPlugin.log(new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, "Undefined parent category " + parentCategoryId)); //$NON-NLS-1$
+ return nodes;
+ }
+
+ // Hook me up to my parents
+ List parentCategoryIds = category.getParentCategoryIds();
+ boolean inTree = false;
+ if (!parentCategoryIds.isEmpty()) {
+ for (String myParentId : parentCategoryIds) {
+ List parents = getParents(myParentId);
+ if (!parents.isEmpty()) {
+ for (Node parent : parents) {
+ Node node = parent.getChild(category);
+ if (node == null)
+ nodes.add(new Node(parent, category));
+ else
+ nodes.add(node);
+ }
+ inTree = true;
+ }
+ }
+ }
+
+ if (!inTree) {
+ // parents not found, I'm an orphan
+ Node node = tree.getChild(category);
+ if (node == null)
+ nodes.add(new Node(tree, category));
+ else
+ nodes.add(node);
+ }
+
+ return nodes;
+ }
+
}