1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-21 15:23:59 +02:00

Add real categories for templates. Organize selection in tree.

This commit is contained in:
Doug Schaefer 2012-01-27 13:40:32 -05:00
parent f13bdf3b33
commit 6fcb52fe97
11 changed files with 720 additions and 277 deletions

View file

@ -6741,45 +6741,81 @@
<extension
point="org.eclipse.cdt.core.templates">
<template
id="org.eclipse.cdt.managedbuilder.core.tests.templates.AppendToMBSStringOptionValue"
filterPattern=".*AppendToMBSStringOptionValue"
id="org.eclipse.cdt.managedbuilder.core.tests.templates.AppendToMBSStringOptionValue"
location="testdata/AppendToMBSStringOptionValue.xml"
projectType="org.eclipse.cdt.managedbuilder.core.tests.projectType"/>
projectType="org.eclipse.cdt.managedbuilder.core.tests.projectType">
<parentCategory
id="org.eclipse.cdt.managedbuilder.core.tests.mbsTests">
</parentCategory>
</template>
<template
id="org.eclipse.cdt.managedbuilder.core.tests.templates.AppendToMBSStringListOptionValues"
filterPattern=".*AppendToMBSStringListOptionValues"
id="org.eclipse.cdt.managedbuilder.core.tests.templates.AppendToMBSStringListOptionValues"
location="testdata/AppendToMBSStringListOptionValues.xml"
projectType="org.eclipse.cdt.managedbuilder.core.tests.projectType"/>
projectType="org.eclipse.cdt.managedbuilder.core.tests.projectType">
<parentCategory
id="org.eclipse.cdt.managedbuilder.core.tests.mbsTests">
</parentCategory>
</template>
<template
id="org.eclipse.cdt.managedbuilder.core.tests.templates.CreateIncludeFolder"
filterPattern=".*CreateIncludeFolder"
id="org.eclipse.cdt.managedbuilder.core.tests.templates.CreateIncludeFolder"
location="testdata/CreateIncludeFolder.xml"
projectType="org.eclipse.cdt.managedbuilder.core.tests.projectType"/>
projectType="org.eclipse.cdt.managedbuilder.core.tests.projectType">
<parentCategory
id="org.eclipse.cdt.managedbuilder.core.tests.mbsTests">
</parentCategory>
</template>
<template
id="org.eclipse.cdt.managedbuilder.core.tests.templates.ExcludeResources"
filterPattern=".*ExcludeResources"
id="org.eclipse.cdt.managedbuilder.core.tests.templates.ExcludeResources"
location="testdata/ExcludeResources.xml"
projectType="org.eclipse.cdt.managedbuilder.core.tests.projectType"/>
projectType="org.eclipse.cdt.managedbuilder.core.tests.projectType">
<parentCategory
id="org.eclipse.cdt.managedbuilder.core.tests.mbsTests">
</parentCategory>
</template>
<template
id="org.eclipse.cdt.managedbuilder.core.tests.templates.NewManagedProject"
filterPattern=".*NewManagedProject"
id="org.eclipse.cdt.managedbuilder.core.tests.templates.NewManagedProject"
location="testdata/NewManagedProject.xml"
projectType="org.eclipse.cdt.managedbuilder.core.tests.projectType"/>
projectType="org.eclipse.cdt.managedbuilder.core.tests.projectType">
<parentCategory
id="org.eclipse.cdt.managedbuilder.core.tests.mbsTests">
</parentCategory>
</template>
<template
id="org.eclipse.cdt.managedbuilder.core.tests.templates.SetMBSBooleanOptionValue"
filterPattern=".*SetMBSBooleanOptionValue"
id="org.eclipse.cdt.managedbuilder.core.tests.templates.SetMBSBooleanOptionValue"
location="testdata/SetMBSBooleanOptionValue.xml"
projectType="org.eclipse.cdt.managedbuilder.core.tests.projectType"/>
projectType="org.eclipse.cdt.managedbuilder.core.tests.projectType">
<parentCategory
id="org.eclipse.cdt.managedbuilder.core.tests.mbsTests">
</parentCategory>
</template>
<template
id="org.eclipse.cdt.managedbuilder.core.tests.templates.SetMBSStringOptionValue"
filterPattern=".*SetMBSStringOptionValue"
id="org.eclipse.cdt.managedbuilder.core.tests.templates.SetMBSStringOptionValue"
location="testdata/SetMBSStringOptionValue.xml"
projectType="org.eclipse.cdt.managedbuilder.core.tests.projectType"/>
projectType="org.eclipse.cdt.managedbuilder.core.tests.projectType">
<parentCategory
id="org.eclipse.cdt.managedbuilder.core.tests.mbsTests">
</parentCategory>
</template>
<template
id="org.eclipse.cdt.managedbuilder.core.tests.templates.SetMBSStringListOptionValues"
filterPattern=".*SetMBSStringListOptionValues"
id="org.eclipse.cdt.managedbuilder.core.tests.templates.SetMBSStringListOptionValues"
location="testdata/SetMBSStringListOptionValues.xml"
projectType="org.eclipse.cdt.managedbuilder.core.tests.projectType"/>
projectType="org.eclipse.cdt.managedbuilder.core.tests.projectType">
<parentCategory
id="org.eclipse.cdt.managedbuilder.core.tests.mbsTests">
</parentCategory>
</template>
<category
id="org.eclipse.cdt.managedbuilder.core.tests.mbsTests"
label="MBS Tests">
</category>
</extension>
<!-- 4.0 tests -->

View file

@ -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

View file

@ -82,6 +82,9 @@
isCategory="true"
location="resources/templateengine/AddFile.xml"
projectType="org.eclipse.cdt.core.tests.projectType">
<parentCategory
id="org.eclipse.cdt.core.tests.coreTests">
</parentCategory>
</template>
<template
id="org.eclipse.cdt.core.tests.templates.AddFiles"
@ -90,38 +93,68 @@
projectType="org.eclipse.cdt.core.tests.projectType">
<toolChain id="org.eclipse.cdt.core.tests.toolChain1"/>
<toolChain id="org.eclipse.cdt.core.tests.toolChain2"/>
<parentCategory
id="org.eclipse.cdt.core.tests.coreTests">
</parentCategory>
</template>
<template
id="org.eclipse.cdt.core.tests.templates.AddLink"
filterPattern=".*AddLink"
location="resources/templateengine/AddLink.xml"
projectType="org.eclipse.cdt.core.tests.projectType">
<parentCategory
id="org.eclipse.cdt.core.tests.coreTests">
</parentCategory>
</template>
<template
id="org.eclipse.cdt.core.tests.templates.Append"
filterPattern=".*Append"
id="org.eclipse.cdt.core.tests.templates.Append"
location="resources/templateengine/Append.xml"
projectType="org.eclipse.cdt.core.tests.projectType"/>
projectType="org.eclipse.cdt.core.tests.projectType">
<parentCategory
id="org.eclipse.cdt.core.tests.coreTests">
</parentCategory>
</template>
<template
id="org.eclipse.cdt.core.tests.templates.AppendCreate"
filterPattern=".*AppendCreate"
id="org.eclipse.cdt.core.tests.templates.AppendCreate"
location="resources/templateengine/AppendCreate.xml"
projectType="org.eclipse.cdt.core.tests.projectType"/>
projectType="org.eclipse.cdt.core.tests.projectType">
<parentCategory
id="org.eclipse.cdt.core.tests.coreTests">
</parentCategory>
</template>
<template
id="org.eclipse.cdt.core.tests.templates.Copy"
filterPattern=".*Copy"
id="org.eclipse.cdt.core.tests.templates.Copy"
location="resources/templateengine/Copy.xml"
projectType="org.eclipse.cdt.core.tests.projectType"/>
projectType="org.eclipse.cdt.core.tests.projectType">
<parentCategory
id="org.eclipse.cdt.core.tests.coreTests">
</parentCategory>
</template>
<template
id="org.eclipse.cdt.core.tests.templates.CreateResourceIdentifier"
filterPattern=".*CreateResourceIdentifier"
id="org.eclipse.cdt.core.tests.templates.CreateResourceIdentifier"
location="resources/templateengine/CreateResourceIdentifier.xml"
projectType="org.eclipse.cdt.core.tests.projectType"/>
projectType="org.eclipse.cdt.core.tests.projectType">
<parentCategory
id="org.eclipse.cdt.core.tests.coreTests">
</parentCategory>
</template>
<template
id="org.eclipse.cdt.core.tests.templates.CreateSourceFolder"
filterPattern=".*CreateSourceFolder"
id="org.eclipse.cdt.core.tests.templates.CreateSourceFolder"
location="resources/templateengine/CreateSourceFolder.xml"
projectType="org.eclipse.cdt.core.tests.projectType"/>
projectType="org.eclipse.cdt.core.tests.projectType">
<parentCategory
id="org.eclipse.cdt.core.tests.coreTests">
</parentCategory>
</template>
<category
id="org.eclipse.cdt.core.tests.coreTests"
label="Core Tests">
</category>
</extension>
<extension
point="org.eclipse.cdt.core.templateAssociations">

View file

@ -1,6 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="org.eclipse.cdt.core">
<schema targetNamespace="org.eclipse.cdt.core" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appInfo>
<meta.schema plugin="org.eclipse.cdt.core" id="templates" name="Template Extension point"/>
@ -12,14 +12,17 @@
<element name="extension">
<annotation>
<appInfo>
<meta.element />
</appInfo>
<documentation>
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.
</documentation>
</annotation>
<complexType>
<sequence>
<element ref="template" minOccurs="1" maxOccurs="unbounded"/>
<element ref="category" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
@ -57,6 +60,7 @@
<complexType>
<sequence>
<element ref="toolChain" minOccurs="0" maxOccurs="unbounded"/>
<element ref="parentCategory" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
<attribute name="id" type="string" use="required">
<annotation>
@ -75,7 +79,7 @@
</appInfo>
</annotation>
</attribute>
<attribute name="projectType" type="string" use="required">
<attribute name="projectType" type="string">
<annotation>
<documentation>
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.
@ -86,6 +90,7 @@ This attribute is mandatory. CDT pre-defines the following values of the build a
&lt;li&gt;&quot;org.eclipse.cdt.build.core.buildArtefactType.sharedLib&quot; - to represent shared library
&lt;li&gt;ISVs can define their own custom build artifact values by contributing to the org.eclipse.cdt.managedbuilder.core.buildProperties extension point.
&lt;/ul&gt;
It&apos;s no longer manditory since templates are no longer organized by project type. Template catogories replace that functionality.
</documentation>
</annotation>
</attribute>
@ -133,6 +138,54 @@ This attribute is mandatory. CDT pre-defines the following values of the build a
</complexType>
</element>
<element name="category">
<annotation>
<documentation>
Used to arrange templates in a hierarchy in the UI.
</documentation>
</annotation>
<complexType>
<sequence>
<element ref="parentCategory" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
<attribute name="id" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="label" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appInfo>
<meta.attribute translatable="true"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>
<element name="parentCategory">
<annotation>
<documentation>
id of parent category.
</documentation>
</annotation>
<complexType>
<attribute name="id" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
</complexType>
</element>
<annotation>
<appInfo>
<meta.section type="since"/>
@ -164,15 +217,6 @@ For more details on how to define your own templates, please check examples prov
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="apiInfo"/>
</appInfo>
<documentation>
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="implementation"/>

View file

@ -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;
}
}

View file

@ -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,26 +203,23 @@ 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 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 {
@ -232,17 +231,34 @@ public class TemplateEngine {
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));
}
for (IConfigurationElement toolChainConfig : toolChainConfigs)
toolChainIdSet.add(toolChainConfig.getAttribute(TemplateEngineHelper.ID));
TemplateInfo templateInfo = new TemplateInfo(templateId, projectType, filterPattern, location,
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);
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$
categoryMap.put(id, new TemplateCategory(id, label, parentCategoryIds));
}
}
}
// Check for tool Chains added to the templates outside template info definition

View file

@ -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);
}
}

View file

@ -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;
}
}

View file

@ -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">
<parentCategory
id="org.eclipse.cdt.ui.tests.uiTests">
</parentCategory>
</template>
<template
id="org.eclipse.cdt.ui.tests.testWidgets"
location="resources/projectTemplates/testWidgets/template.xml"
projectType="org.eclipse.cdt.build.core.buildArtefactType.exe">
<parentCategory
id="org.eclipse.cdt.ui.tests.uiTests">
</parentCategory>
</template>
<category
id="org.eclipse.cdt.ui.tests.uiTests"
label="UI Tests">
</category>
</extension>

View file

@ -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)

View file

@ -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<Node> children = new LinkedList<Node>();
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<Node> 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,14 +91,83 @@ 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<String> parentCategoryIds = ((TemplateInfo2)template.getTemplateInfo()).getParentCategoryIds();
boolean inTree = false;
if (!parentCategoryIds.isEmpty()) {
for (String parentCategoryId : parentCategoryIds) {
List<Node> 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<Node> getParents(String parentCategoryId) {
List<Node> nodes = new LinkedList<Node>();
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<String> parentCategoryIds = category.getParentCategoryIds();
boolean inTree = false;
if (!parentCategoryIds.isEmpty()) {
for (String myParentId : parentCategoryIds) {
List<Node> 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;
}
}