diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/plugin.xml b/build/org.eclipse.cdt.managedbuilder.core.tests/plugin.xml
index 51ae714d352..fb1fef30d4f 100644
--- a/build/org.eclipse.cdt.managedbuilder.core.tests/plugin.xml
+++ b/build/org.eclipse.cdt.managedbuilder.core.tests/plugin.xml
@@ -6542,4 +6542,41 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/testdata/AppendToMBSStringListOptionValues.xml b/build/org.eclipse.cdt.managedbuilder.core.tests/testdata/AppendToMBSStringListOptionValues.xml
new file mode 100644
index 00000000000..3828ccc6c95
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.core.tests/testdata/AppendToMBSStringListOptionValues.xml
@@ -0,0 +1,44 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/testdata/AppendToMBSStringOptionValue.xml b/build/org.eclipse.cdt.managedbuilder.core.tests/testdata/AppendToMBSStringOptionValue.xml
new file mode 100644
index 00000000000..526809bacae
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.core.tests/testdata/AppendToMBSStringOptionValue.xml
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/testdata/Basename.cpp b/build/org.eclipse.cdt.managedbuilder.core.tests/testdata/Basename.cpp
new file mode 100644
index 00000000000..f3e3376e87c
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.core.tests/testdata/Basename.cpp
@@ -0,0 +1,37 @@
+/*
+============================================================================
+ Name : $(baseName).cpp
+ Author : $(author)
+ Version :
+ Copyright : $(copyright)
+ Description : Exe source file
+============================================================================
+*/
+
+// Include Files
+
+#include "$(baseName).h"
+
+// Defined Constants
+
+#define Constant "CONSTANT"
+
+
+// Global Variables
+
+static int globalValue;
+
+// Local Functions
+
+void printMessage(char* message) {
+ printf(message);
+}
+
+// Main Function
+
+int main(int nArgs, char **args) {
+ printMessage("Hello, world!\n");
+ printMessage("$(baseName)");
+}
+
+
diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/testdata/Basename.h b/build/org.eclipse.cdt.managedbuilder.core.tests/testdata/Basename.h
new file mode 100644
index 00000000000..3c5300af32d
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.core.tests/testdata/Basename.h
@@ -0,0 +1,27 @@
+/*
+============================================================================
+ Name : $(baseName).h
+ Author : $(author)
+ Version :
+ Copyright : $(copyright)
+ Description : Exe header file
+============================================================================
+*/
+
+#ifndef __$(baseName)_H__
+#define __$(baseName)_H__
+
+
+// Include Files
+
+#include
+
+
+// Function Prototypes
+
+void printMessage(char*);
+
+
+#endif // __$(baseName)_H__
+
+
diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/testdata/CreateIncludeFolder.xml b/build/org.eclipse.cdt.managedbuilder.core.tests/testdata/CreateIncludeFolder.xml
new file mode 100644
index 00000000000..dec5ff13268
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.core.tests/testdata/CreateIncludeFolder.xml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/testdata/ExcludeResources.xml b/build/org.eclipse.cdt.managedbuilder.core.tests/testdata/ExcludeResources.xml
new file mode 100644
index 00000000000..4334d98915b
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.core.tests/testdata/ExcludeResources.xml
@@ -0,0 +1,66 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/testdata/NewManagedProject.xml b/build/org.eclipse.cdt.managedbuilder.core.tests/testdata/NewManagedProject.xml
new file mode 100644
index 00000000000..240a362a8fe
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.core.tests/testdata/NewManagedProject.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/testdata/SetMBSBooleanOptionValue.xml b/build/org.eclipse.cdt.managedbuilder.core.tests/testdata/SetMBSBooleanOptionValue.xml
new file mode 100644
index 00000000000..eebe1fd11d7
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.core.tests/testdata/SetMBSBooleanOptionValue.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/testdata/SetMBSStringListOptionValues.xml b/build/org.eclipse.cdt.managedbuilder.core.tests/testdata/SetMBSStringListOptionValues.xml
new file mode 100644
index 00000000000..b83d7512a03
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.core.tests/testdata/SetMBSStringListOptionValues.xml
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/testdata/SetMBSStringOptionValue.xml b/build/org.eclipse.cdt.managedbuilder.core.tests/testdata/SetMBSStringOptionValue.xml
new file mode 100644
index 00000000000..50c089b8987
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.core.tests/testdata/SetMBSStringOptionValue.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/templateengine/tests/AllTemplateEngineTests.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/templateengine/tests/AllTemplateEngineTests.java
new file mode 100644
index 00000000000..ac589bfee3e
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/templateengine/tests/AllTemplateEngineTests.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.managedbuilder.templateengine.tests;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * This is a TestSuite, the TestCases created to test Template engine are
+ * added to testsuite.
+ * The test suite will execute all the Testcases added to the Suite.
+ *
+ * @since 4.0
+ */
+
+public class AllTemplateEngineTests extends TestSuite{
+
+ public static void main(String[] args) {
+ junit.swingui.TestRunner.run(AllTemplateEngineTests.class);
+ }
+
+ /**
+ * Since the TemplateEngine consists of UI(Wizard).
+ * A TestWizard is created to which the dynamically generated
+ * UIPages are added. The Wizard is launched from here.
+ * The TestCases created to test the TemplateEngine is initialized here.
+ * @return
+ *
+ * @since 4.0
+ */
+ public static Test suite() {
+ TestSuite suite = new TestSuite("Template engine tests"); //$NON-NLS-1$
+ //$JUnit-BEGIN$
+
+// suite.addTestSuite(TestProcesses.class);
+
+ //$JUnit-END$
+ return suite;
+ }
+}
diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/templateengine/tests/TemplateEngineTestsHelper.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/templateengine/tests/TemplateEngineTestsHelper.java
new file mode 100644
index 00000000000..f9505ecc88b
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/templateengine/tests/TemplateEngineTestsHelper.java
@@ -0,0 +1,159 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.managedbuilder.templateengine.tests;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.eclipse.cdt.core.templateengine.TemplateDescriptor;
+import org.eclipse.cdt.core.templateengine.TemplateEngine;
+import org.eclipse.cdt.managedbuilder.core.IConfiguration;
+import org.eclipse.cdt.managedbuilder.core.IProjectType;
+import org.eclipse.cdt.managedbuilder.core.IToolChain;
+import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceDescription;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.osgi.framework.Bundle;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+
+/**
+ *
+ * All supporting functions which are not part of Testing class.
+ *
+ * @since 4.0
+*/
+
+public class TemplateEngineTestsHelper {
+
+ public static final String LOGGER_FILE_NAME="TemplateEngineTests"; //$NON-NLS-1$
+ private static List projectTypes = new ArrayList();
+ private static List projectTypeNames = new ArrayList();
+
+ /**
+ * get the url of a xml template, by passing the xml file name.
+ * @param templateName
+ * @return URL
+ */
+ public static URL getTemplateURL(String templateName){
+ Bundle bundle = Platform.getBundle("org.eclipse.cdt.managedbuilder.core.tests"); //$NON-NLS-1$
+ URL url = FileLocator.find(bundle, new Path("testdata/"+templateName), null); //$NON-NLS-1$
+ if ( url != null )
+ {
+ try {
+ url = FileLocator.toFileURL(url);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ return url;
+ }
+
+ public static int getChildCount(TemplateDescriptor templateDescriptor, String propertyGroupID){
+ List list = templateDescriptor.getPropertyGroupList();
+ for (int i = 0, l = list.size(); i < l; i++) {
+ Element element = (Element) list.get(i);
+ NamedNodeMap attributes = element.getAttributes();
+ for (int j = 0, l1 = attributes.getLength(); j < l1; j++) {
+ String value = attributes.item(j).getNodeValue();
+ if (value.equals(propertyGroupID)) {
+ return TemplateEngine.getChildrenOfElement(element).size();
+ }
+ }
+ }
+ return 0;
+ }
+
+ public static boolean failIfErrorStatus(IStatus[] statuses) {
+ for(int i=0; i
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/templateengine/CreateProjectProgressMonitor.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/templateengine/CreateProjectProgressMonitor.java
new file mode 100644
index 00000000000..4b4de357748
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/templateengine/CreateProjectProgressMonitor.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.managedbuilder.templateengine;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+
+public class CreateProjectProgressMonitor extends NullProgressMonitor {
+
+ /**
+ * Constructs a new progress monitor.
+ */
+ public CreateProjectProgressMonitor() {
+ super();
+ }
+
+ public CreateProjectProgressMonitor(String taskName) {
+ super();
+ super.setTaskName(taskName);
+ }
+
+ /**
+ * Override this method to do something
+ * with the name of the task.
+ *
+ * @see IProgressMonitor#setTaskName(String)
+ */
+ public void setTaskName(String name) {
+ super.setTaskName(name);
+ }
+
+ /**
+ * This implementation sets the value of an internal state variable.
+ *
+ * @see IProgressMonitor#isCanceled()
+ * @see IProgressMonitor#setCanceled(boolean)
+ */
+ public void setCanceled(boolean cancelled) {
+ super.setCanceled(cancelled);
+ }
+
+ /**
+ * This implementation returns the value of the internal
+ * state variable set by setCanceled.
+ *
+ * @see IProgressMonitor#isCanceled()
+ * @see IProgressMonitor#setCanceled(boolean)
+ */
+ public boolean isCanceled() {
+ return super.isCanceled();
+ }
+
+
+
+}
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/templateengine/ProjectCreatedActions.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/templateengine/ProjectCreatedActions.java
new file mode 100644
index 00000000000..9660f26e246
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/templateengine/ProjectCreatedActions.java
@@ -0,0 +1,254 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.managedbuilder.templateengine;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.cdt.core.CCProjectNature;
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.CProjectNature;
+import org.eclipse.cdt.core.model.CoreModel;
+import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
+import org.eclipse.cdt.core.settings.model.ICProjectDescription;
+import org.eclipse.cdt.core.settings.model.extension.CConfigurationData;
+import org.eclipse.cdt.core.templateengine.TemplateEngineMessages;
+import org.eclipse.cdt.managedbuilder.buildproperties.IBuildProperty;
+import org.eclipse.cdt.managedbuilder.core.BuildException;
+import org.eclipse.cdt.managedbuilder.core.IBuilder;
+import org.eclipse.cdt.managedbuilder.core.IConfiguration;
+import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
+import org.eclipse.cdt.managedbuilder.core.IManagedProject;
+import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
+import org.eclipse.cdt.managedbuilder.internal.core.Configuration;
+import org.eclipse.cdt.managedbuilder.internal.core.ManagedBuildInfo;
+import org.eclipse.cdt.managedbuilder.internal.core.ManagedProject;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Preferences;
+
+/**
+ * This class is a helper for creating general CDT projects
+ */
+public class ProjectCreatedActions {
+ IProject project;
+ IPath projectLocation;
+ IConfiguration[] configs;
+ String artifactExtension;
+ private static final String PROPERTY = "org.eclipse.cdt.build.core.buildType"; //$NON-NLS-1$
+ private static final String PROP_VAL = PROPERTY + ".debug"; //$NON-NLS-1$
+
+ /*
+ * create a project and do things common to project creationr from the new project
+ * wizard.
+ */
+ public ProjectCreatedActions() {}
+
+ Map/**/ original2newConfigs;
+
+ /**
+ * Utility method that
+ *
+ *
Creates a CDT MBS project from an IProject
+ *
Autoexpands the project in the C/C++ Projects view
+ *
+ *
+ *
+ * @param project the IProject to turn into a CDT MBS project
+ * @param projType
+ * @param configs
+ * @param artifactExtn
+ * @return an IManagedBuildInfo instance (from which the IManagedProject can be retrieved)
+ * @throws CoreException
+ * @throws BuildException
+ */
+ public IManagedBuildInfo createProject(IProgressMonitor monitor, String indexerId, boolean isCProject) throws CoreException, BuildException {
+ if(!areFieldsValid()) {
+ throw new IllegalArgumentException(TemplateEngineMessages.getString("ProjectCreatedActions.InsufficientInformation")); //$NON-NLS-1$
+ }
+
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ IProjectDescription description = workspace.newProjectDescription(project.getName());
+
+ if ((projectLocation != null) && (!projectLocation.equals(Platform.getLocation()))) {
+ description.setLocation(projectLocation);
+ }
+
+ Preferences corePrefs = CCorePlugin.getDefault().getPluginPreferences();
+ corePrefs.setValue(CCorePlugin.PREF_INDEXER, indexerId);
+
+ CCorePlugin.getDefault().createCDTProject(description, project, monitor);
+ // Open the project if we have to
+ if (!project.isOpen()) {
+ project.open(monitor);
+ }
+
+ if (isCProject) {
+ CProjectNature.addCNature(project, monitor);
+ } else {
+ CProjectNature.addCNature(project, monitor);
+ CCProjectNature.addCCNature(project, monitor);
+ }
+
+ CoreModel coreModel = CoreModel.getDefault();
+ ICProjectDescription des = coreModel.createProjectDescription(project, false);
+ ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
+ ManagedProject newManagedProject = new ManagedProject(project, configs[0].getProjectType());
+ info.setManagedProject(newManagedProject);
+
+ original2newConfigs = new HashMap/**/();
+ ICConfigurationDescription active = null;
+ for(int i=0; i < configs.length; i++) {
+ IConfiguration config = configs[i];
+ if (config != null) {
+ String id = ManagedBuildManager.calculateChildId(config.getId(), null);
+ Configuration configuration = new Configuration(newManagedProject, (Configuration)config, id, false, true);
+ CConfigurationData data = configuration.getConfigurationData();
+ ICConfigurationDescription cfgDes = des.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data);
+ configuration.setConfigurationDescription(cfgDes);
+ configuration.exportArtifactInfo();
+ configuration.setArtifactExtension(artifactExtension);
+ original2newConfigs.put(config, (IConfiguration)configuration);
+
+ IBuilder builder = configuration.getEditableBuilder();
+ if (builder != null) {
+ builder.setManagedBuildOn(builder.isManagedBuildOn());
+ }
+
+ configuration.setName(config.getName());
+ configuration.setArtifactName(project.getName());
+
+ IBuildProperty buildProperty = configuration.getBuildProperties().getProperty(PROPERTY);
+ if (buildProperty != null && buildProperty.getValue() != null && PROP_VAL.equals(buildProperty.getValue().getId())) {
+ active = cfgDes;
+ } else if (active == null) {// select at least first configuration
+ active = cfgDes;
+ }
+ }
+ }
+
+ if (active != null) {
+ active.setActive();
+ }
+ coreModel.setProjectDescription(project, des);
+
+ info.setValid(true);
+ ManagedBuildManager.saveBuildInfo(project, true);
+
+ IStatus status = ManagedBuildManager.initBuildInfoContainer(project);
+ if (status.getCode() != IStatus.OK) {
+ ResourcesPlugin.getPlugin().getLog().log(status);
+ }
+
+ // Force the binary parser list to be updated for the project.
+ // An attempt is made to do this earlier when the project is being
+ // created, but the build info may not be ready then.
+ CCorePlugin.getDefault().getCProjectDescription(project, false).get(CCorePlugin.BINARY_PARSER_UNIQ_ID, true);
+
+ return info;
+ }
+
+ protected boolean areFieldsValid() {
+ return project!=null && configs!=null && artifactExtension!=null;
+ }
+
+ public IConfiguration getNewConfiguration(IConfiguration original) {
+ return (IConfiguration) original2newConfigs.get(original);
+ }
+
+ public Set/**/ getNewConfigurations(Collection/**/ originalConfigs) {
+ Set/**/ result = new HashSet/**/();
+ for(Iterator i = originalConfigs.iterator(); i.hasNext(); ) {
+ result.add(getNewConfiguration((IConfiguration)i.next()));
+ }
+ return result;
+ }
+
+ /**
+ * Chooses the IConfiguration which should be considered the project default.
+ * @param configs an array containing each of the newly created IConfigurations
+ * @return an element of the input array
+ */
+ protected IConfiguration chooseDefaultConfiguration(IConfiguration[] configs) {
+ return configs[0];
+ }
+
+ /**
+ * @param artifactExtension the artifactExtension to set
+ */
+ public void setArtifactExtension(String artifactExtension) {
+ this.artifactExtension = artifactExtension;
+ }
+
+
+ /**
+ * @return the configs
+ */
+ public IConfiguration[] getConfigs() {
+ return configs;
+ }
+
+
+ /**
+ * @param configs the configs to set
+ */
+ public void setConfigs(IConfiguration[] configs) {
+ this.configs = configs;
+ }
+
+
+ /**
+ * @return the project
+ */
+ public IProject getProject() {
+ return project;
+ }
+
+
+ /**
+ * @param project the project to set
+ */
+ public void setProject(IProject project) {
+ this.project = project;
+ }
+
+
+ /**
+ * @return the projectLocation
+ */
+ public IPath getProjectLocation() {
+ return projectLocation;
+ }
+
+
+ /**
+ * @param projectLocation the projectLocation to set
+ */
+ public void setProjectLocation(IPath projectLocation) {
+ this.projectLocation = projectLocation;
+ }
+
+
+ protected IConfiguration createNewConfiguration(IManagedProject managedProject, IConfiguration config) {
+ return managedProject.createConfiguration(config, config.getId() + "." + ManagedBuildManager.getRandomNumber()); //$NON-NLS-1$
+ }
+}
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/templateengine/processes/AppendToMBSStringListOptionValues.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/templateengine/processes/AppendToMBSStringListOptionValues.java
new file mode 100644
index 00000000000..15c95d605f0
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/templateengine/processes/AppendToMBSStringListOptionValues.java
@@ -0,0 +1,192 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.managedbuilder.templateengine.processes;
+
+import org.eclipse.cdt.core.templateengine.process.processes.Messages;
+import org.eclipse.cdt.core.templateengine.TemplateCore;
+import org.eclipse.cdt.core.templateengine.process.ProcessArgument;
+import org.eclipse.cdt.core.templateengine.process.ProcessFailureException;
+import org.eclipse.cdt.core.templateengine.process.ProcessRunner;
+import org.eclipse.cdt.managedbuilder.core.BuildException;
+import org.eclipse.cdt.managedbuilder.core.IConfiguration;
+import org.eclipse.cdt.managedbuilder.core.IHoldsOptions;
+import org.eclipse.cdt.managedbuilder.core.IOption;
+import org.eclipse.cdt.managedbuilder.core.IResourceConfiguration;
+import org.eclipse.cdt.managedbuilder.core.ITool;
+import org.eclipse.cdt.managedbuilder.core.IToolChain;
+import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceDescription;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+
+/**
+ * This class Appends contents to Managed Build System StringList Option Values.
+ */
+public class AppendToMBSStringListOptionValues extends ProcessRunner {
+
+ /**
+ * This method Appends contents to Managed Build System StringList Option Values.
+ */
+ public void process(TemplateCore template, ProcessArgument[] args, String processId, IProgressMonitor monitor) throws ProcessFailureException {
+ String projectName = args[0].getSimpleValue();
+ IProject projectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ IWorkspaceDescription workspaceDesc = workspace.getDescription();
+ boolean autoBuilding = workspaceDesc.isAutoBuilding();
+ workspaceDesc.setAutoBuilding(false);
+ try {
+ workspace.setDescription(workspaceDesc);
+ } catch (CoreException e) {//ignore
+ }
+
+ ProcessArgument[][] resourcePathObjects = args[1].getComplexArrayValue();
+ boolean modified = false;
+ for(int i=0; i
+ *
projectName the name of the project to exclude resources for. Must be a CDT Managed project.
+ *
configIdPattern a regular expression in java.util.regex.Pattern syntax for matching against the project configuration ids. The resources that
+ * match any of the regular expressions given in the filePatterns argument will be excluded for all matching project configurations.
+ *
filePatterns an array of regular expressions in java.util.regex.Pattern syntax for matching against project resources. The paths that
+ * will be matched against are workspace relative (include the project folder) and use forward slash as the file separator. That this argument is an
+ * array is purely to allow logically separate patterns to be given separately )rather than as one big string). If any of the regular expressions matches
+ * then the resource in question will be excluded for the matching configuration(s).
+ *
invertConfigMatching if this is set to "true" then the set of configurations for which resources matching any of the specified file patterns will
+ * be inverted. This enables you to specify which resources the files should not be excluded for without having to know what other configurations may exist.
+ *
+ */
+public class ExcludeResources extends ProcessRunner {
+
+ public void process(TemplateCore template, final ProcessArgument[] args, String processId, IProgressMonitor monitor) throws ProcessFailureException {
+ String projectName = args[0].getSimpleValue();
+ String configIdPattern = args[1].getSimpleValue();
+ final String[] filePatterns = args[2].getSimpleArrayValue();
+ String invertConfigMatching = args[3].getSimpleValue();
+
+ boolean invert = Boolean.valueOf(invertConfigMatching).booleanValue();
+
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+
+ IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
+ if(info==null) {
+ throw new ProcessFailureException(Messages.getString("ExcludeResources.0")); //$NON-NLS-1$
+ }
+ IManagedProject managedProject = info.getManagedProject();
+
+ /*
+ * Determine which configurations to exclude for
+ */
+ IConfiguration[] allConfigs = managedProject.getConfigurations();
+ List/**/ matchingConfigs = new ArrayList/**/();
+ for(int i=0; i
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/build/org.eclipse.cdt.managedbuilder.gnu.ui/templates/projecttemplates/EmptyProject/template.xml b/build/org.eclipse.cdt.managedbuilder.gnu.ui/templates/projecttemplates/EmptyProject/template.xml
new file mode 100644
index 00000000000..e623b54648e
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.gnu.ui/templates/projecttemplates/EmptyProject/template.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
diff --git a/build/org.eclipse.cdt.managedbuilder.gnu.ui/templates/projecttemplates/HelloWorldCAnsiProject/src/Basename.cpp b/build/org.eclipse.cdt.managedbuilder.gnu.ui/templates/projecttemplates/HelloWorldCAnsiProject/src/Basename.cpp
new file mode 100644
index 00000000000..c9fd0add173
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.gnu.ui/templates/projecttemplates/HelloWorldCAnsiProject/src/Basename.cpp
@@ -0,0 +1,20 @@
+/*
+============================================================================
+ Name : $(baseName).cpp
+ Author : $(author)
+ Version :
+ Copyright : $(copyright)
+ Description : Exe source file
+============================================================================
+*/
+/* Hello World in C, Ansi-style */
+
+#include
+#include
+
+int main(void)
+{
+ puts("$(message)");
+ return EXIT_SUCCESS;
+}
+
diff --git a/build/org.eclipse.cdt.managedbuilder.gnu.ui/templates/projecttemplates/HelloWorldCAnsiProject/template.xml b/build/org.eclipse.cdt.managedbuilder.gnu.ui/templates/projecttemplates/HelloWorldCAnsiProject/template.xml
new file mode 100644
index 00000000000..c04c5adf343
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.gnu.ui/templates/projecttemplates/HelloWorldCAnsiProject/template.xml
@@ -0,0 +1,56 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/build/org.eclipse.cdt.managedbuilder.gnu.ui/templates/projecttemplates/HelloWorldCCProject/src/Basename.cpp b/build/org.eclipse.cdt.managedbuilder.gnu.ui/templates/projecttemplates/HelloWorldCCProject/src/Basename.cpp
new file mode 100644
index 00000000000..ce61112f2af
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.gnu.ui/templates/projecttemplates/HelloWorldCCProject/src/Basename.cpp
@@ -0,0 +1,18 @@
+/*
+============================================================================
+ Name : $(baseName).cpp
+ Author : $(author)
+ Version :
+ Copyright : $(copyright)
+ Description : Exe source file
+============================================================================
+*/
+/* Hello World in C++, Ansi-style */
+#include
+using namespace std;
+
+int main ()
+{
+ cout << "$(message)" << endl; // prints $(message)
+ return 0;
+}
diff --git a/build/org.eclipse.cdt.managedbuilder.gnu.ui/templates/projecttemplates/HelloWorldCCProject/template.xml b/build/org.eclipse.cdt.managedbuilder.gnu.ui/templates/projecttemplates/HelloWorldCCProject/template.xml
new file mode 100644
index 00000000000..86ab82bd611
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.gnu.ui/templates/projecttemplates/HelloWorldCCProject/template.xml
@@ -0,0 +1,64 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/FileListControlFieldEditor.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/FileListControlFieldEditor.java
index 55c01100df7..44fc4f7927a 100644
--- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/FileListControlFieldEditor.java
+++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/FileListControlFieldEditor.java
@@ -20,6 +20,8 @@ import org.eclipse.cdt.managedbuilder.core.IHoldsOptions;
import org.eclipse.cdt.managedbuilder.core.IOption;
import org.eclipse.cdt.managedbuilder.internal.macros.OptionContextData;
import org.eclipse.cdt.managedbuilder.macros.IBuildMacroProvider;
+import org.eclipse.cdt.utils.ui.controls.FileListControl;
+import org.eclipse.cdt.utils.ui.controls.IFileListChangeListener;
import org.eclipse.core.resources.IResource;
import org.eclipse.jface.preference.FieldEditor;
import org.eclipse.jface.preference.IPreferenceStore;
diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/ManagedBuilderUIImages.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/ManagedBuilderUIImages.java
index 030ca985646..5072f847f86 100644
--- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/ManagedBuilderUIImages.java
+++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/ManagedBuilderUIImages.java
@@ -61,18 +61,6 @@ public class ManagedBuilderUIImages {
public static final String IMG_BUILD_CAT = NAME_PREFIX + "config-category.gif"; //$NON-NLS-1$
public static final ImageDescriptor DESC_BUILD_CAT = createManaged(T_BUILD, IMG_BUILD_CAT);
- // Image for file list control
- public static final String IMG_FILELIST_ADD = NAME_PREFIX + "list-add.gif"; //$NON-NLS-1$
- public static final ImageDescriptor DESC_FILELIST_ADD = createManaged(T_LIST, IMG_FILELIST_ADD);
- public static final String IMG_FILELIST_DEL = NAME_PREFIX + "list-delete.gif"; //$NON-NLS-1$
- public static final ImageDescriptor DESC_FILELIST_DEL = createManaged(T_LIST, IMG_FILELIST_DEL);
- public static final String IMG_FILELIST_EDIT = NAME_PREFIX + "list-edit.gif"; //$NON-NLS-1$
- public static final ImageDescriptor DESC_FILELIST_EDIT = createManaged(T_LIST, IMG_FILELIST_EDIT);
- public static final String IMG_FILELIST_MOVEUP = NAME_PREFIX + "list-moveup.gif"; //$NON-NLS-1$
- public static final ImageDescriptor DESC_FILELIST_MOVEUP = createManaged(T_LIST, IMG_FILELIST_MOVEUP);
- public static final String IMG_FILELIST_MOVEDOWN = NAME_PREFIX + "list-movedown.gif"; //$NON-NLS-1$
- public static final ImageDescriptor DESC_FILELIST_MOVEDOWN = createManaged(T_LIST, IMG_FILELIST_MOVEDOWN);
-
// new images
public static final String IMG_READ_ONLY = NAME_PREFIX + "read_only.gif"; //$NON-NLS-1$
public static final ImageDescriptor DESC_READ_ONLY = createManaged(T_OBJ, IMG_READ_ONLY);
diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/NewVarDialog.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/NewVarDialog.java
index 80228d40f9b..b16c94fe8f7 100644
--- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/NewVarDialog.java
+++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/NewVarDialog.java
@@ -22,6 +22,7 @@ import org.eclipse.cdt.managedbuilder.internal.macros.BuildMacro;
import org.eclipse.cdt.managedbuilder.macros.IBuildMacro;
import org.eclipse.cdt.ui.newui.UIMessages;
import org.eclipse.cdt.utils.cdtvariables.CdtVariableResolver;
+import org.eclipse.cdt.utils.ui.controls.FileListControl;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/AbstractCWizard.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/AbstractCWizard.java
index 0d261161cef..a0e0b29190a 100644
--- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/AbstractCWizard.java
+++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/AbstractCWizard.java
@@ -7,7 +7,8 @@
*
* Contributors:
* Intel Corporation - Initial API and implementation
- *******************************************************************************/package org.eclipse.cdt.managedbuilder.ui.wizards;
+ *******************************************************************************/
+package org.eclipse.cdt.managedbuilder.ui.wizards;
import java.util.Arrays;
import java.util.List;
@@ -56,4 +57,21 @@ public abstract class AbstractCWizard implements ICNewWizard {
return true; // No platform: nothing to check
}
+/* comment it out for now..
+ protected boolean isSupportedForTemplate(TemplateInfo templateInfo, IToolChain tc) {
+ String[] tcIds = templateInfo.getToolChainIds();
+ if (tcIds.length != 0) {
+ for (int i=0; i< tcIds.length; i++) {
+ if (tcIds[i].equals(tc.getId()) || tcIds[i].equals(tc.getSuperClass().getId())) {
+ return true;
+ }
+ }
+ return false;
+ } else {
+ return true;
+ }
+ }
+*/
+
+
}
diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/CDTConfigWizardPage.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/CDTConfigWizardPage.java
index 99cce78f3ce..8d94a335553 100644
--- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/CDTConfigWizardPage.java
+++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/CDTConfigWizardPage.java
@@ -108,7 +108,7 @@ public class CDTConfigWizardPage extends WizardPage {
public CfgHolder[] getCfgItems(boolean getDefault) {
CfgHolder[] its;
- if (getDefault)
+ if (getDefault || table == null)
its = getDefaultCfgs(handler);
else {
ArrayList out = new ArrayList(table.getItemCount());
diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/MBSWizardHandler.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/MBSWizardHandler.java
index 99fe20e6ead..2c9c38ccb50 100644
--- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/MBSWizardHandler.java
+++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/MBSWizardHandler.java
@@ -11,9 +11,11 @@
package org.eclipse.cdt.managedbuilder.ui.wizards;
import java.lang.reflect.InvocationTargetException;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
@@ -22,6 +24,7 @@ import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.extension.CConfigurationData;
+import org.eclipse.cdt.core.templateengine.process.ProcessFailureException;
import org.eclipse.cdt.managedbuilder.buildproperties.IBuildProperty;
import org.eclipse.cdt.managedbuilder.buildproperties.IBuildPropertyValue;
import org.eclipse.cdt.managedbuilder.core.IBuilder;
@@ -35,6 +38,11 @@ import org.eclipse.cdt.managedbuilder.internal.core.ManagedProject;
import org.eclipse.cdt.managedbuilder.ui.properties.ManagedBuilderUIPlugin;
import org.eclipse.cdt.managedbuilder.ui.properties.Messages;
import org.eclipse.cdt.ui.newui.CDTPrefUtil;
+import org.eclipse.cdt.ui.templateengine.Template;
+import org.eclipse.cdt.ui.templateengine.TemplateEngineUI;
+import org.eclipse.cdt.ui.templateengine.TemplateEngineUIUtil;
+import org.eclipse.cdt.ui.templateengine.pages.UIWizardPage;
+import org.eclipse.cdt.ui.wizards.CDTMainWizardPage;
import org.eclipse.cdt.ui.wizards.CWizardHandler;
import org.eclipse.cdt.ui.wizards.EntryDescriptor;
import org.eclipse.cdt.ui.wizards.IWizardItemsListListener;
@@ -79,7 +87,123 @@ public class MBSWizardHandler extends CWizardHandler implements ICBuildWizardHan
protected CDTConfigWizardPage fConfigPage;
private IToolChain[] savedToolChains = null;
private IWizard wizard;
- private EntryDescriptor entryDescriptor = null;
+ private IWizardPage startingPage;
+// private EntryDescriptor entryDescriptor = null;
+ private EntryInfo entryInfo;
+
+ protected static final class EntryInfo {
+ private EntryDescriptor entryDescriptor;
+ private Template template;
+ private boolean initialized;
+ private boolean isValid;
+ private String projectTypeId;
+ private String templateId;
+ private IWizardPage[] templatePages;
+ private IWizardPage predatingPage;
+ private IWizardPage followingPage;
+
+ public EntryInfo(EntryDescriptor dr){
+ entryDescriptor = dr;
+ }
+
+ public boolean isValid(){
+ initialize();
+ return isValid;
+ }
+
+ public Template getTemplate(){
+ initialize();
+ return template;
+ }
+
+ public EntryDescriptor getDescriptor(){
+ return entryDescriptor;
+ }
+
+ private void initialize(){
+ if(initialized)
+ return;
+
+ do {
+ if(entryDescriptor == null)
+ break;
+ String path[] = entryDescriptor.getPathArray();
+ if(path == null || path.length == 0)
+ break;
+
+ projectTypeId = path[0];
+ if(path.length > 1){
+ templateId = path[path.length - 1];
+ Template templates[] = TemplateEngineUI.getDefault().getTemplates(projectTypeId);
+ if(templates.length == 0)
+ break;
+
+ for(int i = 0; i < templates.length; i++){
+ if(templates[i].getTemplateId().equals(templateId)){
+ template = templates[i];
+ break;
+ }
+ }
+
+ if(template == null)
+ break;
+ }
+
+ isValid = true;
+ } while(false);
+
+ initialized = true;
+ }
+
+ public Template getInitializedTemplate(IWizardPage predatingPage, IWizardPage followingPage, Map map){
+ getNextPage(predatingPage, followingPage);
+
+ Template template = getTemplate();
+
+ if(template != null){
+ Map/**/ valueStore = template.getValueStore();
+// valueStore.clear();
+ for(int i=0; i < templatePages.length; i++) {
+ IWizardPage page = templatePages[i];
+ if (page instanceof UIWizardPage)
+ valueStore.putAll(((UIWizardPage)page).getPageData());
+ }
+ if (map != null) {
+ valueStore.putAll(map);
+ }
+ }
+ return template;
+ }
+
+ public IWizardPage getNextPage(IWizardPage predatingPage, IWizardPage followingPage) {
+ initialize();
+ if(this.templatePages == null
+ || this.predatingPage != predatingPage
+ || this.followingPage != followingPage){
+ this.predatingPage = predatingPage;
+ this.followingPage = followingPage;
+ if (template != null) {
+ this.templatePages = template.getTemplateWizardPages(predatingPage, followingPage, predatingPage.getWizard());
+ } else {
+ templatePages = new IWizardPage[0];
+ followingPage.setPreviousPage(predatingPage);
+ }
+ }
+
+ if(templatePages.length != 0)
+ return templatePages[0];
+ return followingPage;
+ }
+
+ public boolean canFinish(IWizardPage predatingPage, IWizardPage followingPage){
+ getNextPage(predatingPage, followingPage);
+ for(int i = 0; i < templatePages.length; i++){
+ if(!templatePages[i].isPageComplete())
+ return false;
+ }
+ return true;
+ }
+ }
public MBSWizardHandler(IProjectType _pt, Composite p, IWizard w) {
super(p, Messages.getString("CWizardHandler.0"), _pt.getName()); //$NON-NLS-1$
@@ -102,9 +226,43 @@ public class MBSWizardHandler extends CWizardHandler implements ICBuildWizardHan
if (w.getStartingPage() instanceof IWizardItemsListListener)
listener = (IWizardItemsListListener)w.getStartingPage();
wizard = w;
+ startingPage = w.getStartingPage();
}
}
+ protected IWizardPage getStartingPage(){
+ return startingPage;
+ }
+
+ public Map getMainPageData() {
+ CDTMainWizardPage page = (CDTMainWizardPage)getStartingPage();
+ Map data = new HashMap();
+ String projName = page.getProjectName();
+ projName = projName != null ? projName.trim() : ""; //$NON-NLS-1$
+ data.put("projectName", projName); //$NON-NLS-1$
+ data.put("baseName", getBaseName(projName)); //$NON-NLS-1$
+ data.put("baseNameUpper", getBaseName(projName).toUpperCase() ); //$NON-NLS-1$
+ data.put("baseNameLower", getBaseName(projName).toLowerCase() ); //$NON-NLS-1$
+ String location = page.getProjectLocationPath();
+ if(location == null)
+ location = ""; //$NON-NLS-1$
+ data.put("location", location); //getProjectLocation().toPortableString()); //$NON-NLS-1$
+ return data;
+ }
+
+ private String getBaseName(String name) {
+ String baseName = name;
+ int dot = baseName.lastIndexOf('.');
+ if (dot != -1) {
+ baseName = baseName.substring(dot + 1);
+ }
+ dot = baseName.indexOf(' ');
+ if (dot != -1) {
+ baseName = baseName.substring(0, dot);
+ }
+ return baseName;
+ }
+
public void handleSelection() {
List preferred = CDTPrefUtil.getPreferredTCs();
@@ -175,7 +333,7 @@ public class MBSWizardHandler extends CWizardHandler implements ICBuildWizardHan
if (defaults) {
cfgs = CDTConfigWizardPage.getDefaultCfgs(this);
} else {
- getSpecificPage(); // ensure that page is created
+ getConfigPage(); // ensure that page is created
cfgs = fConfigPage.getCfgItems(defaults);
if (cfgs == null || cfgs.length == 0)
cfgs = CDTConfigWizardPage.getDefaultCfgs(this);
@@ -225,14 +383,34 @@ public class MBSWizardHandler extends CWizardHandler implements ICBuildWizardHan
if (fConfigPage != null && fConfigPage.pagesLoaded)
doCustom();
}
-
- protected void doPostProcess(IProject prj) {}
- public IWizardPage getSpecificPage() {
+ protected void doPostProcess(IProject prj) {
+ if(entryInfo == null)
+ return;
+
+ Template template = entryInfo.getInitializedTemplate(getStartingPage(), getConfigPage(), getMainPageData());
+ if(template == null)
+ return;
+
+ IStatus[] statuses = template.executeTemplateProcesses(null, false);
+ if (statuses.length == 1 && statuses[0].getException() instanceof ProcessFailureException) {
+ TemplateEngineUIUtil.showError(statuses[0].getMessage(), statuses[0].getException());
+ }
+ }
+
+ protected CDTConfigWizardPage getConfigPage() {
if (fConfigPage == null) {
fConfigPage = new CDTConfigWizardPage(this);
}
- return fConfigPage;
+ return fConfigPage;
+ }
+
+ public IWizardPage getSpecificPage() {
+ return entryInfo.getNextPage(getStartingPage(), getConfigPage());
+// if (fConfigPage == null) {
+// fConfigPage = new CDTConfigWizardPage(this);
+// }
+// return fConfigPage;
}
/**
@@ -300,7 +478,7 @@ public class MBSWizardHandler extends CWizardHandler implements ICBuildWizardHan
return wizard;
}
public CfgHolder[] getCfgItems(boolean defaults) {
- getSpecificPage(); // ensure that page is created
+ getConfigPage(); // ensure that page is created
return fConfigPage.getCfgItems(defaults);
}
public String getErrorMessage() {
@@ -358,11 +536,16 @@ public class MBSWizardHandler extends CWizardHandler implements ICBuildWizardHan
}
public boolean isApplicable(EntryDescriptor data) {
- return true;
+ EntryInfo info = new EntryInfo(data);
+ return info.isValid();
}
public void initialize(EntryDescriptor data) throws CoreException {
- entryDescriptor = data;
+ EntryInfo info = new EntryInfo(data);
+ if(!info.isValid())
+ throw new CoreException(new Status(IStatus.ERROR, ManagedBuilderUIPlugin.getUniqueIdentifier(), "inappropriate descriptor"));
+
+ entryInfo = info;
}
/**
@@ -374,6 +557,10 @@ public class MBSWizardHandler extends CWizardHandler implements ICBuildWizardHan
* Note that full_tcs map should remain unchanged
*/
protected Set tc_filter(Set full) {
+ if(entryInfo == null)
+ return full;
+
+ EntryDescriptor entryDescriptor = entryInfo.getDescriptor();
if (entryDescriptor == null)
return full;
Set out = new LinkedHashSet(full.size());
@@ -406,10 +593,22 @@ public class MBSWizardHandler extends CWizardHandler implements ICBuildWizardHan
clone.pt = pt;
clone.listener = listener;
clone.wizard = wizard;
- clone.entryDescriptor = entryDescriptor; // the same !
+ clone.entryInfo = entryInfo; // the same !
clone.fConfigPage = fConfigPage; // the same !
clone.full_tcs = full_tcs; // the same !
}
return clone;
}
+
+ public boolean canFinich() {
+ if(entryInfo == null)
+ return false;
+
+ if(!entryInfo.canFinish(getStartingPage(), getConfigPage()))
+ return false;
+
+ return super.canFinich();
+ }
+
+
}
diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/STDWizardHandler.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/STDWizardHandler.java
index a0e5654ab24..2ea8694d767 100644
--- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/STDWizardHandler.java
+++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/STDWizardHandler.java
@@ -77,6 +77,8 @@ public class STDWizardHandler extends MBSWizardHandler {
des.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data);
}
coreModel.setProjectDescription(project, des);
+
+ doPostProcess(project);
}
public boolean canCreateWithoutToolchain() { return true; }
diff --git a/core/org.eclipse.cdt.core.tests/.classpath b/core/org.eclipse.cdt.core.tests/.classpath
index f0d7b046461..5b2e2ed7c08 100644
--- a/core/org.eclipse.cdt.core.tests/.classpath
+++ b/core/org.eclipse.cdt.core.tests/.classpath
@@ -6,6 +6,7 @@
+
diff --git a/core/org.eclipse.cdt.core.tests/build.properties b/core/org.eclipse.cdt.core.tests/build.properties
index f8584cb74a0..a249c7cb71d 100644
--- a/core/org.eclipse.cdt.core.tests/build.properties
+++ b/core/org.eclipse.cdt.core.tests/build.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2005, 2006 IBM Corporation and others.
+# Copyright (c) 2005, 2007 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
@@ -24,7 +24,8 @@ source.cdtcoretests.jar = failures/,\
parser/,\
suite/,\
misc/,\
- regression/
+ regression/,\
+ templateengine/
jre.compilation.profile=J2SE-1.4
javacSource=1.4
diff --git a/core/org.eclipse.cdt.core.tests/plugin.xml b/core/org.eclipse.cdt.core.tests/plugin.xml
index 1f18da7ae6e..c26068255f2 100644
--- a/core/org.eclipse.cdt.core.tests/plugin.xml
+++ b/core/org.eclipse.cdt.core.tests/plugin.xml
@@ -45,6 +45,7 @@
class="org.eclipse.cdt.internal.pdom.tests.GeneratePDOMApplicationTest$TestProjectProvider4">
+
@@ -61,4 +62,46 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java
index aa1e66eb93c..2318458a06b 100644
--- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java
+++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java
@@ -91,6 +91,8 @@ public class AutomatedIntegrationSuite extends TestSuite {
suite.addTestSuite(STLFailedTests.class);
suite.addTestSuite(FailedCompleteParseASTTest.class);
+// suite.addTest(AllTemplateEngineTests.suite());
+
return suite;
}
diff --git a/core/org.eclipse.cdt.core.tests/templateengine/org/eclipse/cdt/core/tests/templateengine/AllTemplateEngineTests.java b/core/org.eclipse.cdt.core.tests/templateengine/org/eclipse/cdt/core/tests/templateengine/AllTemplateEngineTests.java
new file mode 100644
index 00000000000..df276976f53
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/templateengine/org/eclipse/cdt/core/tests/templateengine/AllTemplateEngineTests.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.tests.templateengine;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * This is a TestSuite, the TestCases created to test Template engine are
+ * added to testsuite.
+ * The test suite will execute all the Testcases added to the Suite.
+ *
+ * @since 4.0
+ */
+
+public class AllTemplateEngineTests extends TestSuite{
+
+ public static void main(String[] args) {
+ junit.swingui.TestRunner.run(AllTemplateEngineTests.class);
+ }
+
+ /**
+ * Since the TemplateEngine consists of UI(Wizard).
+ * A TestWizard is created to which the dynamically generated
+ * UIPages are added. The Wizard is launched from here.
+ * The TestCases created to test the TemplateEngine is initialized here.
+ * @return
+ *
+ * @since 4.0
+ */
+ public static Test suite() {
+ TestSuite suite = new TestSuite("Template engine tests"); //$NON-NLS-1$
+ //$JUnit-BEGIN$
+
+ suite.addTestSuite(TestTemplateEngine.class);
+ suite.addTestSuite(TestTemplateCore.class);
+ suite.addTestSuite(TestValueStore.class);
+ suite.addTestSuite(TestSharedDefaults.class);
+ suite.addTestSuite(TestProcesses.class);
+
+ //$JUnit-END$
+ return suite;
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/templateengine/org/eclipse/cdt/core/tests/templateengine/TemplateEngineTestsHelper.java b/core/org.eclipse.cdt.core.tests/templateengine/org/eclipse/cdt/core/tests/templateengine/TemplateEngineTestsHelper.java
new file mode 100644
index 00000000000..a087fc5a36b
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/templateengine/org/eclipse/cdt/core/tests/templateengine/TemplateEngineTestsHelper.java
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.tests.templateengine;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.List;
+
+import junit.framework.Assert;
+
+import org.eclipse.cdt.core.templateengine.TemplateDescriptor;
+import org.eclipse.cdt.core.templateengine.TemplateEngine;
+import org.eclipse.cdt.core.testplugin.CTestPlugin;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceDescription;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.osgi.framework.Bundle;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+
+/**
+ *
+ * All supporting functions which are not part of Testing class.
+ *
+ * @since 4.0
+*/
+
+public class TemplateEngineTestsHelper {
+
+ public static final String LOGGER_FILE_NAME="TemplateEngineTests"; //$NON-NLS-1$
+
+ /**
+ * get the url of a xml template, by passing the xml file name.
+ * @param templateName
+ * @return URL
+ */
+ public static URL getTemplateURL(String templateName){
+ Bundle bundle = Platform.getBundle(CTestPlugin.PLUGIN_ID);
+ URL url = FileLocator.find(bundle, new Path("testdata/"+templateName), null); //$NON-NLS-1$
+ if ( url != null )
+ {
+ try {
+ url = FileLocator.toFileURL(url);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ return url;
+ }
+
+ public static int getChildCount(TemplateDescriptor templateDescriptor, String propertyGroupID){
+ List list = templateDescriptor.getPropertyGroupList();
+ for (int i = 0, l = list.size(); i < l; i++) {
+ Element element = (Element) list.get(i);
+ NamedNodeMap attributes = element.getAttributes();
+ for (int j = 0, l1 = attributes.getLength(); j < l1; j++) {
+ String value = attributes.item(j).getNodeValue();
+ if (value.equals(propertyGroupID)) {
+ return TemplateEngine.getChildrenOfElement(element).size();
+ }
+ }
+ }
+ return 0;
+ }
+
+ public static boolean failIfErrorStatus(IStatus[] statuses) {
+ for(int i=0; i 0);
+ }
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core.tests/templateengine/org/eclipse/cdt/core/tests/templateengine/TestTemplateEngine.java b/core/org.eclipse.cdt.core.tests/templateengine/org/eclipse/cdt/core/tests/templateengine/TestTemplateEngine.java
new file mode 100644
index 00000000000..98cf4fd551b
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/templateengine/org/eclipse/cdt/core/tests/templateengine/TestTemplateEngine.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.tests.templateengine;
+
+import junit.framework.TestCase;
+
+import org.eclipse.cdt.core.templateengine.TemplateEngine;
+
+/**
+ * Test the functionality of TemplateEngine.
+ */
+public class TestTemplateEngine extends TestCase {
+
+
+ TemplateEngine templateEngine = null;
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ templateEngine = TemplateEngine.getDefault();
+ }
+
+ /*
+ * @see TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ /**
+ * Constructor for TestTemplateEngine.
+ * @param name
+ */
+ public TestTemplateEngine(String name) {
+ super(name);
+ }
+
+ /**
+ * check for non null SharedDefaults
+ *
+ */
+ public void testSharedDefaults(){
+ assertNotNull(templateEngine.getSharedDefaults());
+ }
+
+ /**
+ * check that the instace is created once(Singleton).
+ */
+ public void testSingleton(){
+ assertSame(templateEngine, TemplateEngine.getDefault());
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core.tests/templateengine/org/eclipse/cdt/core/tests/templateengine/TestValueStore.java b/core/org.eclipse.cdt.core.tests/templateengine/org/eclipse/cdt/core/tests/templateengine/TestValueStore.java
new file mode 100644
index 00000000000..744d91f29d9
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/templateengine/org/eclipse/cdt/core/tests/templateengine/TestValueStore.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.tests.templateengine;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.eclipse.cdt.core.templateengine.TemplateCore;
+import org.eclipse.cdt.core.templateengine.TemplateDescriptor;
+import org.eclipse.cdt.core.templateengine.TemplateEngine;
+
+
+/**
+ * Test the functionality of the ValueStore class.
+ */
+public class TestValueStore extends TestCase {
+
+
+ /**
+ * setUp is called before execution of test method.
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ /**
+ * release resources held.
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public TestValueStore(String name) {
+ super(name);
+ }
+
+ /**
+ * Test ValueStore for Not Null condition.
+ *
+ */
+ public void testValueStoreNotNull(){
+ TemplateCore[] templates = TemplateEngine.getDefault().getTemplates();
+ for (int i=0; i
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/core/org.eclipse.cdt.core.tests/testdata/AddFiles.xml b/core/org.eclipse.cdt.core.tests/testdata/AddFiles.xml
new file mode 100644
index 00000000000..977c27b34a8
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/testdata/AddFiles.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/core/org.eclipse.cdt.core.tests/testdata/AddLink.xml b/core/org.eclipse.cdt.core.tests/testdata/AddLink.xml
new file mode 100644
index 00000000000..5612a96f994
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/testdata/AddLink.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/core/org.eclipse.cdt.core.tests/testdata/Append.xml b/core/org.eclipse.cdt.core.tests/testdata/Append.xml
new file mode 100644
index 00000000000..4bdb482078f
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/testdata/Append.xml
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/core/org.eclipse.cdt.core.tests/testdata/AppendCreate.xml b/core/org.eclipse.cdt.core.tests/testdata/AppendCreate.xml
new file mode 100644
index 00000000000..6f2bbb7e0c8
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/testdata/AppendCreate.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/core/org.eclipse.cdt.core.tests/testdata/Basename.cpp b/core/org.eclipse.cdt.core.tests/testdata/Basename.cpp
new file mode 100644
index 00000000000..f3e3376e87c
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/testdata/Basename.cpp
@@ -0,0 +1,37 @@
+/*
+============================================================================
+ Name : $(baseName).cpp
+ Author : $(author)
+ Version :
+ Copyright : $(copyright)
+ Description : Exe source file
+============================================================================
+*/
+
+// Include Files
+
+#include "$(baseName).h"
+
+// Defined Constants
+
+#define Constant "CONSTANT"
+
+
+// Global Variables
+
+static int globalValue;
+
+// Local Functions
+
+void printMessage(char* message) {
+ printf(message);
+}
+
+// Main Function
+
+int main(int nArgs, char **args) {
+ printMessage("Hello, world!\n");
+ printMessage("$(baseName)");
+}
+
+
diff --git a/core/org.eclipse.cdt.core.tests/testdata/Basename.h b/core/org.eclipse.cdt.core.tests/testdata/Basename.h
new file mode 100644
index 00000000000..3c5300af32d
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/testdata/Basename.h
@@ -0,0 +1,27 @@
+/*
+============================================================================
+ Name : $(baseName).h
+ Author : $(author)
+ Version :
+ Copyright : $(copyright)
+ Description : Exe header file
+============================================================================
+*/
+
+#ifndef __$(baseName)_H__
+#define __$(baseName)_H__
+
+
+// Include Files
+
+#include
+
+
+// Function Prototypes
+
+void printMessage(char*);
+
+
+#endif // __$(baseName)_H__
+
+
diff --git a/core/org.eclipse.cdt.core.tests/testdata/Copy.xml b/core/org.eclipse.cdt.core.tests/testdata/Copy.xml
new file mode 100644
index 00000000000..8fa2c96157d
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/testdata/Copy.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/core/org.eclipse.cdt.core.tests/testdata/CreateResourceIdentifier.xml b/core/org.eclipse.cdt.core.tests/testdata/CreateResourceIdentifier.xml
new file mode 100644
index 00000000000..fd5a43800c4
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/testdata/CreateResourceIdentifier.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/core/org.eclipse.cdt.core.tests/testdata/CreateSourceFolder.xml b/core/org.eclipse.cdt.core.tests/testdata/CreateSourceFolder.xml
new file mode 100644
index 00000000000..6faa32118c8
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/testdata/CreateSourceFolder.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/core/org.eclipse.cdt.core/.classpath b/core/org.eclipse.cdt.core/.classpath
index c23d8a7724e..7628a2b870a 100644
--- a/core/org.eclipse.cdt.core/.classpath
+++ b/core/org.eclipse.cdt.core/.classpath
@@ -5,6 +5,7 @@
+
diff --git a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF
index 4b16b1ed430..81d9531f208 100644
--- a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF
+++ b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF
@@ -37,6 +37,9 @@ Export-Package: org.eclipse.cdt.core,
org.eclipse.cdt.core.settings.model.extension,
org.eclipse.cdt.core.settings.model.extension.impl,
org.eclipse.cdt.core.settings.model.util,
+ org.eclipse.cdt.core.templateengine,
+ org.eclipse.cdt.core.templateengine.process,
+ org.eclipse.cdt.core.templateengine.process.processes,
org.eclipse.cdt.internal.core;x-friends:="org.eclipse.cdt.ui",
org.eclipse.cdt.internal.core.browser.util;x-friends:="org.eclipse.cdt.ui",
org.eclipse.cdt.internal.core.cdtvariables,
diff --git a/core/org.eclipse.cdt.core/build.properties b/core/org.eclipse.cdt.core/build.properties
index 53ae47b4681..2540a6ae901 100644
--- a/core/org.eclipse.cdt.core/build.properties
+++ b/core/org.eclipse.cdt.core/build.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2003, 2006 IBM Corporation and others.
+# Copyright (c) 2003, 2007 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
@@ -21,6 +21,7 @@ javadoc.packages = org.eclipse.cdt.core.*,\
org.eclipse.cdt.core.index.*,\
org.eclipse.cdt.core.model.*,\
org.eclipse.cdt.core.resources.*,\
+ org.eclipse.cdt.core.templateengine.*,\
org.eclipse.cdt.utils.*,\
org.eclipse.cdt.utils.elf.*,\
org.eclipse.cdt.utils.spawner.*
@@ -28,6 +29,7 @@ source.. = src/,\
model/,\
parser/,\
browser/,\
+ templateengine/,\
utils/
jre.compilation.profile=J2SE-1.4
@@ -36,6 +38,7 @@ javacTarget=1.4
source.library.jar = model/,\
browser/,\
src/,\
+ templateengine/,\
utils/,\
parser/
\ No newline at end of file
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CProjectDescription.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CProjectDescription.java
index e798815229e..3f31ce75cd5 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CProjectDescription.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CProjectDescription.java
@@ -116,7 +116,7 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon
if(cfg.getProjectDescription() != CProjectDescription.this)
throw new IllegalArgumentException();
- if(!fCfg.getId().equals(getId()))
+ if(!cfg.getId().equals(getId()))
return;
fIsModified = true;
diff --git a/core/org.eclipse.cdt.core/plugin.xml b/core/org.eclipse.cdt.core/plugin.xml
index 35e38695549..038e70b319d 100644
--- a/core/org.eclipse.cdt.core/plugin.xml
+++ b/core/org.eclipse.cdt.core/plugin.xml
@@ -624,7 +624,89 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/core/org.eclipse.cdt.core/schema/TemplateDescriptorSchema.xsd b/core/org.eclipse.cdt.core/schema/TemplateDescriptorSchema.xsd
new file mode 100644
index 00000000000..cca9d453c78
--- /dev/null
+++ b/core/org.eclipse.cdt.core/schema/TemplateDescriptorSchema.xsd
@@ -0,0 +1,220 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/core/org.eclipse.cdt.core/schema/templateProcessTypes.exsd b/core/org.eclipse.cdt.core/schema/templateProcessTypes.exsd
new file mode 100644
index 00000000000..6dcd8a8b554
--- /dev/null
+++ b/core/org.eclipse.cdt.core/schema/templateProcessTypes.exsd
@@ -0,0 +1,307 @@
+
+
+
+
+
+
+
+
+ This extension point is to be extended to define new processes to be used in template descriptors by template writers.
+
+
+
+
+
+
+ One or more elements of processType should be added as children to this element.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ This element defines a single process. A process is analogous to a procedure with a set of parameters. In similar terms, one can say that this element defines the prototype of this process procedure. One needs to specify all the parameters expected by this process. In the eventual template xml, one needs to specify arguments for the process matching the types and order of these parameters.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ The value of this attribute is used (fully qualified with the namespace in which the extension is declared), to uniquely identify this processType. e.g. a value such as AddFiles will mean that the usage in the template.xml should be something like <process type="<plugin_id>.AddFiles>
+
+
+
+
+
+
+ A class that extends org.eclipse.cdt.templateengine.process.ProcessRunner abstract class and implements all its abstract methods. This is the code that actually processes.
+
+
+
+
+
+
+
+
+
+
+
+
+ A simple string parameter. In the eventual template xml, one needs to specify the same name as the value of the name attribute of a simple argument alongwith the corresponding value attribute.
+
+
+
+
+
+
+ Name of the parameter. This should be used exactly as is in the name attribute of a simple argument in the template xml.
+
+
+
+
+
+
+ This is an optional attribute. If specified with a true value, it implies that the template xml need not mention this argument for this param. The attribute does not have any meaning in the context of a child of a complex param or of a child of a complexArray param.
+
+Another thing to note is that arguments corresponding to external=true type params, if not mentioned in the template xml, should be supplied directly through the ValueStore with the key as the param's name.
+
+If not mentioned, this attribute's is treated as false.
+
+
+
+
+
+
+ This is an optional attribute. If specified with a true value, it implies that the template xml need not mention the value attribute of the argument for this param. The attribute does not have any meaning in the context of a child of a complex param or of a child of a complexArray param.
+
+If not mentioned, this attribute's is treated as false.
+
+
+
+
+
+
+
+
+
+ A simple string array parameter. In the eventual template xml, one needs to specify the same name as the value of the name attribute of a simple-array argument alongwith the corresponding element children, one child per array element with the corresponding value attribute.
+
+
+
+
+
+
+ Name of the parameter. This should be used exactly as is in the name attribute of a simple-array argument in the template xml.
+
+
+
+
+
+
+
+
+
+ A complex parameter that groups together any number of simple, simpleArray, complex, complexArray parameters. This is equivalent of an object parameter. In the eventual template xml, one needs to specify the same name as the value of the name attribute of a simple argument alongwith the corresponding children, each child matching the type of the corresponding child of this element.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Name of the parameter. This should be used exactly as is in the name attribute of a complex argument in the template xml.
+
+
+
+
+
+
+
+
+
+ A complex array parameter. Each element of this parameter is of the same base complex type as specified by the baseType child of this element. In the eventual template xml, one needs to specify the same name as the value of the name attribute of a complex-array argument alongwith the corresponding element children, one child per array element with the corresponding complex type arguments (based on baseType definition).
+
+
+
+
+
+
+
+
+
+ Name of the parameter. This should be used exactly as is in the name attribute of a complex-array argument in the template xml.
+
+
+
+
+
+
+
+
+
+ This is not a direct parameter of a process. This simply acts as a complex grouping of parameters to be used as the base type of complexArray parameters.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ This extension point was added in CDT 4.0
+
+
+
+
+
+
+
+
+ The following is an example of the extension point usage:
+<p>
+<pre>
+ <extension
+ id="processExample"
+ name="Process Example"
+ point="org.eclipse.cdt.core.templateengine.processTypes">
+
+ <processType
+ name="NewManagedProject"
+ processRunner="org.eclipse.cdt.core.templateengine.process.processes.NewManagedProject">
+ <simple name="name"/>
+ <simple
+ external="true"
+ name="projectType"/>
+ <simple
+ external="true"
+ name="location"
+ nullable="true"/>
+ <simple name="targetType"/>
+ </processType>
+
+ <processType
+ name="SetMBSBooleanOptionValue"
+ processRunner="org.eclipse.cdt.core.templateengine.process.processes.SetMBSBooleanOptionValue">
+ <simple name="projectName"/>
+ <complexArray name="resourcePaths">
+ <baseType>
+ <simple name="id"/>
+ <simple name="value"/>
+ <simple name="path"/>
+ </baseType>
+ </complexArray>
+ </processType>
+
+ <processType
+ name="AddFile"
+ processRunner="org.eclipse.cdt.core.templateengine.process.processes.AddFile">
+ <simple name="projectName"/>
+ <complex name="file">
+ <simple name="source"/>
+ <simple name="target"/>
+ <simple name="replaceable"/>
+ </complex>
+ </processType>
+
+ <processType
+ name="AppendToMBSStringListOptionValues"
+ processRunner="org.eclipse.cdt.core.templateengine.process.processes.AppendToMBSStringListOptionValues">
+ <simple name="projectName"/>
+ <complexArray name="resourcePaths">
+ <baseType>
+ <simple name="id"/>
+ <simpleArray name="values"/>
+ <simple name="path"/>
+ </baseType>
+ </complexArray>
+ </processType>
+
+ </extension>
+</pre>
+
+For more details on how to define your own templates, please check examples provided under
+<samp>org.eclipse.cdt.gnu.templates</samp>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ An implementation of this extension point is supplied in <samp>org.eclipse.cdt.core.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:
+Bala Torati (Symbian) - Initial API and implementation
+
+
+
+
diff --git a/core/org.eclipse.cdt.core/schema/templates.exsd b/core/org.eclipse.cdt.core/schema/templates.exsd
new file mode 100644
index 00000000000..eee1c106792
--- /dev/null
+++ b/core/org.eclipse.cdt.core/schema/templates.exsd
@@ -0,0 +1,196 @@
+
+
+
+
+
+
+
+
+ This templates extension point facilitates the users to contribute their Template XMLs to the Template Engine plugin.
+
+
+
+
+
+
+ Extension point added to Template Engine plugin. Any plugin, which intends to contribute XML templates to Temaplate Engine has to extend this extension point, and add template element.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Id for the extension in the extender plugin.
+
+
+
+
+
+
+ Optional name attribute.
+
+
+
+
+
+
+
+
+
+
+
+
+ By adding the templates extension point the users can contribute there Template XMLs to the Template Engine plugin.
+
+
+
+
+
+
+
+
+
+ The location of the template(relative within the extender plugin).
+This is a must enter, attribute.
+
+
+
+
+
+
+
+
+
+ Any filterPatter associated with this Template to be used by TemplateEngine.
+This is an optional attribute.
+
+
+
+
+
+
+ A notation describing how this template is used. Usually used to filter the list of templates on offer depending on other wizard attributes.
+This is an optional attribute.
+
+
+
+
+
+
+ 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 extension point was added in CDT 4.0
+
+
+
+
+
+
+
+
+ The following is an example of the extension point usage:
+<p>
+<pre>
+ <extension
+ id="simpleEXETemplateExample"
+ name="Simple EXE Template Example"
+ point="org.eclipse.cdt.templateengine.templates">
+ <template
+ filterPattern=".*"
+ usageDescription="Simple EXE"
+ location="templates/org/eclipse/cdt/templates/projecttemplates/Simple EXE/template.xml"
+ projectType="org.eclipse.cdt.build.projectType.exe"
+ wizardId="org.eclipse.cdt.templates.ui.NewManagedProjectWizard">
+ </template>
+ </extension>
+</pre>
+
+For more details on how to define your own templates, please check examples provided under
+<samp>org.eclipse.cdt.templates</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/SharedDefaults.java b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/SharedDefaults.java
new file mode 100644
index 00000000000..7872ba64e37
--- /dev/null
+++ b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/SharedDefaults.java
@@ -0,0 +1,325 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.templateengine;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.Result;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+
+/**
+ * Processes the shared default values. Updates and Persists new key - value (default) pair
+ */
+
+public class SharedDefaults extends HashMap/**/ {
+ private static final long serialVersionUID = 0000000000L;
+
+ public Document document;
+ private File parsedXML;
+ private File backUpSharedXML;
+
+ /**
+ * HashMap's for persistence
+ */
+ private HashMap/**/ sharedDefaultsMap;
+ private HashMap/**/ persistDataMap;
+ private HashMap/**/ tableDataMap;
+
+ /**
+ * Two XML files here supports to provide consistent writing of data into
+ * them even during some destructive events which can happen during data
+ * persistence
+ */
+ private static final String SHARED_DEFAULTS_DOT_XML = "shareddefaults.xml"; //$NON-NLS-1$
+ private static final String SHARED_DEFAULTS_DOT_BACKUP_DOT_XML = "shareddefaults.backup.xml"; //$NON-NLS-1$
+
+ /**
+ * Static reference string for getting (GET) and storing (SET)
+ * shareddefaults.xml
+ */
+
+ public static final String SET = "SET"; //$NON-NLS-1$
+ public static final String GET = "GET"; //$NON-NLS-1$
+
+ /**
+ * Specifies the folder name present in the plugin
+ */
+ public static final String ResourceFolder = "resources"; //$NON-NLS-1$
+
+ /**
+ * Static reference of Singleton SharedDefault Instance
+ */
+ private static SharedDefaults SHAREDDEFAULTS = new SharedDefaults();
+
+ /**
+ * Returns static SharedDefaults Instance
+ *
+ * @return
+ */
+
+ public static SharedDefaults getInstance() {
+ return SHAREDDEFAULTS;
+ }
+
+ /**
+ * Default Constructor for creating and instantiating objects. On the
+ * startup of Template Engine, if it checks for the existence of
+ * TempSharedDefaultsXML file, then it is determined that the last Template
+ * Engine process under went some System destructive events and takes up
+ * reconstructive process to regain the consistent data by persisting all
+ * information first into temporary file and then into actual file.
+ */
+
+ public SharedDefaults() {
+ sharedDefaultsMap = new HashMap/**/();
+ persistDataMap = new HashMap/**/();
+ tableDataMap = new HashMap/**/();
+
+ // The conditional controls here is provided to have consistent
+ // data storage in the file during System crash or
+ // Power shutdown during data persistence into the file.
+
+ parsedXML = TemplateEngineHelper.getSharedDefaultLocation(SHARED_DEFAULTS_DOT_XML);
+ backUpSharedXML = TemplateEngineHelper.getSharedDefaultLocation(SHARED_DEFAULTS_DOT_BACKUP_DOT_XML);
+
+ if (backUpSharedXML.exists())
+ swapXML();
+
+ initSharedDefaults();
+ }
+
+ /**
+ * This method instantiates the SharedDefaults process by gathering XML
+ * document and creating shared key-value pair in HashMap. Also creates a
+ * new XML file if none exists and adds the default XML format.
+ */
+
+ private void initSharedDefaults() {
+ String key = null;
+ String value = null;
+
+ try {
+ long length = parsedXML.length();
+ // Adds defaultXML format if the file length is zero
+ if (length == 0) {
+ parsedXML = createDefaultXMLFormat(parsedXML);
+ }
+ document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(parsedXML.toURL().openStream());
+ } catch (Exception exp) {
+ TemplateEngineUtil.log(exp);
+ }
+
+ List/**/ sharedElementList = TemplateEngine.getChildrenOfElement(document.getDocumentElement());
+ int listSize = sharedElementList.size();
+ for (int i = 0; i < listSize; i++) {
+ Element xmlElement = (Element) sharedElementList.get(i);
+ key = xmlElement.getAttribute(TemplateEngineHelper.ID);
+ value = xmlElement.getAttribute(TemplateEngineHelper.VALUE);
+ if (key != null && !key.trim().equals("")) {
+ sharedDefaultsMap.put(key, value);
+ }
+ }
+ }
+
+ /**
+ * This method updates the HashMap with new key-value pair into the XML file
+ *
+ * @param sharedMap
+ */
+
+ public void updateShareDefaultsMap(Map/**/ sharedMap) {
+ sharedDefaultsMap.putAll(sharedMap);
+ persistSharedValueMap();
+ }
+
+ /**
+ * This method persists the latest data (HashMap) in the XML file New data
+ * obtained from the PreferencePage GUI.
+ */
+
+ public void persistSharedValueMap() {
+ generateSharedXML(backUpSharedXML);
+ generateSharedXML(parsedXML);
+ swapXML();
+ }
+
+ /**
+ * This method returns the latest key value pair (HashMap)
+ *
+ * @return HashMap
+ */
+
+ public Map/**/ getSharedDefaultsMap() {
+ return sharedDefaultsMap;
+ }
+
+ /**
+ * Adds data to the backend XML (persistence) Data obtained from the
+ * PreferencePage GUI.
+ */
+
+ public void addToBackEndStorage(String name, String value) {
+ if (sharedDefaultsMap != null) {
+ tableDataMap.putAll(sharedDefaultsMap);
+ }
+
+ tableDataMap.put(name, value);
+ updateShareDefaultsMap(tableDataMap);
+ }
+
+ /**
+ * Updates backend with changed value for a specific key(name)
+ *
+ * @param updateName
+ * @param updateValue
+ */
+
+ public void updateToBackEndStorage(String updateName, String updateValue) {
+ try {
+ document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(parsedXML.toURL().openStream());
+ } catch (Exception exp) {
+ TemplateEngineUtil.log(exp);
+ }
+
+ persistDataMap.putAll(sharedDefaultsMap);
+ List/**/ sharedElementList = TemplateEngine.getChildrenOfElement(document.getDocumentElement());
+ int elementListSize = sharedElementList.size();
+
+ for (int i = 0; i < elementListSize; i++) {
+ Element xmlElement = (Element) sharedElementList.get(i);
+ String name = xmlElement.getAttribute(TemplateEngineHelper.ID);
+
+ if (updateName.equals(name)) {
+ persistDataMap.put(updateName, updateValue);
+ }
+ }
+
+ updateShareDefaultsMap(persistDataMap);
+ }
+
+ /**
+ * Deletes the key-value pair from the backend with Key as identifier.
+ *
+ * @param deleteName
+ */
+ public void deleteBackEndStorage(String[] deleteName) {
+
+ try {
+ document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(parsedXML.toURL().openStream());
+ } catch (Exception exp) {
+ TemplateEngineUtil.log(exp);
+ }
+
+ List/**/ sharedElementList = TemplateEngine.getChildrenOfElement(document.getDocumentElement());
+ int elementListSize = sharedElementList.size();
+ for (int i = 0; i < elementListSize; i++) {
+
+ Element xmlElement = (Element) sharedElementList.get(i);
+ String name = xmlElement.getAttribute(TemplateEngineHelper.ID);
+
+ for (int k = 0; k < deleteName.length; k++) {
+ if (deleteName[k].equals(name)) {
+ xmlElement.removeAttribute(name);
+ sharedDefaultsMap.remove(name);
+ }
+ }
+ }
+
+ updateShareDefaultsMap(sharedDefaultsMap);
+ }
+
+ /**
+ * This method returns the default XMLFormat for the newly created XML file
+ *
+ * @param parsedXML
+ * @return
+ */
+
+ private File createDefaultXMLFormat(File xmlFile) {
+ Document d;
+ try {
+ d = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
+ } catch (ParserConfigurationException e) {
+ TemplateEngineUtil.log(e);
+ return xmlFile;
+ }
+ Node rootElement = d.appendChild(d.createElement("SharedRoot")); //$NON-NLS-1$
+ Element element = (Element) rootElement.appendChild(d.createElement("SharedProperty")); //$NON-NLS-1$
+ element.setAttribute(TemplateEngineHelper.ID, ""); //$NON-NLS-1$
+ element.setAttribute(TemplateEngineHelper.VALUE, ""); //$NON-NLS-1$
+
+ DOMSource domSource = new DOMSource(d);
+ TransformerFactory transFactory = TransformerFactory.newInstance();
+ Result fileResult = new StreamResult(xmlFile);
+ try {
+ transFactory.newTransformer().transform(domSource, fileResult);
+ } catch (Throwable t) {
+ TemplateEngineUtil.log(t);
+ }
+ return xmlFile;
+ }
+
+ /**
+ * This method generates XML file for backupshareddefaults and
+ * shareddefaults to support consistent persistency
+ */
+
+ private void generateSharedXML(File xmlFile) {
+ Document d;
+ try {
+ d = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
+ } catch (ParserConfigurationException e) {
+ TemplateEngineUtil.log(e);
+ return;
+ }
+ Node rootElement = d.appendChild(d.createElement("SharedRoot")); //$NON-NLS-1$
+
+ for(Iterator i = sharedDefaultsMap.keySet().iterator(); i.hasNext(); ) {
+ String key = (String) i.next();
+ Element element = (Element) rootElement.appendChild(d.createElement("SharedProperty")); //$NON-NLS-1$
+ element.setAttribute(TemplateEngineHelper.ID, key);
+ element.setAttribute(TemplateEngineHelper.VALUE, (String) sharedDefaultsMap.get(key));
+ }
+
+ DOMSource domSource = new DOMSource(d);
+ TransformerFactory transFactory = TransformerFactory.newInstance();
+ Result fileResult = new StreamResult(xmlFile);
+ try {
+ transFactory.newTransformer().transform(domSource, fileResult);
+ } catch (Throwable t) {
+ TemplateEngineUtil.log(t);
+ }
+ }
+
+ /**
+ * This method swaps the backup file name to XML file containing latest or
+ * persisted data
+ */
+
+ private void swapXML() {
+ if (parsedXML.exists())
+ parsedXML.delete();
+ backUpSharedXML.renameTo(parsedXML);
+ }
+}
diff --git a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/TemplateCore.java b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/TemplateCore.java
new file mode 100644
index 00000000000..5e28f4ddc9b
--- /dev/null
+++ b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/TemplateCore.java
@@ -0,0 +1,257 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.templateengine;
+
+import java.io.IOException;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.templateengine.process.ProcessFailureException;
+import org.eclipse.cdt.core.templateengine.process.TemplateProcessHandler;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.xml.sax.SAXException;
+
+
+/**
+ * TemplateCore class is responsible providing the non-UI part of template and
+ * initiating process part of Template Engine. This is created per TemplateDescriptor basis.
+ * Once The Template is created it creates a TemplateDescriptor for the XML file name given.
+ * Template class extends this class with additional UI elements that are part of the template.
+ *
+ * @since 4.0
+ */
+public class TemplateCore {
+
+ private static final String DESCRIPTION = "description"; //$NON-NLS-1$
+ private static final String LABEL = "label"; //$NON-NLS-1$
+ private static final String ID = "id"; //$NON-NLS-1$
+
+ private static Map/**/ templateCache = new HashMap/**/();
+
+ public static final Comparator/**/ TEMPLATE_ID_CASE_INSENSITIVE_COMPARATOR = new Comparator/**/() {
+ public int compare(Object/*Template*/ t1, Object/*Template*/ t2) {
+ return String.CASE_INSENSITIVE_ORDER.compare(((TemplateCore)t1).getTemplateId(), ((TemplateCore)t2).getTemplateId());
+ }
+ };
+
+ private TemplateDescriptor templateDescriptor;
+ private Map/**/ valueStore;
+ private TemplateInfo templateInfo;
+ private Set/**/ allMacrosInProcesses;
+ private TemplateProcessHandler processHandler;
+ private String description;
+ private String label;
+ private String templateId;
+ private boolean fireDirtyEvents;
+
+ /**
+ * Constructor
+ *
+ * @param templateInfo
+ * @throws IOException
+ * @throws SAXException
+ * @throws ParserConfigurationException
+ */
+
+ protected TemplateCore(TemplateInfo templateInfo) throws IOException, SAXException, ParserConfigurationException {
+ this.templateInfo = templateInfo;
+ templateDescriptor = new TemplateDescriptor(TemplateEngineHelper.getTemplateResourceURL(templateInfo.getPluginId(), templateInfo.getTemplatePath()));
+ valueStore = new ValueStore/**/(this);
+ valueStore.putAll(templateDescriptor.getTemplateDefaults(templateDescriptor.getRootElement()));
+ valueStore.putAll(TemplateEngine.getDefault().getSharedDefaults());
+ valueStore.put("projectType", templateInfo.getProjectType()); //$NON-NLS-1$
+
+ processHandler = new TemplateProcessHandler(this);
+ allMacrosInProcesses = processHandler.getAllMacros();
+
+ fireDirtyEvents = true;
+ }
+
+ /**
+ * Returns All Missing Macros In Processes.
+ * @return Set
+ */
+ public Set/**/ getAllMissingMacrosInProcesses() {
+ Set/**/ set = new TreeSet/**/(allMacrosInProcesses);
+ if (set != null) {
+ for (Iterator iter = set.iterator(); iter.hasNext();) {
+ if (valueStore.get(iter.next()) != null) {
+ iter.remove();
+ }
+ }
+ }
+ return set;
+ }
+
+ /**
+ * return the ValueStore maintained by this Template.
+ * @return ValueStore.
+ */
+ public Map/**/ getValueStore() {
+ return valueStore;
+ }
+
+ /**
+ * This is the List of IDs from TemplateDescriptor with "attribute" Persist
+ * as "true"
+ *
+ * @return Vector of IDs.
+ */
+ public List/**/ getPersistTrueIDs() {
+ return templateDescriptor.getPersistTrueIDs();
+ }
+
+ /**
+ * return the TemplateInfo instance corresponding to this Template.
+ * @return TemplateInfo.
+ */
+ public TemplateInfo getTemplateInfo() {
+ return templateInfo;
+ }
+
+ /**
+ * TemplateDescriptor for which, this Template is created.
+ */
+ public TemplateDescriptor getTemplateDescriptor() {
+ return templateDescriptor;
+ }
+
+ /**
+ * @return String, which contains the description
+ */
+ public String getDescription() {
+ if (description == null) {
+ description = templateDescriptor.getRootElement().getAttribute(DESCRIPTION).trim();
+ }
+ return description;
+ }
+
+ /**
+ * @return String, which contains the id of the template
+ */
+ public String getTemplateId() {
+ if (templateId == null) {
+ templateId = templateDescriptor.getRootElement().getAttribute(ID).trim();
+ }
+ return templateId;
+ }
+
+ /**
+ * @return String, which contains the Label
+ */
+ public String getLabel() {
+ if (label == null) {
+ label = templateDescriptor.getRootElement().getAttribute(LABEL).trim();
+ }
+ return label;
+ }
+
+ /**
+ * TemplateDescriptor for which, this Template is created.
+ */
+ public TemplateProcessHandler getProcessHandler() {
+ return processHandler;
+ }
+
+ public String toString()
+ {
+ return getLabel();
+ }
+ /**
+ * sets Dirty
+ *
+ */
+ public void setDirty() {
+ if (fireDirtyEvents) {
+ synchronized (templateCache) {
+ templateCache.remove(templateInfo);
+ }
+ }
+ }
+
+ /**
+ * initializeProcessBlockList() will create the ProcessBlockList,
+ * processPorcessBlockList() will invoke each process execution by assigning
+ * resources to each process (Ref. ProcessResourceManager).
+ * @param monitor
+ */
+ public IStatus[] executeTemplateProcesses(IProgressMonitor monitor, final boolean showError) {
+ setDirty();
+ TemplateEngine.getDefault().updateSharedDefaults(this);
+ final IStatus[][] result = new IStatus[1][];
+ try {
+ result[0] = getProcessHandler().processAll(monitor);
+ } catch (ProcessFailureException e) {
+ TemplateEngineUtil.log(e);
+ result[0] = new IStatus[] {new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e)};
+ }
+ return result[0];
+ }
+
+ /**
+ * Gets the Template
+ *
+ * @param templateInfo
+ * @throws IOException
+ * @throws ProcessFailureException
+ * @throws SAXException
+ * @throws ParserConfigurationException
+ *
+ * @since 4.0
+ */
+ public static TemplateCore getTemplate(TemplateInfo templateInfo) throws IOException, ProcessFailureException, SAXException, ParserConfigurationException {
+ synchronized (templateCache) {
+ TemplateCore template = (TemplateCore) templateCache.get(templateInfo);
+ if (template == null) {
+ template = new TemplateCore(templateInfo);
+ templateCache.put(templateInfo, template);
+ }
+ return template;
+ }
+ }
+
+ private static class ValueStore/**/ extends HashMap/**/ {
+ private static final long serialVersionUID = -4523467333437879406L;
+ private TemplateCore template;
+
+ ValueStore(TemplateCore template) {
+ this.template = template;
+ }
+
+ public Object/*V*/ put(Object/*K*/ key, Object/*V*/ value) {
+ Object/*V*/ v = super.put(key, value);
+ template.setDirty();
+ return v;
+ }
+
+ public void putAll(Map/* extends K, ? extends V>*/ map) {
+ super.putAll(map);
+ template.setDirty();
+ }
+
+ public Object/*V*/ remove(Object key) {
+ Object/*V*/ v = super.remove(key);
+ template.setDirty();
+ return v;
+ }
+
+ }
+}
diff --git a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/TemplateDescriptor.java b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/TemplateDescriptor.java
new file mode 100644
index 00000000000..bacec4f40ad
--- /dev/null
+++ b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/TemplateDescriptor.java
@@ -0,0 +1,198 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.templateengine;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.xml.sax.SAXException;
+
+
+/**
+ * This class contains methods to get first process block element, next process block
+ * element and checks for next process block element.
+ */
+public class TemplateDescriptor {
+ public static final String PROPERTY_GROUP = "property-group"; //$NON-NLS-1$
+ public static final String PROCESS = "process"; //$NON-NLS-1$
+ public static final String IF = "if"; //$NON-NLS-1$
+ public static final String ID = "id"; //$NON-NLS-1$
+ public static final String DEFAULT = "default"; //$NON-NLS-1$
+ public static final String PERSIST = "persist"; //$NON-NLS-1$
+ public static final String BOOL_TRUE = "true"; //$NON-NLS-1$
+
+ private Document document;
+ private Element rootElement;
+ private List/**/ persistVector;
+
+ /**
+ * Constructor which construct the Document based the URL
+ * @param descriptorURL
+ * @throws SAXException
+ * @throws IOException
+ * @throws ParserConfigurationException
+ */
+ public TemplateDescriptor(URL descriptorURL) throws SAXException, IOException, ParserConfigurationException {
+ document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(descriptorURL.openStream());
+ rootElement = document.getDocumentElement();
+ persistVector = new ArrayList/**/();
+ }
+
+ /**
+ * This method is to get the default key value pair (HashMap) form template
+ * descriptor root element.
+ *
+ * @return default values with keys
+ */
+ public Map/**/ getTemplateDefaults(Element rootElement) {
+ Map/**/ templateDefaults = new HashMap/**/();
+ Element propertyGroupElement;
+ List/**/ children = TemplateEngine.getChildrenOfElement(rootElement);
+ for (int i = 0, l = children.size(); i < l; i++) {
+ propertyGroupElement = (Element) children.get(i);
+ if (isNestedElement(propertyGroupElement)) {
+ templateDefaults = getTemplateDefaults(propertyGroupElement);
+ }
+ propertyElements(templateDefaults, propertyGroupElement);
+ }
+ return templateDefaults;
+ }
+
+ /**
+ * Checks whether element nested or not
+ * @param element
+ * @return
+ */
+ private boolean isNestedElement(Element element){
+ boolean result=false;
+ if (element!=null){
+ List/**/ children = TemplateEngine.getChildrenOfElement(element);
+ String elementName = element.getNodeName();
+ Element testElement;
+ String testElementName = null;
+ if (children.size() > 0){
+ testElement = (Element) children.get(0);
+ testElementName=testElement.getNodeName();
+ }
+ if(elementName.equals(testElementName))
+ result=true;
+ else result=false;
+ }
+ return result;
+ }
+
+ /**
+ * This method is to get the list of property-group elements from template
+ * descriptor root element
+ *
+ * @param aRootElement
+ * root element of type JDOM Element
+ * @return list of property-group elements
+ */
+ public List getPropertyGroupList() {
+ List resultList = null;
+ List/**/ list = new ArrayList/**/();
+ resultList = list;
+ if (rootElement != null) {
+ List/**/ tempList = TemplateEngine.getChildrenOfElement(rootElement);
+ for (int i = 0, l = tempList.size(); i < l; i++) {
+ Element nextPropertyGroup = (Element) tempList.get(i);
+ String nextPGName = nextPropertyGroup.getNodeName();
+ if (nextPGName.equalsIgnoreCase(PROPERTY_GROUP)) {
+ list.add(nextPropertyGroup);
+ }
+ }
+ }
+ return resultList;
+ }
+
+ /**
+ * This mehtod is to get the complex property-group from template descriptor
+ * root element. complex means a property-group contains other
+ * property-group(s)
+ *
+ * @param rootElement
+ * root element of type JDOM Element
+ * @return porperty-group root element of type JDOM Element
+ */
+ public Element getRootPropertyGroup(Element rootElement) {
+ if (rootElement != null) {
+ String rootElementName = rootElement.getNodeName();
+ if (rootElementName.equalsIgnoreCase(PROPERTY_GROUP) && isNestedElement(rootElement)) {
+ return rootElement;
+ }
+ return rootElement;
+ } else {
+ String nextPGElementName = null;
+ List/**/ propertyGroupList = TemplateEngine.getChildrenOfElement(rootElement);
+ for (int i = 0, l = propertyGroupList.size(); i < l; i++) {
+ Element nextPGElement = (Element) propertyGroupList.get(i);
+ if (isNestedElement(nextPGElement))
+ nextPGElementName = nextPGElement.getNodeName();
+ if (nextPGElementName.equalsIgnoreCase(PROPERTY_GROUP) && isNestedElement(nextPGElement)) {
+ return nextPGElement;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * This private method is used in getTemplateDefaults() to get defaults from
+ * property elements
+ *
+ * @param defaults
+ * HashMap to store deraults
+ * @param propertyGroupElement
+ * traverse the complex property-group element
+ */
+ private void propertyElements(Map/**/ defaults, Element propertyGroupElement) {
+ List/**/ children = TemplateEngine.getChildrenOfElement(propertyGroupElement);
+ for (int i = 0, l = children.size(); i < l; i++) {
+ Element propertyElement = (Element) children.get(i);
+ String key = propertyElement.getAttribute(ID);
+ String value = propertyElement.getAttribute(DEFAULT);
+ if (key != null && !key.equals("")) {
+ defaults.put(key, value);
+ }
+
+ String persist = propertyElement.getAttribute(PERSIST);
+ if ((persist != null) && (persist.trim().equalsIgnoreCase(BOOL_TRUE))) {
+ persistVector.add(key);
+ }
+ }
+ }
+
+ /**
+ * added to return root of this document.
+ */
+ public Element getRootElement() {
+ return rootElement;
+ }
+
+ /**
+ * return the list of IDs whose Persist attribute is true.
+ *
+ * @return Vector.
+ */
+ public List/**/ getPersistTrueIDs() {
+ return persistVector;
+ }
+}
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
new file mode 100644
index 00000000000..dea101fe822
--- /dev/null
+++ b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/TemplateEngine.java
@@ -0,0 +1,344 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.templateengine;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.Platform;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+
+/**
+ * TemplateEngine is implemented as a Singleton. TemplateEngine is responsible for
+ * creating SharedDefaults and initializing the SharedDefaults. Template instances
+ * are obtained from TemplateEngine.
+ *
+ * @since 4.0
+ */
+public class TemplateEngine {
+
+ public static String TEMPLATES_EXTENSION_ID = CCorePlugin.PLUGIN_ID + ".templates"; //$NON-NLS-1$
+
+ /**
+ * static reference to the Singleton TemplateEngine instance.
+ */
+ private static TemplateEngine TEMPLATE_ENGINE = new TemplateEngine();
+
+ /**
+ * This is a Map .
+ */
+ private Map/*>*/ templateInfoMap;
+
+ /**
+ * TemplateEngine constructor, create and initialize SharedDefaults.
+ */
+ private TemplateEngine() {
+ templateInfoMap = new HashMap/*>*/();
+ initializeTemplateInfoMap();
+ }
+
+ /**
+ * get All the templates, no filtering is done.
+ *
+ * @return
+ */
+ public TemplateCore[] getTemplates() {
+ TemplateInfo[] templateInfoArray = getTemplateInfos();
+ List/**/ templatesList = new ArrayList/**/();
+ for (int i=0; i*/ templatesList = new ArrayList/**/();
+ for (int i=0; i*/ getSharedDefaults() {
+ return SharedDefaults.getInstance().getSharedDefaultsMap();
+ }
+
+ /**
+ * update The SharedDefaults Map. This method will be called by Container
+ * UIs. After collecting data from UIPages, the IDs with Persist attribute
+ * as true, has to be persisted in SharedDefaults XML. For the same this
+ * method is called by passing the ValueStore(updated with user entered
+ * values). Get the PersistTrueIDs from TemplateDescriptor. Persist the
+ * values of IDs in ValueStore, which are also present in PersistTrueIDs
+ * vector.
+ * @param template
+ * @param aSharedValue
+ */
+ public void updateSharedDefaults(TemplateCore template) {
+ Map/**/ tobePersisted = new HashMap/**/();
+ Map/**/ valueStore = template.getValueStore();
+
+ for (Iterator i = template.getPersistTrueIDs().iterator(); i.hasNext();) {
+ String key = (String) i.next();
+ tobePersisted.put(key, valueStore.get(key));
+ }
+ SharedDefaults.getInstance().updateShareDefaultsMap(tobePersisted);
+ }
+
+ /**
+ * create the singleton instance, check for null condition of
+ * TEMPLATE_ENGINE. If TEMPLATE_ENGINE is null create the TemplateEngine
+ * instance assign it to TEMPLATE_ENGINE. There is no need to have
+ * synchronized here(while creating TemplateEngine).
+ *
+ * @return TEMPLATE_ENGINE, instance of TemplateEngine.
+ *
+ * @since 4.0
+ */
+ public static TemplateEngine getDefault() {
+ return TEMPLATE_ENGINE;
+ }
+
+ /**
+ * From the extension point take the class implementing the required
+ * functionality. Update the local HashMap of page-id and URL. This is for
+ * extension point "templates"
+ */
+ private void initializeTemplateInfoMap() {
+ String location = null;
+ String pluginId = null;
+ String projectType = null;
+ String filterPattern = null;
+ String usage = null;
+ boolean isCategory = false;
+ String extraPagesProvider = null;
+
+ IExtension[] extensions = Platform.getExtensionRegistry().getExtensionPoint(TEMPLATES_EXTENSION_ID).getExtensions();
+ for(int i=0; i*/());
+ }
+ ((List/**/)templateInfoMap.get(projectType)).add(templateInfo);
+ }
+ }
+ }
+
+ /**
+ * Gets an array of template info objects matching the criteria passed as params.
+ */
+ public TemplateInfo[] getTemplateInfos(String projectType, String toolChain, String usageFilter) {
+ List/**/ templateInfoList = (List/**/ matchedTemplateInfoList = new ArrayList/**/();
+
+ if (templateInfoList != null) {
+ for (Iterator i = templateInfoList.iterator(); i.hasNext(); ) {
+ TemplateInfo templateInfo = (TemplateInfo) i.next();
+ String filterPattern = templateInfo.getFilterPattern();
+ String[] toolChains = templateInfo.getToolChainIds();
+
+ if (toolChain != null) {
+ for (int j=0; j < toolChains.length; j++) {
+ if (toolChains[j].equals(toolChain)) {
+ if (usageFilter != null && filterPattern.matches(usageFilter)) {
+ matchedTemplateInfoList.add(templateInfo);
+ } else if (usageFilter == null) {
+ matchedTemplateInfoList.add(templateInfo);
+ }
+ continue;
+ }
+ }
+ } else {
+ if (usageFilter != null && filterPattern.matches(usageFilter)) {
+ matchedTemplateInfoList.add(templateInfo);
+ } else if (usageFilter == null) {
+ matchedTemplateInfoList.add(templateInfo);
+ }
+ }
+ }
+ }
+ return (TemplateInfo[]) matchedTemplateInfoList.toArray(new TemplateInfo[matchedTemplateInfoList.size()]);
+ }
+
+ public TemplateInfo[] getTemplateInfos(String projectType, String toolChain) {
+ return getTemplateInfos(projectType, toolChain, null);
+ }
+
+ public TemplateInfo[] getTemplateInfos(String projectType) {
+ return getTemplateInfos(projectType, null, null);
+ }
+
+ public TemplateInfo[] getTemplateInfos() {
+ List/**/ infoList = new ArrayList/**/();
+ for (Iterator i = templateInfoMap.values().iterator(); i.hasNext();) {
+ infoList.addAll((List/**/)i.next());
+ }
+
+ return (TemplateInfo[]) infoList.toArray(new TemplateInfo[infoList.size()]);
+ }
+
+
+ /**
+ * Getter for templateInfoMap
+ *
+ * @return
+ */
+ public Map/*>*/ getTemplateInfoMap() {
+ return templateInfoMap;
+ }
+
+ /**
+ * Returns the Template Schema URL
+ *
+ * @return URL of the Template Schema.
+ * @throws IOException
+ */
+ public URL getTemplateSchemaURL() throws IOException {
+ return FileLocator.toFileURL(Platform.getBundle(CCorePlugin.PLUGIN_ID).getEntry("schema/TemplateDescriptorSchema.xsd")); //$NON-NLS-1$
+ }
+
+ /**
+ * Returns the Children of the Element.
+ * @param element
+ * @return List of the child elelments
+ *
+ * @since 4.0
+ */
+ public static List/**/ getChildrenOfElement(Element element) {
+ List/**/ list = new ArrayList/**/();
+ NodeList children = element.getChildNodes();
+ for (int i = 0, l = children.getLength(); i < l; i++) {
+ Node child = children.item(i);
+ if (child.getNodeType() == Node.ELEMENT_NODE) {
+ list.add((Element) child);
+ }
+ }
+ return list;
+ }
+
+ /**
+ * Returns the child elements by Tag
+ *
+ * @param element
+ * @param tag
+ * @return List of child elements
+ *
+ * @since 4.0
+ */
+ public static List/**/ getChildrenOfElementByTag(Element element, String tag) {
+ List/**/ list = new ArrayList/**/();
+ NodeList children = element.getChildNodes();
+ for (int i = 0, l = children.getLength(); i < l; i++) {
+ Node child = children.item(i);
+ if (child.getNodeType() == Node.ELEMENT_NODE && child.getNodeName().equals(tag)) {
+ list.add((Element) child);
+ }
+ }
+ return list;
+ }
+}
diff --git a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/TemplateEngineHelper.java b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/TemplateEngineHelper.java
new file mode 100644
index 00000000000..1866acdba6b
--- /dev/null
+++ b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/TemplateEngineHelper.java
@@ -0,0 +1,221 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.templateengine;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Plugin;
+
+/**
+ * Acts as an Helper class for Template Engine
+ *
+ * @since 4.0
+ */
+public class TemplateEngineHelper {
+
+ public static final String OPEN_MARKER = "$("; //$NON-NLS-1$
+ public static final String CLOSE_MARKER = ")"; //$NON-NLS-1$
+ public static final String LOGGER_FILE_NAME = "Process"; //$NON-NLS-1$
+ // This is used while getting the Plugin Path.
+ public static final String PROJRESOURCE = "plugin.xml"; //$NON-NLS-1$
+ public static final String BOOLTRUE = "true"; //$NON-NLS-1$
+ public static final String ID = "id"; //NON-NLS-1$
+ public static final String VALUE = "value"; //NON-NLS-1$
+ public static final String SDLOG_FILE_NAME = "sharedDefaults"; //$NON-NLS-1$
+ public static final String LOCATION = "location"; //NON-NLS-1$
+ public static final String WIZARD_ID = "wizardId"; //NON-NLS-1$
+ public static final String FILTER_PATTERN = "filterPattern"; //NON-NLS-1$
+ public static final String USAGE_DESCRIPTION = "usageDescription"; //NON-NLS-1$
+ public static final String PROJECT_TYPE = "projectType"; //NON-NLS-1$
+ public static final String TOOL_CHAIN = "toolChain"; //NON-NLS-1$
+ public static final String EXTRA_PAGES_PROVIDER = "pagesAfterTemplateSelectionProvider"; //NON-NLS-1$
+ public static final String IS_CATEGORY = "isCategory"; //NON-NLS-1$
+ public static final String CONFIGURATIONS = "Configurations"; //NON-NLS-1$
+
+ /**
+ * Gets the backup shareddefaults XML file. Presence of the file indicates
+ * that the template engine or the application underwent some crash or
+ * destruction.
+ *
+ * @param sharedLocation
+ * @return sharedXMLFile
+ *
+ * @since 4.0
+ */
+
+ public static File getSharedDefaultLocation(String sharedLocation) {
+
+ File sharedXMLFile = findLocation(sharedLocation);
+ return sharedXMLFile;
+ }
+
+ /**
+ * Finds the location of the shareddefaults backup and original xml file.
+ *
+ * @param fileLocation
+ * @return file
+ *
+ * @since 4.0
+ */
+
+ private static File findLocation(String fileLocation) {
+
+ Plugin plugin = CCorePlugin.getDefault();
+ IPath stateLoc = plugin.getStateLocation();
+ fileLocation = stateLoc.toString() + File.separator + fileLocation;
+ File file = new File(fileLocation);
+
+ return file;
+ }
+
+ /**
+ * Stores the shareddefaults xml file in
+ * "${workspace}/.metadata/.plugins/${plugin.name}/shareddefaults.xml" path.
+ *
+ * @param sharedLocation
+ * @return sharedXMLFile
+ *
+ * @since 4.0
+ */
+
+ public static File storeSharedDefaultLocation(String sharedLocation) {
+
+ File sharedXMLFile = findLocation(sharedLocation);
+
+ try {
+ createNewFile(sharedXMLFile.getPath());
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return sharedXMLFile;
+ }
+
+ /**
+ * This creates a new File, in the Absolute Path given as argument. The File
+ * name will be part of the path argument.
+ *
+ * @param aFileName,
+ * absoulute File path(including File name) to be created.
+ *
+ * @since 4.0
+ */
+ public static void createNewFile(String fileName) throws IOException {
+
+ (new File(fileName)).createNewFile();
+ }
+
+ /**
+ * This method returns the workspace path present in the workspace
+ *
+ * @return String Example : file:/C:/eclipse/workspace/
+ *
+ * @since 4.0
+ */
+ public static IPath getWorkspacePath() {
+
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ IWorkspaceRoot root = workspace.getRoot();
+ IPath workSpacePath = new Path(root.getLocation().toString() + File.separator);
+ return workSpacePath;
+
+ }
+
+ /**
+ * given a String of the form $(ID), return ID.
+ *
+ * @param markerString
+ * @return
+ *
+ * @since 4.0
+ */
+ public static String getFirstMarkerID(String markerString) {
+ String key = null;
+ if (markerString.indexOf(OPEN_MARKER) != -1) {
+ key = markerString.substring(markerString.indexOf(OPEN_MARKER) + OPEN_MARKER.length(), markerString
+ .indexOf(CLOSE_MARKER));
+ }
+ return key;
+ }
+
+ /**
+ * Check whether there is a directory existing in present workspace, with
+ * the given name.
+ *
+ * @param directoryName
+ * @return true, if directory exists.
+ *
+ * @since 4.0
+ */
+ public static boolean checkDirectoryInWorkspace(String directoryName) {
+
+ boolean retVal = false;
+ File file = null;
+
+ try {
+ file = new File(getWorkspacePath() + directoryName);
+ } catch (Exception exp) {
+
+ }
+ if ((file != null) && (file.exists()) && (file.isDirectory())) {
+ retVal = true;
+ }
+ return retVal;
+ }
+ /**
+ * Return Template Source path as URL
+ * @param pluginId
+ * @param resourcePath
+ * @return URL, of the Template Resource
+ * @throws IOException
+ *
+ * @since 4.0
+ */
+
+ public static URL getTemplateResourceURL(String pluginId, String resourcePath) throws IOException {
+ return FileLocator.toFileURL(Platform.getBundle(pluginId).getEntry(resourcePath));
+ }
+
+ /**
+ *
+ * Returns the Template Resource Relative Path as URL
+ * @param template
+ * @param resourcePath
+ * @return URL, of the Template Resource
+ * @throws IOException
+ *
+ * @since 4.0
+ */
+ public static URL getTemplateResourceURLRelativeToTemplate(TemplateCore template, String resourcePath) throws IOException {
+ TemplateInfo templateInfo = template.getTemplateInfo();
+ String path = templateInfo.getTemplatePath();
+ int slash = path.lastIndexOf("/"); //$NON-NLS-1$
+ if (slash == -1) {
+ path = resourcePath;
+ } else {
+ path = path.substring(0, slash + 1) + resourcePath;
+ }
+ URL entry = Platform.getBundle(templateInfo.getPluginId()).getEntry(path);
+ if (entry == null) {
+ return null;
+ }
+ return FileLocator.toFileURL(entry);
+ }
+}
diff --git a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/TemplateEngineMessages.java b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/TemplateEngineMessages.java
new file mode 100644
index 00000000000..bba96d27340
--- /dev/null
+++ b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/TemplateEngineMessages.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.templateengine;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class TemplateEngineMessages {
+ private static final String BUNDLE_NAME = "org.eclipse.cdt.core.templateengine.messages"; //$NON-NLS-1$
+
+ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
+ .getBundle(BUNDLE_NAME);
+
+ private TemplateEngineMessages() {
+ }
+
+ public static String getString(String key) {
+ try {
+ return RESOURCE_BUNDLE.getString(key);
+ } catch (MissingResourceException e) {
+ return '!' + key + '!';
+ }
+ }
+}
diff --git a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/TemplateEngineUtil.java b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/TemplateEngineUtil.java
new file mode 100644
index 00000000000..6802f700941
--- /dev/null
+++ b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/TemplateEngineUtil.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.templateengine;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.templateengine.process.ProcessFailureException;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+
+public class TemplateEngineUtil {
+
+ public static void log(Throwable t) {
+ if (t == null) {
+ return;
+ }
+ if (t instanceof InvocationTargetException) {
+ t = ((InvocationTargetException) t).getTargetException();
+ }
+ if (t instanceof CoreException) {
+ ResourcesPlugin.getPlugin().getLog().log(((CoreException) t).getStatus());
+ } if (t instanceof ProcessFailureException) {
+ do {
+ List/**/ statuses = ((ProcessFailureException) t).getStatuses();
+ if (statuses != null) {
+ for(Iterator i = statuses.iterator(); i.hasNext(); ) {
+ IStatus status = (IStatus) i.next();
+ ResourcesPlugin.getPlugin().getLog().log(status);
+ }
+ }
+ t = t.getCause();
+ } while (t != null && t instanceof ProcessFailureException);
+ } else {
+ ResourcesPlugin.getPlugin().getLog().log(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, IStatus.OK, t.getMessage() == null ? t.toString() : t.getMessage() , t));
+ }
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/TemplateInfo.java b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/TemplateInfo.java
new file mode 100644
index 00000000000..169b708964c
--- /dev/null
+++ b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/TemplateInfo.java
@@ -0,0 +1,129 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.templateengine;
+
+import java.util.Set;
+
+
+
+/**
+ * TemplateInfo class contains the template information like wizard ID, pattern, path and project type.
+ */
+public class TemplateInfo {
+ private String projectTypeId;
+ private String filterPattern;
+ private String usageDescription;
+ private String templatePath;
+ private String pluginId;
+ private Set toolChainIdSet;
+ private String pagesProvider;
+ private boolean isCategory;
+ private String icon;
+
+ public TemplateInfo(String projectTypeId, String filterPattern, String templatePath,
+ String pluginId, Set toolChainIdSet, String usageDescription,
+ String pagesProvider, boolean isCategory) {
+ this.filterPattern = filterPattern;
+ this.templatePath = templatePath;
+ this.pluginId = pluginId;
+ this.projectTypeId = projectTypeId;
+ this.toolChainIdSet = toolChainIdSet;
+ this.usageDescription = usageDescription != null ? usageDescription : ""; //$NON-NLS-1$
+ this.pagesProvider = pagesProvider;
+ this.isCategory = isCategory;
+ }
+
+ /**
+ * Returns the Plugin ID
+ * @return String contains the plugin id.
+ */
+ public String getPluginId() {
+ return pluginId;
+ }
+
+ /**
+ * Returns the Template path as String.
+ * @return String containing the path.
+ */
+ public String getTemplatePath() {
+ return templatePath;
+ }
+
+ /**
+ * Returns the Filter Pattern.
+ * @return String containing the Filter Pattern.
+ */
+ public String getFilterPattern() {
+ return filterPattern;
+ }
+
+ /**
+ * @return the usageDescription
+ */
+ public String getUsageDescription() {
+ return usageDescription;
+ }
+
+ public String getExtraPagesProvider() {
+ return pagesProvider;
+ }
+
+ /**
+ * @return the projectTypeIds
+ */
+ public String getProjectType() {
+ return projectTypeId;
+ }
+
+ /**
+ * @return the toolChainIds
+ */
+ public String[] getToolChainIds() {
+ return (String[]) toolChainIdSet.toArray(new String[toolChainIdSet.size()]);
+ }
+
+ /**
+ * @return the isCategory
+ */
+ public boolean isCategory() {
+ return isCategory;
+ }
+
+ /**
+ * @return the icon image file name
+ */
+ public String getIcon() {
+ return icon;
+ }
+
+ /**
+ * Checks whether two TemplateInfo object are equal.
+ */
+ public boolean equals(Object obj) {
+ if (obj instanceof TemplateInfo) {
+ TemplateInfo info = (TemplateInfo) obj;
+ return projectTypeId.equals(info.projectTypeId) && templatePath.equals(info.templatePath) && pluginId.equals(info.pluginId)
+ && (((filterPattern == null || info.filterPattern == null) && filterPattern == info.filterPattern)
+ || filterPattern.equals(info.filterPattern))
+ && ((toolChainIdSet.equals(info.toolChainIdSet)))
+ && ((isCategory == info.isCategory));
+ }
+ return false;
+ }
+
+ /**
+ * Return the hashcode of the object.
+ */
+ public int hashCode() {
+ return projectTypeId.hashCode() | templatePath.hashCode() | pluginId.hashCode();
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/messages.properties b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/messages.properties
new file mode 100644
index 00000000000..08fb3cac580
--- /dev/null
+++ b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/messages.properties
@@ -0,0 +1,31 @@
+###############################################################################
+# 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:
+# Bala Torati (Symbian) - Initial API and implementation
+###############################################################################
+
+TemplateEngine.internalError=Internal Error:
+TemplateEngine.templateEngine=Template Engine
+ProjectCreatedActions.InsufficientInformation=Insufficient information to create new project
+
+ConditionalProcessGroup.notExecuting=Condition block not executing:
+ConditionalProcessGroup.unexpandableMacro=Condition has an unexpandable macro:
+Process.argument=Argument
+Process.expandableMacro=\ has an unexpandable macro:
+Process.error=-->Error:
+Process.success=-->Success:
+Process.info=-->Info:
+Process.unknownProcess=Unknown process:
+Process.executedSuccessfully=Executed successfully with args:
+ProcessRunner.unexpectedArguments=Unexpected arguments found.
+ProcessRunner.missingArguments=Missing arguments.
+ProcessRunner.argumentsMismatch=Argument type mismatch:
+ProcessRunner.error=-->Error:
+ProcessRunner.success=-->Success:
+ProcessRunner.info=-->Info:
+ProcessHelper.fileNotFound=File not found:
diff --git a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/ConditionalProcessGroup.java b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/ConditionalProcessGroup.java
new file mode 100644
index 00000000000..f3f59406f48
--- /dev/null
+++ b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/ConditionalProcessGroup.java
@@ -0,0 +1,284 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.templateengine.process;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.templateengine.TemplateCore;
+import org.eclipse.cdt.core.templateengine.TemplateDescriptor;
+import org.eclipse.cdt.core.templateengine.TemplateEngine;
+import org.eclipse.cdt.core.templateengine.TemplateEngineMessages;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.w3c.dom.Element;
+
+
+/**
+ * ConditionalProcess encloses an <if condition="..."></if> block of the template.
+ * The currently supported conditions are equals and not equals operations performed on two
+ * Strings. The respective operators are == and !=. Any spaces will be treated as part of the
+ * operands. The two operands will be evaluated for simple String equals and not equals after
+ * performing a single pass replace of any replace markers with their values in the template's
+ * value store.
+ */
+public class ConditionalProcessGroup {
+
+ private TemplateCore template;
+ private Set/**/ macros;
+ private String conditionString;
+ private String lValue;
+ private String rValue;
+ private Operator op;
+ private List/**/ processes;
+ private String id;
+
+ /**
+ * @author BalaT
+ */
+ private static class Operator {
+ final static Operator EQUALS = new Operator("="); //$NON-NLS-1$
+ final static Operator NOT_EQUALS = new Operator("!="); //$NON-NLS-1$
+
+ String id;
+ Operator(String id) {
+ this.id = id;
+ }
+ public boolean equals(Object arg0) {
+ if(arg0 instanceof Operator) {
+ return id.equals(((Operator)arg0).id);
+ }
+ return false;
+ }
+ }
+
+ /**
+ * Constructs a ConditionalProcess element from the supplied conditionElement (<if>) while building Process
+ * objects out of each of the element's <process> children.
+ * @throws ProcessFailureException
+ */
+ public ConditionalProcessGroup(TemplateCore template, Element conditionElement, int id) {
+ this.id = "Condition " + id; //$NON-NLS-1$
+ conditionString = conditionElement.getAttribute(ProcessHelper.CONDITION);
+ if (conditionString != null) {
+ if (conditionString.trim().equals("")) { //$NON-NLS-1$
+ conditionString = null;
+ } else {
+ int op = conditionString.indexOf(ProcessHelper.EQUALS);
+ if (op != -1) {
+ this.op = Operator.EQUALS;
+ lValue = conditionString.substring(0, op);
+ rValue = conditionString.substring(op + ProcessHelper.EQUALS.length());
+ } else {
+ op = conditionString.indexOf(ProcessHelper.NOT_EQUALS);
+ if (op != -1) {
+ this.op = Operator.NOT_EQUALS;
+ lValue = conditionString.substring(0, op);
+ rValue = conditionString.substring(op + ProcessHelper.NOT_EQUALS.length());
+ }//else an unsupported operation where this condition is ignored.
+ }
+ collectMacros(lValue);
+ collectMacros(rValue);
+ }
+ }
+ createProcessObjects(template, TemplateEngine.getChildrenOfElementByTag(conditionElement, TemplateDescriptor.PROCESS));
+ }
+
+ /**
+ * Adds values passed as parameter to the macros object
+ * @param value
+ */
+ private void collectMacros(String value) {
+ if (value != null) {
+ if (macros == null) {
+ macros = new HashSet/**/();
+ }
+ macros.addAll(ProcessHelper.getReplaceKeys(value));
+ }
+ }
+
+ /**
+ * Constructs a ConditionalProcess element from the supplied process elements while building Process
+ * objects out of each of the supplied process elements (<process>). The condition in this case is evaluated to true.
+ *
+ * This Constructor is expected to be used to evaluate all those process elements that are children of the template root element.
+ * @throws ProcessFailureException
+ */
+ public ConditionalProcessGroup(TemplateCore template, Element[] processElements) {
+ id = "No Condition"; //$NON-NLS-1$
+ createProcessObjects(template, Arrays.asList(processElements));
+ }
+
+ /**
+ * Creates the Proccess from the process Elements.
+ * @param template
+ * @param processElements
+ */
+ private void createProcessObjects(TemplateCore template, List/**/ processElements) {
+ this.template = template;
+ this.processes = new ArrayList/**/(processElements.size());
+ for (int j = 0, l = processElements.size(); j < l; j++) {
+ Element processElem = (Element) processElements.get(j);
+ if (processElem.getNodeName().equals(TemplateDescriptor.PROCESS)) {
+ String processId = id + "--> Process " + (j + 1) + " (" + processElem.getAttribute(Process.ELEM_TYPE) + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ processes.add(new Process(template, processElem, processId));
+ }
+ }
+ }
+
+ /**
+ * Checks if this conditional process group is completely ready to be processed.
+ */
+ public boolean isReadyToProcess() {
+ return areMacrosForConditionEvaluationExpandable() && isConditionValueTrue() && areProcessesReady();
+ }
+
+ /**
+ *
+ * @return boolean, as true if the Processes are ready to process
+ */
+ private boolean areProcessesReady() {
+ for(Iterator i = processes.iterator(); i.hasNext(); ) {
+ Process process = (Process) i.next();
+ if (!process.isReadyToProcess()) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ *
+ * @return boolean, true if Macros For Condition Evaluation Expandable.
+ */
+ private boolean areMacrosForConditionEvaluationExpandable() {
+ if (macros != null) {
+ Map/**/ valueStore = template.getValueStore();
+ for(Iterator i = macros.iterator(); i.hasNext(); ) {
+ String value = (String) i.next();
+ if (valueStore.get(value) == null) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ /**
+ *
+ * @return boolean, true if Condition Value is True.
+ */
+ public boolean isConditionValueTrue() {
+ if (conditionString == null) {
+ return true;
+ }
+ if (!areMacrosForConditionEvaluationExpandable()) {
+ return false;
+ }
+ Map/**/ valueStore = template.getValueStore();
+ String lValue = this.lValue;
+ String rValue = this.rValue;
+ for(Iterator i = macros.iterator(); i.hasNext(); ) {
+ String value = (String) i.next();
+ lValue = lValue.replaceAll(ProcessHelper.START_PATTERN + value + ProcessHelper.END_PATTERN, (String) valueStore.get(value));
+ rValue = rValue.replaceAll(ProcessHelper.START_PATTERN + value + ProcessHelper.END_PATTERN, (String) valueStore.get(value));
+ }
+ if(op.equals(Operator.EQUALS)) {
+ return lValue.equals(rValue);
+ } else if(op.equals(Operator.NOT_EQUALS)) {
+ return !lValue.equals(rValue);
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Process and Returns the Status of the prosses as a List.
+ * @param monitor
+ * @return List contains the IStatus.
+ * @throws ProcessFailureException
+ */
+ public List/**/ process(IProgressMonitor monitor) throws ProcessFailureException {
+ if (!areMacrosForConditionEvaluationExpandable()) {
+ throw new ProcessFailureException(getUnexpandableMacroMessage());
+ }
+ if (!isConditionValueTrue()) {
+ List/**/ statuses = new ArrayList/**/(1);
+ statuses.add(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, IStatus.INFO, TemplateEngineMessages.getString("ConditionalProcessGroup.notExecuting") + id, null)); //$NON-NLS-1$
+ return statuses;
+ }
+ List/**/ statuses = new ArrayList/**/(processes.size());
+ for(Iterator i = processes.iterator(); i.hasNext(); ) {
+ Process process = (Process) i.next();
+ try {
+ statuses.add(process.process(monitor));
+ } catch (ProcessFailureException e) {
+ throw new ProcessFailureException(e.getMessage(), e, statuses);
+ }
+ }
+ return statuses;
+ }
+
+ /**
+ * Return the Unexpandable Macro Message
+ * @return
+ */
+ private String getUnexpandableMacroMessage() {
+ if (macros != null) {
+ Map/**/ valueStore = template.getValueStore();
+ for(Iterator i = macros.iterator(); i.hasNext(); ) {
+ String value = (String) i.next();
+ if (valueStore.get(value) == null) {
+ return TemplateEngineMessages.getString("ConditionalProcessGroup.unexpandableMacro") + value; //$NON-NLS-1$
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns the Macros as a Set.
+ * @return Set, contains macros
+ */
+ public Set/**/ getMacros() {
+ return macros;
+ }
+
+ /**
+ * Returns All Macros as a Set.
+ * @return Set, contains macros
+ */
+ public Set/**/ getAllMacros() {
+ Set/**/ set = null;
+ if (macros != null) {
+ set = new HashSet/**/();
+ set.addAll(macros);
+ }
+ for(Iterator i = processes.iterator(); i.hasNext(); ) {
+ Process process = (Process) i.next();
+ Set/**/ subSet = process.getMacros();
+ if (subSet != null) {
+ if (set == null) {
+ set = new HashSet/**/();
+ }
+ set.addAll(subSet);
+ }
+ }
+ return set;
+ }
+}
diff --git a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/Process.java b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/Process.java
new file mode 100644
index 00000000000..cad1c6e38a5
--- /dev/null
+++ b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/Process.java
@@ -0,0 +1,201 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.templateengine.process;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.templateengine.TemplateCore;
+import org.eclipse.cdt.core.templateengine.TemplateEngine;
+import org.eclipse.cdt.core.templateengine.TemplateEngineMessages;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.w3c.dom.Element;
+
+
+/**
+ * This class contains methods to get first process block element, next process
+ * block element and checks for next process block element.
+ */
+public class Process {
+ public static final String ELEM_TYPE = "type"; //$NON-NLS-1$
+
+ private ProcessRunner processRunner;
+ private ProcessArgument[] args;
+ private TemplateCore template;
+ private String id;
+ private String processType;
+
+ /**
+ * Constructor to create a process.
+ * @param template
+ * @param element
+ * @param id
+ */
+ public Process(TemplateCore template, Element element, String id) {
+ this.template = template;
+ this.id = id;
+ processType = element.getAttribute(ELEM_TYPE);
+ processRunner = ProcessRunnerFactory.getDefault().getProcessRunner(processType);
+ if (processRunner != null) {
+ buildArgs(template, element);
+ }
+ }
+
+ /**
+ * This method build the necessary Arguments for the process
+ * @param template
+ * @param element
+ */
+ private void buildArgs(TemplateCore template, Element element) {
+ List/**/ children = TemplateEngine.getChildrenOfElement(element);
+ ProcessParameter[] params = processRunner.getProcessParameters();
+ List/**/ list = new ArrayList/**/(params.length);
+ int childIndex = 0;
+ for(int i=0; i*/ getMacros() {
+ Set/**/ set = null;
+ if (args != null) {
+ for(int i=0; i*/ subSet = arg.getMacros();
+ if (subSet != null) {
+ if (set == null) {
+ set = new HashSet/**/();
+ }
+ set.addAll(subSet);
+ }
+ }
+ }
+ return set;
+ }
+
+ public String toString() {
+ return id;
+ }
+}
diff --git a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/ProcessArgument.java b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/ProcessArgument.java
new file mode 100644
index 00000000000..b5abbba0137
--- /dev/null
+++ b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/ProcessArgument.java
@@ -0,0 +1,435 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.templateengine.process;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.cdt.core.templateengine.TemplateCore;
+import org.eclipse.cdt.core.templateengine.TemplateEngine;
+import org.w3c.dom.Element;
+
+
+/**
+ * ProcessArgument class responsible for constructing process Arguments by taking info from Template.
+ */
+public class ProcessArgument {
+
+ static final String ELEM_NAME = "name"; //$NON-NLS-1$
+ private static final String ELEM_VALUE = "value"; //$NON-NLS-1$
+ private static final String ELEM_ELEMENT = "element"; //$NON-NLS-1$
+ private static final String ELEM_SIMPLE = "simple"; //$NON-NLS-1$
+ private static final String ELEM_SIMPLE_ARRAY = "simple-array"; //$NON-NLS-1$
+ private static final String ELEM_COMPLEX = "complex"; //$NON-NLS-1$
+ private static final String ELEM_COMPLEX_ARRAY = "complex-array"; //$NON-NLS-1$
+
+ private String name;
+ private byte type;
+
+ private String simpleValue;
+ private String[] simpleValueArray;
+ private ProcessArgument[] complexValue;
+ private ProcessArgument[][] complexValueArray;
+
+ private String resolvedSimpleValue;
+ private String[] resolvedSimpleValueArray;
+
+ private TemplateCore template;
+
+ private Set/**/ macros;
+ private boolean resolved;
+ private ProcessParameter externalParam;
+
+ /**
+ * constructor
+ * @param template
+ * @param elem
+ */
+ public ProcessArgument(TemplateCore template, Element elem) {
+ this.template = template;
+ this.name = elem.getAttribute(ELEM_NAME);
+ String elemName = elem.getNodeName();
+ if (elemName.equals(ELEM_SIMPLE)) {
+ type = ProcessParameter.SIMPLE;
+ simpleValue = elem.getAttribute(ELEM_VALUE);
+ collectMacros(simpleValue);
+ } else if (elemName.equals(ELEM_SIMPLE_ARRAY)) {
+ type = ProcessParameter.SIMPLE_ARRAY;
+ List/**/ valueElements = TemplateEngine.getChildrenOfElementByTag(elem, ELEM_ELEMENT);
+ simpleValueArray = new String[valueElements.size()];
+ for (int i = 0, l = valueElements.size(); i < l; i++) {
+ simpleValueArray[i] = ((Element)valueElements.get(i)).getAttribute(ELEM_VALUE);
+ collectMacros(simpleValueArray[i]);
+ }
+ } else if (elemName.equals(ELEM_COMPLEX)) {
+ type = ProcessParameter.COMPLEX;
+ List/**/ children = TemplateEngine.getChildrenOfElement(elem);
+ complexValue = new ProcessArgument[children.size()];
+ for (int i = 0, l = children.size(); i < l; i++) {
+ complexValue[i] = new ProcessArgument(template, (Element) children.get(i));
+ Set/**/ subMacros = complexValue[i].getMacros();
+ if (macros == null) {
+ macros = new HashSet/**/();
+ }
+ if (subMacros != null) {
+ macros.addAll(subMacros);
+ }
+ }
+ } else if (elemName.equals(ELEM_COMPLEX_ARRAY)) {
+ type = ProcessParameter.COMPLEX_ARRAY;
+ List/**/ valueElements = TemplateEngine.getChildrenOfElementByTag(elem, ELEM_ELEMENT);
+ complexValueArray = new ProcessArgument[valueElements.size()][];
+
+ for (int i = 0, l = valueElements.size(); i < l; i++) {
+ List/**/ children = TemplateEngine.getChildrenOfElement((Element)valueElements.get(i));
+ complexValueArray[i] = new ProcessArgument[children.size()];
+ for (int j = 0, l2 = children.size(); j < l2; j++) {
+ complexValueArray[i][j] = new ProcessArgument(template, (Element) children.get(j));
+ Set/**/ subMacros = complexValueArray[i][j].getMacros();
+ if (subMacros != null) {
+ if (macros == null) {
+ macros = new HashSet/**/();
+ }
+ macros.addAll(subMacros);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Creates an external argument. This is not read from the template descriptor.
+ * @param param The ProcessParameter whose replacement this argument is in the Process call
+ */
+ public ProcessArgument(TemplateCore template, ProcessParameter param) {
+ this.template = template;
+ name = param.getName();
+ type = param.getType();
+ macros = new HashSet/**/();
+ macros.add(name);
+ simpleValue = ProcessHelper.getReplaceMarker(name);
+ this.externalParam = param;
+ }
+
+ /**
+ * Adds the marcos based on the value.
+ * @param value
+ */
+ private void collectMacros(String value) {
+ if (value == null) {
+ return;
+ }
+ if (macros == null) {
+ macros = new HashSet/**/();
+ }
+ macros.addAll(ProcessHelper.getReplaceKeys(value));
+ }
+
+ /**
+ * Returns Parameter name.
+ * @return parameter name as String
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Returns the Parameter Type
+ * @return the Parmeter Type as String
+ */
+ public byte getParameterType() {
+ return type;
+ }
+
+ /**
+ * Returns the Simple Value.
+ * @return String,
+ */
+ public String getSimpleValue() {
+ return resolved ? resolvedSimpleValue : simpleValue;
+ }
+
+ /**
+ * Returns the Simple Array Values.
+ * @return String Array.
+ */
+ public String[] getSimpleArrayValue() {
+ return resolved ? resolvedSimpleValueArray : simpleValueArray;
+ }
+
+ /**
+ * Returns Process Arguments
+ */
+ public ProcessArgument[] getComplexValue() {
+ return complexValue;
+ }
+
+ /**
+ * Returns Process Arguments
+ */
+ public ProcessArgument[][] getComplexArrayValue() {
+ return complexValueArray;
+ }
+
+ /**
+ * Check for parameter type.
+ * @param param
+ * @return boolean
+ */
+ public boolean isOfParameterType(ProcessParameter param) {
+ if (param.getType() != type || !param.getName().equals(name)) {
+ return false;
+ }
+ switch (type) {
+ case ProcessParameter.SIMPLE:
+ return simpleValue != null || param.isNullable();
+ case ProcessParameter.SIMPLE_ARRAY:
+ return true;
+ case ProcessParameter.COMPLEX:
+ ProcessParameter[] params = param.getComplexChildren();
+ if (params.length != complexValue.length) {
+ return false;
+ }
+ for (int i = 0; i < complexValue.length; i++) {
+ if (!complexValue[i].isOfParameterType(params[i])) {
+ return false;
+ }
+ }
+ return true;
+ case ProcessParameter.COMPLEX_ARRAY:
+ params = param.getComplexChildren();
+ for(int i=0; i*/ valueStore = template.getValueStore();
+ for(Iterator i = macros.iterator(); i.hasNext(); ) {
+ String macro = (String) i.next();
+ if (valueStore.get(macro) == null) {
+ return false;
+ }
+ }
+ return true;
+ case ProcessParameter.COMPLEX:
+ for(int i=0; i*/ valueStore = template.getValueStore();
+ for(Iterator i = macros.iterator(); i.hasNext(); ) {
+ String macro = (String) i.next();
+ if (valueStore.get(macro) == null) {
+ return macro;
+ }
+ }
+ return null;
+ case ProcessParameter.COMPLEX:
+ String macro;
+ for(int i=0; i*/ getMacros() {
+ return macros;
+ }
+
+ /**
+ * resolve
+ *
+ */
+ public void resolve() {
+ Map/**/ valueStore = template.getValueStore();
+ switch (type) {
+ case ProcessParameter.SIMPLE:
+ if (externalParam != null) {
+ resolvedSimpleValue = (String) template.getValueStore().get(name);
+ } else {
+ resolvedSimpleValue = simpleValue;
+ if (macros != null && !macros.isEmpty()) {
+ resolvedSimpleValue = ProcessHelper.getValueAfterExpandingMacros(resolvedSimpleValue, macros, valueStore);
+ }
+ }
+ break;
+ case ProcessParameter.SIMPLE_ARRAY:
+ resolvedSimpleValueArray = simpleValueArray;
+ if (macros != null && !macros.isEmpty()) {
+ for (int i = 0; i < resolvedSimpleValueArray.length; i++) {
+ resolvedSimpleValueArray[i] = ProcessHelper.getValueAfterExpandingMacros(resolvedSimpleValueArray[i], macros, valueStore);
+ }
+ }
+ break;
+ case ProcessParameter.COMPLEX:
+ for(int i=0; i*/ statuses;
+
+ /**
+ * Constructor based on the msg.
+ * @param msg
+ */
+ public ProcessFailureException(String msg) {
+ super(msg);
+ }
+
+ /**
+ * Constructor based on the msg and cause.
+ * @param cause
+ */
+ public ProcessFailureException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * Constructor based on the msg and cause.
+ * @param msg
+ * @param cause
+ */
+ public ProcessFailureException(String msg, Throwable cause) {
+ super(msg, cause);
+ }
+
+ /**
+ * Constructor based on the msg and causes.
+ * @param msg
+ * @param statuses
+ */
+ public ProcessFailureException(String msg, List/**/ statuses) {
+ super(msg);
+ this.statuses = statuses;
+ }
+
+ public ProcessFailureException(String msg, Throwable cause, List/**/ statuses) {
+ super(msg, cause);
+ this.statuses = statuses;
+ }
+
+ /**
+ * Returns the Statuses.
+ * @return List, contains the IStatus.
+ */
+ public List/**/ getStatuses() {
+ return statuses;
+ }
+}
diff --git a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/ProcessHelper.java b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/ProcessHelper.java
new file mode 100644
index 00000000000..d8d7f0d14ea
--- /dev/null
+++ b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/ProcessHelper.java
@@ -0,0 +1,232 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.templateengine.process;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.RandomAccessFile;
+import java.net.URL;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.cdt.core.templateengine.TemplateEngineMessages;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+
+/**
+ * Acts as Helper class for process the processes i.e., copy, replace and append
+ * files.
+ */
+public class ProcessHelper {
+ public static final String CONDITION = "condition"; //$NON-NLS-1$
+ public static final String START_PATTERN = "$("; //$NON-NLS-1$
+ public static final String END_PATTERN = ")"; //$NON-NLS-1$
+ public static final String EQUALS = "=="; //$NON-NLS-1$
+ public static final String NOT_EQUALS = "!="; //$NON-NLS-1$
+
+ /**
+ * This method is to append the given contents into a file.
+ *
+ * @param fileContents,
+ * contents which are appended to the file.
+ * @param toFile,
+ * a file to append contents.
+ * @throws IOException,
+ * exception while writing contents into a file
+ *
+ * @since 4.0
+ */
+ public static void appendFile(String fileContents, File toFile) throws IOException {
+ RandomAccessFile raf = null;
+ if (!toFile.exists()) {
+ throw new FileNotFoundException(" The specified destination file does not exists "); //$NON-NLS-1$
+ } else {
+ try {
+ raf = new RandomAccessFile(toFile, "rw"); //$NON-NLS-1$
+ raf.skipBytes((int) raf.length());
+ raf.writeBytes(fileContents);
+ } finally {
+ raf.close();
+ }
+ }
+ }
+
+ /**
+ * This method returns a vector of all replace marker strings. (e.g.,
+ * $(item), vector contains 'item' as one item. , ) is the end pattern.
+ *
+ * @param str,
+ * A given string may contains replace markers.
+ * @param pattern
+ * start pattern (e.g., $( is the start pattern)
+ * @param endPat
+ * end pattern (e.g., ) is the end pattern)
+ * @return a set of all replace marker strings.
+ *
+ * @since 4.0
+ */
+ public static Set/**/ getReplaceKeys(String str) {
+ int start = 0;
+ int end = 0;
+ Set/**/ replaceStrings = new HashSet/**/();
+ while ((start = str.indexOf(START_PATTERN, start)) >= 0) {
+ end = str.indexOf(END_PATTERN, start);
+ if (end != -1) {
+ replaceStrings.add(str.substring(start + START_PATTERN.length(), end));
+ start = end + START_PATTERN.length();
+ } else
+ start++;
+ }
+ return replaceStrings;
+ }
+
+ /**
+ * This method takes a URL as parameter to read the contents, and to add
+ * into a string buffer.
+ *
+ * @param source
+ * URL to read the contents.
+ * @return string, contents of a file specified in the URL source path.
+ * @throws IOException
+ *
+ * @since 4.0
+ */
+ public static String readFromFile(URL source) throws IOException {
+ char[] chars = new char[4092];
+ InputStreamReader contentsReader = null;
+ StringBuffer buffer = new StringBuffer();
+ if (!new java.io.File(source.getFile()).exists()) {
+ throw new FileNotFoundException(TemplateEngineMessages.getString("ProcessHelper.fileNotFound") + source.getFile()); //$NON-NLS-1$
+ } else {
+ contentsReader = new InputStreamReader(source.openStream());
+ int c;
+ do {
+ c = contentsReader.read(chars);
+ if (c == -1)
+ break;
+ buffer.append(chars, 0, c);
+ } while (c != -1);
+ contentsReader.close();
+ }
+ return buffer.toString();
+ }
+
+ /**
+ * This method reads contents from source, and writes the contents into
+ * destination file.
+ *
+ * @param source
+ * URL to read the contents.
+ * @param dest
+ * destination file to write the contents.
+ * @throws IOException
+ *
+ * @since 4.0
+ */
+ public static void copyBinaryFile(URL source, File dest) throws IOException {
+ byte[] bytes = new byte[4092];
+ if (source != null && dest != null) {
+ File file = new File(source.getFile());
+ if (file.isFile()) {
+ FileInputStream fis = new FileInputStream(file);
+ FileOutputStream fos = new FileOutputStream(dest);
+ int ch;
+ while (true) {
+ ch = fis.read(bytes);
+ if (ch == -1) {
+ break;
+ }
+ fos.write(bytes, 0, ch);
+ }
+ }
+ }
+ }
+
+ /**
+ * This method Creates the Directories in the parent Folder.
+ * @param projectHandle
+ * @param parentFolder
+ * @throws CoreException
+ *
+ * @since 4.0
+ */
+ public static void mkdirs(IProject projectHandle, IFolder parentFolder) throws CoreException {
+ if (parentFolder.getProjectRelativePath().equals(projectHandle.getProjectRelativePath())) {
+ return;
+ }
+ if (!parentFolder.getParent().exists()) {
+ mkdirs(projectHandle, projectHandle.getFolder(parentFolder.getParent().getProjectRelativePath()));
+ }
+ parentFolder.create(true, true, null);
+ }
+
+
+ /**
+ * Returns the Macro Value after Exanding the Macros.
+ * @param string
+ * @param macros
+ * @param valueStore
+ * @return
+ *
+ * @since 4.0
+ */
+ public static String getValueAfterExpandingMacros(String string, Set/**/ macros, Map/**/ valueStore) {
+ for (Iterator i = macros.iterator(); i.hasNext();) {
+ String key = (String) i.next();
+ String value = (String) valueStore.get(key);
+ if (value != null) {
+ string = replace(START_PATTERN + key + END_PATTERN, value, string);
+ }
+ }
+ return string;
+ }
+
+ /**
+ * This is equivalent to Java 5.0 version of
+ * String.replace(CharSequence target, CharSequence replacement) method.
+ * @since 4.0
+ */
+ private static String replace(String target, String replacement, String string) {
+ try {
+ StringBuffer stringBuffer = new StringBuffer(string);
+
+ int index = string.length();
+ int offset = target.length();
+
+ while ((index=string.lastIndexOf(target, index-1)) != -1) {
+ stringBuffer.replace(index, index+offset, replacement);
+ }
+
+ return stringBuffer.toString();
+ } catch (StringIndexOutOfBoundsException e) {
+ return string;
+ }
+ }
+
+ /**
+ * Consturct and Return the Replacment Markers
+ * after adding the patterns to the macro.
+ * @param macro
+ * @return
+ *
+ * @since 4.0
+ */
+ public static String getReplaceMarker(String macro) {
+ return START_PATTERN + macro + END_PATTERN;
+ }
+}
diff --git a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/ProcessParameter.java b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/ProcessParameter.java
new file mode 100644
index 00000000000..ce43a2bedd0
--- /dev/null
+++ b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/ProcessParameter.java
@@ -0,0 +1,111 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.templateengine.process;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+
+/**
+ * ProcessParameter is responsible for construting the Process Parameter the given configuration element.
+ */
+public class ProcessParameter {
+ public static final byte SIMPLE = 1;
+ public static final byte SIMPLE_ARRAY = 2;
+ public static final byte COMPLEX = 3;
+ public static final byte COMPLEX_ARRAY = 4;
+
+ private static final String ELEM_NAME = "name"; //$NON-NLS-1$
+ private static final String ELEM_BASE_TYPE = "baseType"; //$NON-NLS-1$
+ private static final String ELEM_SIMPLE = "simple"; //$NON-NLS-1$
+ private static final String ELEM_SIMPLE_ARRAY = "simpleArray"; //$NON-NLS-1$
+ private static final String ELEM_COMPLEX = "complex"; //$NON-NLS-1$
+ private static final String ELEM_COMPLEX_ARRAY = "complexArray"; //$NON-NLS-1$
+ private static final String ELEM_EXTERNAL = "external"; //$NON-NLS-1$
+ private static final String ELEM_NULLABLE = "nullable"; //$NON-NLS-1$
+
+ private String name;
+ private byte type;
+
+ private ProcessParameter[] complexChildren;
+ private boolean external;
+ private boolean nullable;
+
+ /**
+ * Constructor to extract the parameter info.
+ * @param element
+ */
+ public ProcessParameter(IConfigurationElement element) {
+ this.name = element.getAttribute(ELEM_NAME);
+ String elemName = element.getName();
+ if (elemName.equals(ELEM_SIMPLE)) {
+ type = SIMPLE;
+ } else if (elemName.equals(ELEM_SIMPLE_ARRAY)) {
+ type = SIMPLE_ARRAY;
+ } else if (elemName.equals(ELEM_COMPLEX)) {
+ type = COMPLEX;
+ IConfigurationElement[] children = element.getChildren();
+ complexChildren = new ProcessParameter[children.length];
+ for(int i=0; i*/ processRunnerMap;
+
+ private ProcessRunnerFactory() {
+ initializeProcessRunners();
+ }
+
+ /**
+ * initializes the process runners.
+ *
+ */
+ private synchronized void initializeProcessRunners() {
+ processRunnerMap = new HashMap/**/();
+ IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(EXTENSION_POINT_PROCESSES);
+ IExtension[] extensions = point.getExtensions();
+ for(int i=0; i*/ params = null;
+ IConfigurationElement[] elementChildren = element.getChildren();
+ for (int k=0; k*/();
+ }
+ params.add(new ProcessParameter(elementChildren[k]));
+ }
+ if (params != null) {
+ runner.setProcessParameters((ProcessParameter[])params.toArray(new ProcessParameter[params.size()]));
+ }
+ processRunnerMap.put(prefix + processType, runner);
+ } catch (CoreException e) {
+ TemplateEngineUtil.log(e);
+// TemplateEngine.showError(e.getMessage(), e);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Process Runners Factory instace.
+ * @return
+ */
+ public static ProcessRunnerFactory getDefault() {
+ return instance;
+ }
+
+ /**
+ * Return the ProcessRunner based on the ProcessType.
+ * @param processType
+ * @return
+ */
+ public ProcessRunner getProcessRunner(String processType) {
+ return (ProcessRunner) processRunnerMap.get(processType);
+ }
+}
diff --git a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/TemplateProcessHandler.java b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/TemplateProcessHandler.java
new file mode 100644
index 00000000000..eab75afe3ca
--- /dev/null
+++ b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/TemplateProcessHandler.java
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.templateengine.process;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.cdt.core.templateengine.TemplateCore;
+import org.eclipse.cdt.core.templateengine.TemplateDescriptor;
+import org.eclipse.cdt.core.templateengine.TemplateEngine;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.w3c.dom.Element;
+
+
+/**
+ * Class handles the Template processes
+ */
+public class TemplateProcessHandler {
+
+ private TemplateCore template;
+ private List/**/ conditionalProcessGroupList;
+
+ public TemplateProcessHandler(TemplateCore template) {
+ this.template = template;
+ initialize();
+ }
+
+ /**
+ * initializes the template descriptor and Root Elements.
+ *
+ */
+ private void initialize() {
+ TemplateDescriptor desc = template.getTemplateDescriptor();
+ Element root = desc.getRootElement();
+ conditionalProcessGroupList = new ArrayList/**/();
+ List/**/ nodeList = TemplateEngine.getChildrenOfElementByTag(root, TemplateDescriptor.IF);
+ for (int j = 0, l = nodeList.size(); j < l; j++) {
+ conditionalProcessGroupList.add(new ConditionalProcessGroup(template, (Element) nodeList.get(j), j + 1));
+ }
+ //Collect all free-hanging processes in one ConditionalProcessGroup object with condition true.
+ nodeList = TemplateEngine.getChildrenOfElementByTag(root, TemplateDescriptor.PROCESS);
+ conditionalProcessGroupList.add(new ConditionalProcessGroup(template, (Element[]) nodeList.toArray(new Element[nodeList.size()])));
+ }
+
+ /**
+ *
+ * @param monitor
+ * @return IStatus, as an array of status info
+ * @throws ProcessFailureException
+ */
+ public IStatus[] processAll(IProgressMonitor monitor) throws ProcessFailureException {
+ List/**/ allStatuses = new ArrayList/**/();
+ for (Iterator i = conditionalProcessGroupList.iterator(); i.hasNext();) {
+ try {
+ allStatuses.addAll(((ConditionalProcessGroup)i.next()).process(monitor));
+ } catch (ProcessFailureException e) {
+ throw new ProcessFailureException(e.getMessage(), e, allStatuses);
+ }
+ }
+ return (IStatus[]) allStatuses.toArray(new IStatus[allStatuses.size()]);
+ }
+
+ /**
+ * Returns all macros
+ * @return
+ */
+ public Set/**/ getAllMacros() {
+ Set/**/ set = null;
+ for (Iterator i = conditionalProcessGroupList.iterator(); i.hasNext();) {
+ Set/**/ subSet = ((ConditionalProcessGroup)i.next()).getAllMacros();
+ if (subSet != null) {
+ if (set == null) {
+ set = new HashSet/**/();
+ }
+ set.addAll(subSet);
+ }
+ }
+ return set;
+ }
+}
diff --git a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/AddFile.java b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/AddFile.java
new file mode 100644
index 00000000000..245867027bf
--- /dev/null
+++ b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/AddFile.java
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.templateengine.process.processes;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.eclipse.cdt.core.templateengine.TemplateCore;
+import org.eclipse.cdt.core.templateengine.TemplateEngineHelper;
+import org.eclipse.cdt.core.templateengine.process.ProcessArgument;
+import org.eclipse.cdt.core.templateengine.process.ProcessFailureException;
+import org.eclipse.cdt.core.templateengine.process.ProcessHelper;
+import org.eclipse.cdt.core.templateengine.process.ProcessRunner;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+
+
+/**
+ * Adds File to the project
+ */
+public class AddFile extends ProcessRunner {
+
+ /**
+ * This method Adds the File to the corresponding Project.
+ */
+ public void process(TemplateCore template, ProcessArgument[] args, String processId, IProgressMonitor monitor) throws ProcessFailureException {
+ String projectName = args[0].getSimpleValue();
+ ProcessArgument file = args[1];
+ ProcessArgument[] fileMembers = file.getComplexValue();
+ String fileSourcePath = fileMembers[0].getSimpleValue();
+ String fileTargetPath = fileMembers[1].getSimpleValue();
+ boolean replaceable = fileMembers[2].getSimpleValue().equals("true"); //$NON-NLS-1$
+
+ IProject projectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ URL path;
+ try {
+ path = TemplateEngineHelper.getTemplateResourceURLRelativeToTemplate(template, fileSourcePath);
+ if (path == null) {
+ throw new ProcessFailureException(getProcessMessage(processId, IStatus.ERROR, Messages.getString("AddFile.0") + fileSourcePath)); //$NON-NLS-1$
+ }
+ } catch (IOException e1) {
+ throw new ProcessFailureException(getProcessMessage(processId, IStatus.ERROR, Messages.getString("AddFile.1") + fileSourcePath)); //$NON-NLS-1$
+ }
+
+ InputStream contents = null;
+ if (replaceable) {
+ String fileContents;
+ try {
+ fileContents = ProcessHelper.readFromFile(path);
+ } catch (IOException e) {
+ throw new ProcessFailureException(getProcessMessage(processId, IStatus.ERROR, Messages.getString("AddFile.2") + fileSourcePath)); //$NON-NLS-1$
+ }
+ fileContents = ProcessHelper.getValueAfterExpandingMacros(fileContents, ProcessHelper.getReplaceKeys(fileContents), template.getValueStore());
+ contents = new ByteArrayInputStream(fileContents.getBytes());
+ } else {
+ try {
+ contents = path.openStream();
+ } catch (IOException e) {
+ throw new ProcessFailureException(getProcessMessage(processId, IStatus.ERROR, Messages.getString("AddFile.3") + fileSourcePath)); //$NON-NLS-1$
+ }
+ }
+
+ try {
+ IFile iFile = projectHandle.getFile(fileTargetPath);
+ if (!iFile.getParent().exists()) {
+ ProcessHelper.mkdirs(projectHandle, projectHandle.getFolder(iFile.getParent().getProjectRelativePath()));
+ }
+ iFile.create(contents, true, null);
+ iFile.refreshLocal(IResource.DEPTH_ONE, null);
+ projectHandle.refreshLocal(IResource.DEPTH_INFINITE, null);
+ } catch (CoreException e) {
+ throw new ProcessFailureException(getProcessMessage(processId, IStatus.ERROR, Messages.getString("AddFile.4") + e.getMessage()), e); //$NON-NLS-1$
+ }
+ }
+}
diff --git a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/AddFiles.java b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/AddFiles.java
new file mode 100644
index 00000000000..bd11bf60268
--- /dev/null
+++ b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/AddFiles.java
@@ -0,0 +1,107 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.templateengine.process.processes;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.eclipse.cdt.core.templateengine.TemplateCore;
+import org.eclipse.cdt.core.templateengine.TemplateEngineHelper;
+import org.eclipse.cdt.core.templateengine.process.ProcessArgument;
+import org.eclipse.cdt.core.templateengine.process.ProcessFailureException;
+import org.eclipse.cdt.core.templateengine.process.ProcessHelper;
+import org.eclipse.cdt.core.templateengine.process.ProcessRunner;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+
+
+/**
+ * Adds Files to the Project
+ */
+public class AddFiles extends ProcessRunner {
+
+ /**
+ * This method Adds the list of Files to the corresponding Project.
+ */
+ public void process(TemplateCore template, ProcessArgument[] args, String processId, IProgressMonitor monitor) throws ProcessFailureException {
+ String projectName = args[0].getSimpleValue();
+ IProject projectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ ProcessArgument[][] files = args[1].getComplexArrayValue();
+ for(int i=0; i HELL
+ */
+public class CreateResourceIdentifier extends ProcessRunner {
+
+ public void process(TemplateCore template, ProcessArgument[] args, String processId, IProgressMonitor monitor) throws ProcessFailureException {
+ String valueName = args[0].getSimpleValue();
+ String appName = args[1].getSimpleValue();
+
+ String value = ""; //$NON-NLS-1$
+ if (appName.length() >= 4) {
+ value = appName.substring(0, 4).toUpperCase();
+ } else {
+ value = appName.toUpperCase();
+ for (int i=0; i<4-appName.length(); i++) {
+ value = value + "X"; //$NON-NLS-1$
+ }
+ }
+ template.getValueStore().put(valueName, value);
+ }
+}
diff --git a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/CreateSourceFolder.java b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/CreateSourceFolder.java
new file mode 100644
index 00000000000..bda5d6b94b6
--- /dev/null
+++ b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/CreateSourceFolder.java
@@ -0,0 +1,148 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.templateengine.process.processes;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.model.CModelException;
+import org.eclipse.cdt.core.model.CoreModel;
+import org.eclipse.cdt.core.model.ICProject;
+import org.eclipse.cdt.core.model.IPathEntry;
+import org.eclipse.cdt.core.settings.model.CSourceEntry;
+import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
+import org.eclipse.cdt.core.settings.model.ICProjectDescription;
+import org.eclipse.cdt.core.settings.model.ICSourceEntry;
+import org.eclipse.cdt.core.settings.model.WriteAccessException;
+import org.eclipse.cdt.core.templateengine.TemplateCore;
+import org.eclipse.cdt.core.templateengine.process.ProcessArgument;
+import org.eclipse.cdt.core.templateengine.process.ProcessFailureException;
+import org.eclipse.cdt.core.templateengine.process.ProcessRunner;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+
+/**
+ * Creates a include Folder to the project.
+ */
+public class CreateSourceFolder extends ProcessRunner {
+
+ public void process(TemplateCore template, ProcessArgument[] args, String processId, IProgressMonitor monitor) throws ProcessFailureException {
+ createSourceFolder(args[0].getSimpleValue(), args[1].getSimpleValue(), monitor);
+ }
+
+ protected void createSourceFolder(String projectName, String targetPath, IProgressMonitor monitor) throws ProcessFailureException {
+ IProject projectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+
+ if (!projectHandle.exists()) {
+ throw new ProcessFailureException(Messages.getString("CreateSourceFolder.0") + projectName); //$NON-NLS-1$
+ }
+
+ IPath projPath = projectHandle.getFullPath();
+
+ IFolder folder = projectHandle.getFolder(targetPath);
+ if (!folder.exists()) {
+ try {
+ folder.create(true, true, monitor);
+ } catch (CoreException e) {
+ throw new ProcessFailureException(Messages.getString("CreateSourceFolder.1") + e.getMessage(), e); //$NON-NLS-1$
+ }
+ }
+
+ try {
+ ICProject cProject = CoreModel.getDefault().create(projectHandle);
+ if (cProject != null) {
+ if(CCorePlugin.getDefault().isNewStyleProject(cProject.getProject())){
+ //create source folder for new style project
+ createNewStyleProjectFolder(monitor, projectHandle, folder);
+ } else {
+ //create source folder for all other projects
+ createFolder(targetPath, monitor, projPath, cProject);
+ }
+ }
+ } catch (WriteAccessException e) {
+ throw new ProcessFailureException(Messages.getString("CreateSourceFolder.2") + e.getMessage(), e); //$NON-NLS-1$
+ } catch (CoreException e) {
+ throw new ProcessFailureException(Messages.getString("CreateSourceFolder.2") + e.getMessage(), e); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * @param monitor
+ * @param projectHandle
+ * @param folder
+ * @throws CoreException
+ * @throws WriteAccessException
+ */
+ private void createNewStyleProjectFolder(IProgressMonitor monitor, IProject projectHandle, IFolder folder) throws CoreException, WriteAccessException {
+ ICSourceEntry newEntry = new CSourceEntry(folder, null, 0);
+ ICProjectDescription description = CCorePlugin.getDefault().getProjectDescription(projectHandle);
+
+ ICConfigurationDescription configs[] = description.getConfigurations();
+ for(int i=0; i < configs.length; i++){
+ ICConfigurationDescription config = configs[i];
+ ICSourceEntry[] entries = config.getSourceEntries();
+ Set set = new HashSet();
+ for (int j=0; j < entries.length; j++) {
+ set.add(entries[j]);
+ }
+ set.add(newEntry);
+ config.setSourceEntries((ICSourceEntry[])set.toArray(new ICSourceEntry[set.size()]));
+ }
+
+ CCorePlugin.getDefault().setProjectDescription(projectHandle, description, false, monitor);
+ }
+
+ /**
+ * @param targetPath
+ * @param monitor
+ * @param projPath
+ * @param cProject
+ * @throws CModelException
+ */
+ private void createFolder(String targetPath, IProgressMonitor monitor, IPath projPath, ICProject cProject) throws CModelException {
+ IPathEntry[] entries = cProject.getRawPathEntries();
+ List/**/ newEntries = new ArrayList/**/(entries.length + 1);
+
+ int projectEntryIndex= -1;
+ IPath path = projPath.append(targetPath);
+
+ for (int i = 0; i < entries.length; i++) {
+ IPathEntry curr = entries[i];
+ if (path.equals(curr.getPath())) {
+ // just return if this folder exists already
+ return;
+ }
+ if (projPath.equals(curr.getPath())) {
+ projectEntryIndex = i;
+ }
+ newEntries.add(curr);
+ }
+
+ IPathEntry newEntry = CoreModel.newSourceEntry(path);
+
+ if (projectEntryIndex != -1) {
+ newEntries.set(projectEntryIndex, newEntry);
+ } else {
+ newEntries.add(CoreModel.newSourceEntry(path));
+ }
+
+ cProject.setRawPathEntries((IPathEntry[])newEntries.toArray(new IPathEntry[newEntries.size()]), monitor);
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/Messages.java b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/Messages.java
new file mode 100644
index 00000000000..863aaef9f1b
--- /dev/null
+++ b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/Messages.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.templateengine.process.processes;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class Messages {
+ private static final String BUNDLE_NAME = "org.eclipse.cdt.core.templateengine.process.processes.messages"; //$NON-NLS-1$
+
+ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
+ .getBundle(BUNDLE_NAME);
+
+ private Messages() {
+ }
+
+ public static String getString(String key) {
+ try {
+ return RESOURCE_BUNDLE.getString(key);
+ } catch (MissingResourceException e) {
+ return '!' + key + '!';
+ }
+ }
+}
diff --git a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/messages.properties b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/messages.properties
new file mode 100644
index 00000000000..833b13cab31
--- /dev/null
+++ b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/messages.properties
@@ -0,0 +1,58 @@
+###############################################################################
+# 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:
+# Bala Torati (Symbian) - Initial API and implementation
+###############################################################################
+
+AddFiles.1=Add File failure: template source not found:
+AddFiles.2=Add Files failure: template source not found:
+AddFiles.3=Add Files failure: cannot read template source:
+AddFiles.4=Add File failure: cannot read template source:
+AddFiles.5=Add Files failure: File already exists.
+AddFiles.6=Add Files failure:
+AddFiles.7=Add Files failure:
+AddFile.0=Add File failure: template source not found:
+AddFile.1=Add File failure: template source not found:
+AddFile.2=Add File failure: cannot read template source:
+AddFile.3=Add File failure: cannot read template source:
+AddFile.4=Add File failure:
+AddLink.0=Add Link failure:
+SetMBSBooleanOptionValue.0=SetMBSBooleanOptionValue failure:
+SetMBSBooleanOptionValue.3=SetMBSBooleanOptionValue failure: No such file exists:
+SetMBSStringOptionValue.0=SetMBSStringOptionValue failure:
+SetMBSStringOptionValue.3=SetMBSStringOptionValue failure: No such file exists:
+SetMBSStringListOptionValues.0=SetMBSStringListOptionValues failure:
+SetMBSStringListOptionValues.3=SetMBSStringListOptionValues failure: No such file exists:
+NewManagedProject.3=New Project failure:
+NewManagedProject.4=New Project failure:
+NewManagedProject.5=New Project failure: project already existing in work space:
+AppendCreate.1=Add File failure: template source not found:
+AppendCreate.2=Append failure: template source not found:
+AppendCreate.3=Append failure: cannot read template source:
+AppendCreate.4=Append failure: failed while trying to append contents.
+AppendToMBSStringOptionValue.0=AppendToMBSStringOptionValue failure:
+AppendToMBSStringOptionValue.3=AppendToMBSStringOptionValue failure: No such file exists:
+AppendToMBSStringListOptionValues.0=AppendToMBSStringListOptionValues failure:
+AppendToMBSStringListOptionValues.3=AppendToMBSStringListOptionValues failure: No such file exists:
+CreateSourceFolder.0=Create Source Folder failure: project does not exist:
+CreateSourceFolder.1=Create Source Folder failure:
+CreateSourceFolder.2=Create Source Folder failure:
+CreateIncludeFolder.3=Create Include Folder failure: while setting include path:
+ExcludeResources.0=ExcludeResources can only process CDT Managed projects
+Copy.0=Add File failure: template source not found:
+Copy.1=Copy failure: template source not found:
+Copy.3=Copy failure: cannot read template source:
+Copy.4=Copy failure: failed while copying contents.
+Copy.5=Copy failure: failed while copying contents.
+NewProject.7=New Project failure:
+NewProject.8=New Project failure:
+NewProject.9=New Project failure: project already existing in work space:
+Append.0=Add File failure: template source not found:
+Append.1=Copy failure: template source not found:
+Append.3=Copy failure: cannot read template source:
+Append.4=Append failure: failed while trying to append contents.
diff --git a/core/org.eclipse.cdt.ui/.classpath b/core/org.eclipse.cdt.ui/.classpath
index fcd0420f98a..07ee51f5d6a 100644
--- a/core/org.eclipse.cdt.ui/.classpath
+++ b/core/org.eclipse.cdt.ui/.classpath
@@ -3,6 +3,7 @@
+
diff --git a/core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF
index 32dd343f442..700c6937974 100644
--- a/core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF
+++ b/core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF
@@ -47,14 +47,19 @@ Export-Package: org.eclipse.cdt.internal.corext;x-internal:=true,
org.eclipse.cdt.ui.actions,
org.eclipse.cdt.ui.browser.typeinfo,
org.eclipse.cdt.ui.dialogs,
+ org.eclipse.cdt.ui.newui,
+ org.eclipse.cdt.ui.templateengine,
+ org.eclipse.cdt.ui.templateengine.event,
+ org.eclipse.cdt.ui.templateengine.pages,
+ org.eclipse.cdt.ui.templateengine.uitree,
+ org.eclipse.cdt.ui.templateengine.uitree.uiwidgets,
org.eclipse.cdt.ui.text,
org.eclipse.cdt.ui.text.c.hover,
org.eclipse.cdt.ui.text.contentassist,
org.eclipse.cdt.ui.text.folding,
org.eclipse.cdt.ui.wizards,
org.eclipse.cdt.ui.wizards.conversion,
- org.eclipse.cdt.utils.ui.controls,
- org.eclipse.cdt.ui.newui
+ org.eclipse.cdt.utils.ui.controls
Require-Bundle: org.eclipse.ui.ide;bundle-version="[3.3.0,4.0.0)",
org.eclipse.ui.views;bundle-version="[3.2.0,4.0.0)",
org.eclipse.jface.text;bundle-version="[3.3.0,4.0.0)",
diff --git a/core/org.eclipse.cdt.ui/build.properties b/core/org.eclipse.cdt.ui/build.properties
index 5330a7b67f9..bbfa9e58c79 100644
--- a/core/org.eclipse.cdt.ui/build.properties
+++ b/core/org.eclipse.cdt.ui/build.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2003, 2006 IBM Corporation and others.
+# Copyright (c) 2003, 2007 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
@@ -24,7 +24,8 @@ javadoc.packages = org.eclipse.cdt.ui.*,\
source.. = src/,\
browser/,\
- utils.ui/
+ utils.ui/,\
+ templateengine/
jre.compilation.profile=J2SE-1.4
javacSource=1.4
diff --git a/core/org.eclipse.cdt.ui/icons/dlcl16/list-add.gif b/core/org.eclipse.cdt.ui/icons/dlcl16/list-add.gif
new file mode 100644
index 00000000000..5ee82b45c22
Binary files /dev/null and b/core/org.eclipse.cdt.ui/icons/dlcl16/list-add.gif differ
diff --git a/core/org.eclipse.cdt.ui/icons/dlcl16/list-delete.gif b/core/org.eclipse.cdt.ui/icons/dlcl16/list-delete.gif
new file mode 100644
index 00000000000..5fd7e2d44e3
Binary files /dev/null and b/core/org.eclipse.cdt.ui/icons/dlcl16/list-delete.gif differ
diff --git a/core/org.eclipse.cdt.ui/icons/dlcl16/list-edit.gif b/core/org.eclipse.cdt.ui/icons/dlcl16/list-edit.gif
new file mode 100644
index 00000000000..37189728513
Binary files /dev/null and b/core/org.eclipse.cdt.ui/icons/dlcl16/list-edit.gif differ
diff --git a/core/org.eclipse.cdt.ui/icons/dlcl16/list-movedown.gif b/core/org.eclipse.cdt.ui/icons/dlcl16/list-movedown.gif
new file mode 100644
index 00000000000..d2866389ea0
Binary files /dev/null and b/core/org.eclipse.cdt.ui/icons/dlcl16/list-movedown.gif differ
diff --git a/core/org.eclipse.cdt.ui/icons/dlcl16/list-moveup.gif b/core/org.eclipse.cdt.ui/icons/dlcl16/list-moveup.gif
new file mode 100644
index 00000000000..f8440c8161e
Binary files /dev/null and b/core/org.eclipse.cdt.ui/icons/dlcl16/list-moveup.gif differ
diff --git a/core/org.eclipse.cdt.ui/icons/elcl16/list-add.gif b/core/org.eclipse.cdt.ui/icons/elcl16/list-add.gif
new file mode 100644
index 00000000000..45c0e60778b
Binary files /dev/null and b/core/org.eclipse.cdt.ui/icons/elcl16/list-add.gif differ
diff --git a/core/org.eclipse.cdt.ui/icons/elcl16/list-delete.gif b/core/org.eclipse.cdt.ui/icons/elcl16/list-delete.gif
new file mode 100644
index 00000000000..af59a0b19a3
Binary files /dev/null and b/core/org.eclipse.cdt.ui/icons/elcl16/list-delete.gif differ
diff --git a/core/org.eclipse.cdt.ui/icons/elcl16/list-edit.gif b/core/org.eclipse.cdt.ui/icons/elcl16/list-edit.gif
new file mode 100644
index 00000000000..d1aa86cdf6f
Binary files /dev/null and b/core/org.eclipse.cdt.ui/icons/elcl16/list-edit.gif differ
diff --git a/core/org.eclipse.cdt.ui/icons/elcl16/list-movedown.gif b/core/org.eclipse.cdt.ui/icons/elcl16/list-movedown.gif
new file mode 100644
index 00000000000..572933eec50
Binary files /dev/null and b/core/org.eclipse.cdt.ui/icons/elcl16/list-movedown.gif differ
diff --git a/core/org.eclipse.cdt.ui/icons/elcl16/list-moveup.gif b/core/org.eclipse.cdt.ui/icons/elcl16/list-moveup.gif
new file mode 100644
index 00000000000..768c5c1711e
Binary files /dev/null and b/core/org.eclipse.cdt.ui/icons/elcl16/list-moveup.gif differ
diff --git a/core/org.eclipse.cdt.ui/plugin.properties b/core/org.eclipse.cdt.ui/plugin.properties
index 18654b14486..193d2ddf88b 100644
--- a/core/org.eclipse.cdt.ui/plugin.properties
+++ b/core/org.eclipse.cdt.ui/plugin.properties
@@ -411,3 +411,5 @@ CPPproject.desc=Create a new C++ project
Cproject=C project
Cproject.desc=Create a new C project
+TemplatePreferencePage.name=Template Default Values
+Template.Engine.Wizard=template entries contributor
diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml
index d146dddb69a..8a4f64bf812 100644
--- a/core/org.eclipse.cdt.ui/plugin.xml
+++ b/core/org.eclipse.cdt.ui/plugin.xml
@@ -2131,5 +2131,31 @@
name="%exportWizard.CDTCategory.name">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CDTUIImages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CDTUIImages.java
new file mode 100644
index 00000000000..b4436270969
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CDTUIImages.java
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * Copyright (c) 2002, 2007 Rational Software 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 Rational Software - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.ui;
+
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.resource.ImageRegistry;
+import org.eclipse.swt.graphics.Image;
+
+
+/**
+ * Bundle of all images used by the C plugin.
+ */
+public class CDTUIImages {
+
+ // The plugin registry
+ private static ImageRegistry imageRegistry = new ImageRegistry();
+
+ // Subdirectory (under the package containing this class) where 16 color images are
+ private static URL iconBaseURL = null;
+ static {
+ iconBaseURL = Platform.getBundle(CUIPlugin.PLUGIN_ID).getEntry("icons/"); //$NON-NLS-1$
+ }
+
+ private static final String NAME_PREFIX= CUIPlugin.PLUGIN_ID + '.';
+ private static final int NAME_PREFIX_LENGTH= NAME_PREFIX.length();
+ public static final String T_LIST= "elcl16/"; //$NON-NLS-1$
+
+ // Image for file list control
+ public static final String IMG_FILELIST_ADD = NAME_PREFIX + "list-add.gif"; //$NON-NLS-1$
+ public static final ImageDescriptor DESC_FILELIST_ADD = createManaged(T_LIST, IMG_FILELIST_ADD);
+ public static final String IMG_FILELIST_DEL = NAME_PREFIX + "list-delete.gif"; //$NON-NLS-1$
+ public static final ImageDescriptor DESC_FILELIST_DEL = createManaged(T_LIST, IMG_FILELIST_DEL);
+ public static final String IMG_FILELIST_EDIT = NAME_PREFIX + "list-edit.gif"; //$NON-NLS-1$
+ public static final ImageDescriptor DESC_FILELIST_EDIT = createManaged(T_LIST, IMG_FILELIST_EDIT);
+ public static final String IMG_FILELIST_MOVEUP = NAME_PREFIX + "list-moveup.gif"; //$NON-NLS-1$
+ public static final ImageDescriptor DESC_FILELIST_MOVEUP = createManaged(T_LIST, IMG_FILELIST_MOVEUP);
+ public static final String IMG_FILELIST_MOVEDOWN = NAME_PREFIX + "list-movedown.gif"; //$NON-NLS-1$
+ public static final ImageDescriptor DESC_FILELIST_MOVEDOWN = createManaged(T_LIST, IMG_FILELIST_MOVEDOWN);
+
+ private static ImageDescriptor createManaged(String prefix, String name) {
+ return createManaged(imageRegistry, prefix, name);
+ }
+
+ private static ImageDescriptor createManaged(ImageRegistry registry, String prefix, String name) {
+ ImageDescriptor result= ImageDescriptor.createFromURL(makeIconFileURL(prefix, name.substring(NAME_PREFIX_LENGTH)));
+ registry.put(name, result);
+ return result;
+ }
+
+ public static Image get(String key) {
+ return imageRegistry.get(key);
+ }
+
+ private static URL makeIconFileURL(String prefix, String name) {
+ StringBuffer buffer= new StringBuffer(prefix);
+ buffer.append(name);
+ try {
+ return new URL(iconBaseURL, buffer.toString());
+ } catch (MalformedURLException e) {
+ CUIPlugin.getDefault().log(e);
+ return null;
+ }
+ }
+
+ /**
+ * Helper method to access the image registry from the JavaPlugin class.
+ */
+ static ImageRegistry getImageRegistry() {
+ return imageRegistry;
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPlugin.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPlugin.java
index 65da9f7cff9..c91b4ab7c9b 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPlugin.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPlugin.java
@@ -801,4 +801,17 @@ public class CUIPlugin extends AbstractUIPlugin {
return fASTProvider;
}
+ /**
+ * Answers the Shell associated with the active workbench, or
+ * one of the windows associated with the workbench.
+ */
+ public Shell getShell() {
+ if (getActiveWorkbenchShell() != null) {
+ return getActiveWorkbenchShell();
+ } else {
+ IWorkbenchWindow[] windows = getDefault().getWorkbench().getWorkbenchWindows();
+ return windows[0].getShell();
+ }
+ }
+
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/CDTCommonProjectWizard.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/CDTCommonProjectWizard.java
index 0c79cc5ea95..caef8120e9f 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/CDTCommonProjectWizard.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/CDTCommonProjectWizard.java
@@ -209,6 +209,8 @@ implements IExecutableExtension, IWizardWithMemory
public boolean canFinish() {
if (fMainPage.h_selected != null) {
+ if(!fMainPage.h_selected.canFinich())
+ return false;
String s = fMainPage.h_selected.getErrorMessage();
if (s != null) return false;
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/CDTMainWizardPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/CDTMainWizardPage.java
index 0aa4ba0a8af..887a274c9b8 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/CDTMainWizardPage.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/CDTMainWizardPage.java
@@ -113,7 +113,8 @@ import org.eclipse.cdt.internal.ui.CPluginImages;
createDynamicGroup(composite);
- switchTo(updateData(tree, right, show_sup, CDTMainWizardPage.this, getWizard()));
+ switchTo(updateData(tree, right, show_sup, CDTMainWizardPage.this, getWizard()),
+ getDescriptor());
setPageComplete(validatePage());
// Show description on opening
@@ -159,7 +160,8 @@ import org.eclipse.cdt.internal.ui.CPluginImages;
public void widgetSelected(SelectionEvent e) {
if (h_selected != null)
h_selected.setSupportedOnly(show_sup.getSelection());
- switchTo(updateData(tree, right, show_sup, CDTMainWizardPage.this, getWizard()));
+ switchTo(updateData(tree, right, show_sup, CDTMainWizardPage.this, getWizard()),
+ getDescriptor());
}} );
// restore settings from preferences
@@ -256,7 +258,11 @@ import org.eclipse.cdt.internal.ui.CPluginImages;
if (locationArea.isDefault()) return null;
return new Path(locationArea.getProjectLocation());
}
-
+
+ public String getProjectLocationPath() {
+ return locationArea.getProjectLocation();
+ }
+
/**
* Returns the value of the project name field
* with leading and trailing spaces removed.
@@ -509,24 +515,42 @@ import org.eclipse.cdt.internal.ui.CPluginImages;
}
private void switchTo(ICWizardHandler h, EntryDescriptor ed) {
+
if (h == null) h = ed.getHandler();
+
try {
- if (h != null) h.initialize(ed);
+
+ if (h != null && ed != null) h.initialize(ed);
+
} catch (CoreException e) { h = null; }
- switchTo(h);
+
+ if (h_selected != null) h_selected.handleUnSelection();
+
+ h_selected = h;
+
+ if (h == null) return;
+
+ right_label.setText(h_selected.getHeader());
+
+ h_selected.handleSelection();
+
+ h_selected.setSupportedOnly(show_sup.getSelection());
+
}
- /**
- * @param h - new handler
- */
- private void switchTo(ICWizardHandler h) {
- if (h_selected != null) h_selected.handleUnSelection();
- h_selected = h;
- if (h == null) return;
- right_label.setText(h_selected.getHeader());
- h_selected.handleSelection();
- h_selected.setSupportedOnly(show_sup.getSelection());
+
+ private EntryDescriptor getDescriptor() {
+
+ TreeItem[] sel = tree.getSelection();
+
+ if (sel == null || sel.length == 0)
+
+ return null;
+
+ return (EntryDescriptor)sel[0].getData(DESC);
+
}
+
public void toolChainListChanged(int count) {
setPageComplete(validatePage());
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/CWizardHandler.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/CWizardHandler.java
index 9b060db7d76..30ddf1b0014 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/CWizardHandler.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/CWizardHandler.java
@@ -97,7 +97,8 @@ public class CWizardHandler implements ICWizardHandler {
public void postProcess(IProject proj) {}
public boolean isApplicable(EntryDescriptor data) { return true; }
public void initialize(EntryDescriptor data) throws CoreException {}
-
+ public boolean canFinich() {return true;}
+
public Object clone() {
try {
CWizardHandler clone = (CWizardHandler)super.clone();
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/EntryDescriptor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/EntryDescriptor.java
index 815d60e0ecc..ef1b0cd5156 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/EntryDescriptor.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/EntryDescriptor.java
@@ -12,6 +12,8 @@ package org.eclipse.cdt.ui.wizards;
import org.eclipse.swt.graphics.Image;
+import org.eclipse.cdt.core.settings.model.util.CDataUtil;
+
/**
* This class stores data for each tree item
* in "Project types" tree of New Project Wizard.
@@ -62,7 +64,11 @@ public class EntryDescriptor {
public String getPath() {
return path;
}
-
+
+ public String[] getPathArray() {
+ return CDataUtil.stringToArray(path, "/"); //$NON-NLS-1$
+ }
+
public void setParent(EntryDescriptor p) {
parent = p;
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/ICWizardHandler.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/ICWizardHandler.java
index 9ad9e63a4a5..cc55cb3fcf3 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/ICWizardHandler.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/ICWizardHandler.java
@@ -103,5 +103,7 @@ public interface ICWizardHandler extends Cloneable {
*/
public void initialize(EntryDescriptor data) throws CoreException;
+ public boolean canFinich();
+
public Object clone();
}
diff --git a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/internal/templateengine/wizard/TemplateCNewWizard.java b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/internal/templateengine/wizard/TemplateCNewWizard.java
new file mode 100644
index 00000000000..29f4985441b
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/internal/templateengine/wizard/TemplateCNewWizard.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Intel 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:
+ * Intel Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.ui.internal.templateengine.wizard;
+
+import java.util.ArrayList;
+
+import org.eclipse.jface.wizard.IWizard;
+import org.eclipse.swt.widgets.Composite;
+
+import org.eclipse.cdt.core.templateengine.TemplateInfo;
+import org.eclipse.cdt.ui.templateengine.Template;
+import org.eclipse.cdt.ui.templateengine.TemplateEngineUI;
+import org.eclipse.cdt.ui.wizards.EntryDescriptor;
+import org.eclipse.cdt.ui.wizards.ICNewWizard;
+import org.eclipse.cdt.ui.wizards.IWizardItemsListListener;
+
+/**
+ *
+ */
+public class TemplateCNewWizard implements ICNewWizard {
+ /**
+ * Creates and returns an array of items to be displayed
+ */
+ public EntryDescriptor[] createItems(boolean supportedOnly, IWizard wizard) {
+ Template[] templates = TemplateEngineUI.getDefault().getTemplates();
+ ArrayList items = new ArrayList();
+
+ for (int k=0; k < templates.length; k++) {
+ TemplateInfo templateInfo = templates[k].getTemplateInfo();
+
+ items.add(new EntryDescriptor(templates[k].getTemplateId(),
+ templateInfo.getProjectType(),
+ templates[k].getLabel(),
+ templateInfo.isCategory(),
+ null,
+ null));
+ }
+ return (EntryDescriptor[])items.toArray(new EntryDescriptor[items.size()]);
+ }
+
+ public void setDependentControl(Composite parent,
+ IWizardItemsListListener page) {
+ //nothing to do?
+ }
+
+}
diff --git a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/FormBrowser.java b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/FormBrowser.java
new file mode 100644
index 00000000000..f9415e0049a
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/FormBrowser.java
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.ui.templateengine;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.forms.widgets.FormText;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.ui.forms.widgets.ScrolledFormText;
+
+/**
+ * FormBrowser.
+ */
+class FormBrowser {
+ private FormToolkit toolkit;
+ private Composite container;
+ private ScrolledFormText formText;
+ private String text;
+
+ public void createControl(Composite parent) {
+ toolkit = new FormToolkit(parent.getDisplay());
+ int borderStyle = toolkit.getBorderStyle() == SWT.BORDER ? SWT.NULL : SWT.BORDER;
+ container = new Composite(parent, borderStyle);
+ FillLayout flayout = new FillLayout();
+ flayout.marginWidth = 1;
+ flayout.marginHeight = 1;
+ container.setLayout(flayout);
+ formText = new ScrolledFormText(container, SWT.V_SCROLL | SWT.H_SCROLL, false);
+ if (borderStyle == SWT.NULL) {
+ formText.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER);
+ toolkit.paintBordersFor(container);
+ }
+ FormText ftext = toolkit.createFormText(formText, false);
+ formText.setFormText(ftext);
+ formText.setExpandHorizontal(true);
+ formText.setExpandVertical(true);
+ formText.setBackground(toolkit.getColors().getBackground());
+ formText.setForeground(toolkit.getColors().getForeground());
+ ftext.marginWidth = 2;
+ ftext.marginHeight = 2;
+ ftext.setHyperlinkSettings(toolkit.getHyperlinkGroup());
+ formText.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ if (toolkit != null) {
+ toolkit.dispose();
+ toolkit = null;
+ }
+ }
+ });
+ if (text != null) {
+ formText.setText(text);
+ }
+ }
+
+ public Control getControl() {
+ return container;
+ }
+
+ /**
+ * @param text the text to set
+ */
+ public void setText(String text) {
+ this.text = text;
+ if (formText != null) {
+ formText.setText(text);
+ }
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/IPagesAfterTemplateSelectionProvider.java b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/IPagesAfterTemplateSelectionProvider.java
new file mode 100644
index 00000000000..d43f40148fd
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/IPagesAfterTemplateSelectionProvider.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.ui.templateengine;
+
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchWizard;
+
+
+public interface IPagesAfterTemplateSelectionProvider {
+
+ /**
+ * Creates pages that will be appended to the pages returned from
+ * TemplatesChoiceWizard.getPagesAfterTemplateSelection()
+ * Parameters are those used to initialize the wizard.
+ *
+ * @param wizard the wizard requesting the pages
+ * @param workbench the current workbench
+ * @param selection the current object selection
+ *
+ * @since 4.0
+ */
+ IWizardDataPage[] createAdditionalPages(IWorkbenchWizard wizard, IWorkbench workbench, IStructuredSelection selection);
+
+ /**
+ * Gets the previously created pages
+ * @param wizard the wizard that requested creation of the pages
+ *
+ * @since 4.0
+ */
+ IWizardDataPage[] getCreatedPages(IWorkbenchWizard wizard);
+}
diff --git a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/ITemplatesListProvider.java b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/ITemplatesListProvider.java
new file mode 100644
index 00000000000..8628d92bdc4
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/ITemplatesListProvider.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.ui.templateengine;
+
+import org.eclipse.jface.viewers.ITreeContentProvider;
+
+/**
+ * ITemplatesListProvider
+ *
+ * @since 4.0
+ */
+public interface ITemplatesListProvider extends ITreeContentProvider {
+
+ Template[] getTemplates();
+
+ String getDescription(Object object);
+
+ boolean showTemplatesInTreeView();
+
+}
diff --git a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/IWizardDataPage.java b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/IWizardDataPage.java
new file mode 100644
index 00000000000..04aac5e5e39
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/IWizardDataPage.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.ui.templateengine;
+
+import java.util.Map;
+
+import org.eclipse.jface.wizard.IWizardPage;
+
+/**
+ * IWizardDataPage
+ *
+ * @since 4.0
+ */
+public interface IWizardDataPage extends IWizardPage {
+ Map/**/ getPageData();
+}
diff --git a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/Messages.java b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/Messages.java
new file mode 100644
index 00000000000..f79224e291a
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/Messages.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.ui.templateengine;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class Messages {
+ private static final String BUNDLE_NAME = "org.eclipse.cdt.ui.templateengine.messages"; //$NON-NLS-1$
+
+ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
+ .getBundle(BUNDLE_NAME);
+
+ private Messages() {
+ }
+
+ public static String getString(String key) {
+ try {
+ return RESOURCE_BUNDLE.getString(key);
+ } catch (MissingResourceException e) {
+ return '!' + key + '!';
+ }
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/ProjectSelectionPage.java b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/ProjectSelectionPage.java
new file mode 100644
index 00000000000..ccab0d912cc
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/ProjectSelectionPage.java
@@ -0,0 +1,330 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.ui.templateengine;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.window.Window;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.ElementListSelectionDialog;
+
+import org.eclipse.cdt.core.CCProjectNature;
+import org.eclipse.cdt.core.CProjectNature;
+import org.eclipse.cdt.core.model.CModelException;
+import org.eclipse.cdt.core.model.CoreModel;
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.ICProject;
+import org.eclipse.cdt.ui.CElementLabelProvider;
+import org.eclipse.cdt.ui.CUIPlugin;
+
+import org.eclipse.cdt.internal.ui.ICHelpContextIds;
+
+public class ProjectSelectionPage extends WizardPage implements IWizardDataPage {
+
+ private static final String PAGE_NAME= "NewProjectSelectionWizardPage"; //$NON-NLS-1$
+ private static final String PAGE_TITLE = Messages.getString("ProjectSelectionPage.0"); //$NON-NLS-1$
+ private static final String PAGE_DESCRIPTION = Messages.getString("ProjectSelectionPage.1"); //$NON-NLS-1$
+
+ private Label projectNameLabel;
+ private Button projectBrowseButton;
+ private Text projectNameText;
+ private String projectName = ""; //$NON-NLS-1$
+
+ private IWorkspaceRoot workspaceRoot;
+ private ICProject currentCProject;
+
+ public ProjectSelectionPage() {
+ super(PAGE_NAME);
+ setTitle(PAGE_TITLE);
+ setDescription(PAGE_DESCRIPTION);
+
+ workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
+
+ setPageComplete(false);
+ }
+
+ public void init(IStructuredSelection selection) {
+ if (selection == null || selection.isEmpty()) {
+ setDefaultAttributes();
+ return;
+ }
+
+ Object selectedElement= selection.getFirstElement();
+ if (selectedElement == null) {
+ selectedElement= getActiveEditorCInput();
+ }
+
+ String projPath= null;
+
+ if (selectedElement instanceof IResource) {
+ IProject project= ((IResource)selectedElement).getProject();
+ if (project != null) {
+ projPath= project.getFullPath().makeRelative().toString();
+ }
+ } else if (selectedElement instanceof ICElement) {
+ ICProject cProject= ((ICElement)selectedElement).getCProject();
+ if (cProject != null) {
+ projPath= cProject.getProject().getFullPath().makeRelative().toString();
+ }
+ }
+
+ if (projPath != null) {
+ projectName = projPath;
+ } else {
+ setDefaultAttributes();
+ }
+ }
+
+ /**
+ * If the current active editor edits a c element return it, else
+ * return null
+ */
+ private ICElement getActiveEditorCInput() {
+ IWorkbenchPage page= CUIPlugin.getActivePage();
+ if (page != null) {
+ IEditorPart part= page.getActiveEditor();
+ if (part != null) {
+ IEditorInput editorInput= part.getEditorInput();
+ if (editorInput != null) {
+ return (ICElement)editorInput.getAdapter(ICElement.class);
+ }
+ }
+ }
+ return null;
+ }
+
+ private void setDefaultAttributes() {
+
+ try {
+ // find the first C project
+ IProject[] projects= workspaceRoot.getProjects();
+ for (int i= 0; i < projects.length; i++) {
+ IProject project= projects[i];
+ if (project.hasNature(CProjectNature.C_NATURE_ID) || project.hasNature(CCProjectNature.CC_NATURE_ID)) {
+ projectName = project.getFullPath().makeRelative().toString();
+ break;
+ }
+ }
+ } catch (CoreException e) {
+ // ignore here
+ }
+ }
+
+ private Map data = new HashMap(2);
+
+ public Map getPageData() {
+ String cPojectName = currentCProject.getResource().getName().trim();
+ data.put("projectName", cPojectName); //$NON-NLS-1$
+ data.put("baseName", getBaseName(cPojectName)); //$NON-NLS-1$
+ return data;
+ }
+
+ private String getBaseName(String name) {
+ String baseName = name;
+ int dot = baseName.lastIndexOf('.');
+ if (dot != -1) {
+ baseName = baseName.substring(dot + 1);
+ }
+ dot = baseName.indexOf(' ');
+ if (dot != -1) {
+ baseName = baseName.substring(0, dot);
+ }
+ return baseName;
+ }
+
+ public void createControl(Composite parent) {
+ initializeDialogUnits(parent);
+
+ Composite composite= new Composite(parent, SWT.NONE);
+
+ GridLayout layout= new GridLayout();
+ layout.marginWidth= 0;
+ layout.marginHeight= 0;
+ layout.numColumns= 3;
+ composite.setLayout(layout);
+
+ createProjectFiled(composite);
+
+ setControl(composite);
+ Dialog.applyDialogFont(composite);
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, ICHelpContextIds.NEW_SRCFLDER_WIZARD_PAGE);
+
+ projectNameText.setFocus();
+ projectNameText.setSelection(0, projectNameText.getText().length());
+
+ setPageComplete(validatePage());
+ }
+
+ private void createProjectFiled(Composite parent) {
+ getLabelControl(parent);
+ GridData gdLabel = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
+ gdLabel.horizontalSpan= 1;
+ projectNameLabel.setLayoutData(gdLabel);
+
+
+ getTextControl(parent);
+ GridData gdText = new GridData();
+ gdText.horizontalAlignment= GridData.FILL;
+ gdText.grabExcessHorizontalSpace= true;
+ gdText.horizontalSpan= 1;
+ gdText.widthHint = convertWidthInCharsToPixels(40);
+ projectNameText.setLayoutData(gdText);
+
+ getButtonControl(parent);
+ GridData gdButton = new GridData();
+ gdButton.horizontalAlignment= GridData.FILL;
+ gdButton.grabExcessHorizontalSpace= false;
+ gdButton.horizontalSpan= 1;
+ projectBrowseButton.setLayoutData(gdButton);
+ }
+
+ /**
+ * Creates or returns the created Label control.
+ * @param parent The parent composite
+ */
+ private void getLabelControl(Composite parent) {
+ projectNameLabel = new Label(parent, SWT.LEFT | SWT.WRAP);
+ projectNameLabel.setText(Messages.getString("ProjectSelectionPage.4")); //$NON-NLS-1$
+ projectNameLabel.setFont(parent.getFont());
+ projectNameLabel.setEnabled(true);
+ }
+
+ /**
+ * Creates or returns the created text control.
+ * @param parent The parent composite
+ */
+ private void getTextControl(Composite parent) {
+ projectNameText = new Text(parent, SWT.SINGLE | SWT.BORDER);
+ projectNameText.setText(projectName);
+ projectNameText.setFont(parent.getFont());
+ projectNameText.setEnabled(true);
+ projectNameText.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ setPageComplete(validatePage());
+ }
+ });
+ }
+
+ /**
+ * Creates or returns the created buttom widget.
+ * @param parent The parent composite
+ */
+ private void getButtonControl(Composite parent) {
+ projectBrowseButton = new Button(parent, SWT.PUSH);
+ projectBrowseButton.setText(Messages.getString("ProjectSelectionPage.5")); //$NON-NLS-1$
+ projectBrowseButton.setFont(parent.getFont());
+ projectBrowseButton.setEnabled(true);
+ projectBrowseButton.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ packRootChangeControlPressed();
+ }
+ public void widgetSelected(SelectionEvent e) {
+ packRootChangeControlPressed();
+ }
+ });
+ }
+
+ public void setVisible(boolean visible) {
+ super.setVisible(visible);
+ }
+
+ protected void packRootChangeControlPressed() {
+ ICProject cProject= chooseProject();
+ if (cProject != null) {
+ IPath path= cProject.getProject().getFullPath().makeRelative();
+ projectName = path.toOSString();
+ projectNameText.setText(projectName);
+ }
+ }
+
+ private boolean validatePage() {
+ currentCProject= null;
+
+ String projectName = projectNameText.getText();
+ if (projectName.length() == 0) {
+ setErrorMessage(Messages.getString("ProjectSelectionPage.6")); //$NON-NLS-1$
+ return false;
+ }
+
+ IPath path= new Path(projectName);
+ if (path.segmentCount() != 1) {
+ setErrorMessage(Messages.getString("ProjectSelectionPage.7")); //$NON-NLS-1$
+ return false;
+ }
+
+ IProject project= workspaceRoot.getProject(path.toString());
+ if (!project.exists()) {
+ setErrorMessage(Messages.getString("ProjectSelectionPage.8")); //$NON-NLS-1$
+ return false;
+ }
+
+ try {
+ if (project.hasNature(CProjectNature.C_NATURE_ID) || project.hasNature(CCProjectNature.CC_NATURE_ID)) {
+ currentCProject= CoreModel.getDefault().create(project);
+ setErrorMessage(null);
+ return true;
+ }
+ } catch (CoreException e) {
+ CUIPlugin.getDefault().log(e);
+ currentCProject= null;
+ }
+
+ setErrorMessage(Messages.getString("ProjectSelectionPage.9")); //$NON-NLS-1$
+ return false;
+ }
+
+ private ICProject chooseProject() {
+ ICProject[] projects;
+ try {
+ projects= CoreModel.create(workspaceRoot).getCProjects();
+ } catch (CModelException e) {
+ CUIPlugin.getDefault().log(e);
+ projects= new ICProject[0];
+ }
+
+ ILabelProvider labelProvider= new CElementLabelProvider(CElementLabelProvider.SHOW_DEFAULT);
+ ElementListSelectionDialog dialog= new ElementListSelectionDialog(getShell(), labelProvider);
+ dialog.setTitle(Messages.getString("ProjectSelectionPage.10")); //$NON-NLS-1$
+ dialog.setMessage(Messages.getString("ProjectSelectionPage.11")); //$NON-NLS-1$
+ dialog.setElements(projects);
+ dialog.setInitialSelections(new Object[] { currentCProject });
+ if (dialog.open() == Window.OK) {
+ return (ICProject) dialog.getFirstResult();
+ }
+ return null;
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/SimpleElementException.java b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/SimpleElementException.java
new file mode 100644
index 00000000000..b13940adbb0
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/SimpleElementException.java
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.ui.templateengine;
+
+
+
+/**
+ * This Exception is thrown when, we execute getNextChild, addToChildList and
+ * getChildCount on an InputUIElement.
+ *
+ * @since 4.0
+ */
+
+public class SimpleElementException extends Exception {
+
+ private static final long serialVersionUID = 0000000000L;
+
+ /**
+ * The description of the exception.
+ */
+ String expDefinition;
+
+ private static final String EXCEPTION_STRING = Messages.getString("SimpleElementException.0"); //$NON-NLS-1$
+
+ /**
+ * Constructor receives description of this instance of event as parameter.
+ * The same is assigned to iExpDefinition.
+ */
+ public SimpleElementException() {
+ super(EXCEPTION_STRING);
+ expDefinition = EXCEPTION_STRING;
+ }
+
+ /**
+ * Constructor receives description of this instance of event as parameter.
+ * The same is assigned to iExpDefinition.
+ *
+ * @param def
+ */
+ public SimpleElementException(String def) {
+ super(def);
+ expDefinition = def;
+ }
+
+ /**
+ * The description of the SimpleElementException is returned.
+ *
+ * @return String
+ */
+ public String toString() {
+ return expDefinition;
+ }
+
+}
diff --git a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/Template.java b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/Template.java
new file mode 100644
index 00000000000..fb432e55ca1
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/Template.java
@@ -0,0 +1,210 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.ui.templateengine;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.wizard.IWizard;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.ui.IWorkbenchWizard;
+import org.eclipse.ui.actions.WorkspaceModifyOperation;
+import org.w3c.dom.Element;
+import org.xml.sax.SAXException;
+
+import org.eclipse.cdt.core.templateengine.TemplateCore;
+import org.eclipse.cdt.core.templateengine.TemplateDescriptor;
+import org.eclipse.cdt.core.templateengine.TemplateEngine;
+import org.eclipse.cdt.core.templateengine.TemplateInfo;
+import org.eclipse.cdt.core.templateengine.process.ProcessFailureException;
+import org.eclipse.cdt.ui.CUIPlugin;
+import org.eclipse.cdt.ui.templateengine.pages.UIPagesProvider;
+import org.eclipse.cdt.ui.templateengine.pages.UIWizardPage;
+import org.eclipse.cdt.ui.templateengine.uitree.UIElementTreeBuilderHelper;
+import org.eclipse.cdt.ui.templateengine.uitree.UIElementTreeBuilderManager;
+
+/**
+ * Template class is responsible for initiating GUI construction. Collecting data from GUI and
+ * initiating process part of Template Engine. This is created per TemplateDescriptor basis.
+ * Once The Template is created it creates a TemplateDescriptor for the XML file name given.
+ *
+ * @since 4.0
+ */
+
+public class Template extends TemplateCore {
+
+ private TemplateDescriptor templateDescriptor;
+ private UIElementTreeBuilderManager uiElementTreeBuilderManager;
+ private UIPagesProvider uiPagesProvider;
+ private Map/**/ pageMap;
+
+ public Template(TemplateInfo templateInfo) throws IOException, ProcessFailureException, SAXException, ParserConfigurationException {
+ super(templateInfo);
+ templateDescriptor = getTemplateDescriptor();
+ uiElementTreeBuilderManager = new UIElementTreeBuilderManager(new UIElementTreeBuilderHelper(templateDescriptor));
+ uiPagesProvider = new UIPagesProvider();
+ }
+
+ /**
+ * 1. get PropertyGroupList.
+ * 2. clear UIPage's display order Vector.
+ * 3. for each PropertyGroup create the UIElementTree.
+ * 4. Request the UIPagesProvider to generate UIPages for the Tree.
+ * 5. return the HashMap of UIPages.
+ */
+ public Map/**/ getUIPages() {
+ if (pageMap == null) {
+ pageMap = new HashMap/**/();
+ List rootPropertyGrouplist = templateDescriptor.getPropertyGroupList();
+
+ uiPagesProvider.clearOrderVector();
+
+ for (int i = 0; i < rootPropertyGrouplist.size(); i++) {
+ // since the tree is constructed for a list of PropertyGroup's tree
+ // root is set to null
+ // before invoking createUIElementTree(...).
+ uiElementTreeBuilderManager.setUIElementTreeRootNull();
+ uiElementTreeBuilderManager.createUIElementTree(null, (Element) rootPropertyGrouplist.get(i));
+ pageMap.putAll(uiPagesProvider.getWizardUIPages(uiElementTreeBuilderManager.getUIElementTreeRoot(), getValueStore()));
+ }
+ }
+
+ return pageMap;
+ }
+
+
+ public IWizardPage[] getTemplateWizardPages(IWizardPage predatingPage, IWizardPage followingPage, IWizard wizard) {
+ List pages= new ArrayList();
+// if (predatingPage != null) {
+// pages.add(predatingPage);
+// }
+
+ Map templatePages = getUIPages();
+ List templatePagesOrderVector = getPagesOrderVector();
+ if (templatePagesOrderVector.size() != 0) {
+ IWizardPage prevPage = predatingPage;
+
+ for (int i=0; i < templatePagesOrderVector.size(); i++) {
+ UIWizardPage page = (UIWizardPage) templatePages.get(templatePagesOrderVector.get(i));
+ pages.add(page);
+ page.setPreviousPage(prevPage);
+ if (i+1 < templatePagesOrderVector.size()) {
+ page.setNextPage((UIWizardPage) templatePages.get(templatePagesOrderVector.get(i+1)));
+ } else {
+ page.setNextPage(followingPage);
+ }
+ page.setWizard(wizard);
+ prevPage = page;
+ }
+
+ try {
+ IWizardDataPage[] extraPages = getExtraCreatedPages((IWorkbenchWizard)wizard);
+ for (int i=0; i < extraPages.length; i++) {
+ IWizardDataPage page = extraPages[i];
+ pages.add(page);
+ page.setPreviousPage(prevPage);
+ //TODO: set the next page for page
+ //page.setNextPage(extraPages[i+1]);
+ page.setWizard(wizard);
+ prevPage = page;
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ followingPage.setPreviousPage(prevPage);
+ } else {
+ followingPage.setPreviousPage(predatingPage);
+ }
+
+// pages.add(followingPage);
+
+ return (IWizardPage[]) pages.toArray(new IWizardPage[pages.size()]);
+ }
+
+ IWizardDataPage[] getExtraCreatedPages(IWorkbenchWizard wizard) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
+ TemplateInfo templateInfo = getTemplateInfo();
+ String pagesProvider = templateInfo.getExtraPagesProvider();
+ if (pagesProvider != null) {
+ IPagesAfterTemplateSelectionProvider extraPagesProvider = (IPagesAfterTemplateSelectionProvider) Class.forName(pagesProvider).newInstance();
+ if (extraPagesProvider != null) {
+ List/**/ pageList = new ArrayList/**/();
+ IWizardDataPage[] extraPages = extraPagesProvider.getCreatedPages(wizard);
+ pageList.addAll(Arrays.asList(extraPages));
+ return (IWizardDataPage[]) pageList.toArray(new IWizardDataPage[pageList.size()]);
+ }
+ }
+ return new IWizardDataPage[0];
+ }
+
+
+ /**
+ *
+ * @return List,which contains Page display order
+ */
+
+ public List/**/ getPagesOrderVector() {
+ return uiPagesProvider.getOrderVector();
+ }
+
+ /**
+ * this method is for JUnit Test case excecution. return the
+ * UIElementTreeBuilderManager instance used by this Template.
+ *
+ * @return UIElementTreeBuilderManager
+ */
+ public UIElementTreeBuilderManager getUIElementTreeBuilderManager() {
+ return uiElementTreeBuilderManager;
+ }
+
+ /**
+ * initializeProcessBlockList() will create the ProcessBlockList,
+ * processPorcessBlockList() will invoke each process execution by assigning
+ * resources to each process (Ref. ProcessResourceManager).
+ * @param monitor
+ */
+ public IStatus[] executeTemplateProcesses(IProgressMonitor monitor, final boolean showError) {
+ setDirty();
+ TemplateEngine.getDefault().updateSharedDefaults(this);
+ final IStatus[][] result = new IStatus[1][];
+ WorkspaceModifyOperation wmo = new WorkspaceModifyOperation() {
+ protected void execute(IProgressMonitor monitor) throws org.eclipse.core.runtime.CoreException ,java.lang.reflect.InvocationTargetException ,InterruptedException {
+ try {
+ result[0] = getProcessHandler().processAll(monitor);
+ } catch (ProcessFailureException e) {
+ if (showError) {
+ TemplateEngineUIUtil.showError(e.getMessage(), e.getCause());
+ }
+ result[0] = new IStatus[] {new Status(IStatus.ERROR, CUIPlugin.getPluginId(), IStatus.ERROR, e.getMessage(), e)};
+ }
+ }
+ };
+ try {
+ wmo.run(monitor); // TODO support progress monitors
+ } catch(InterruptedException ie) {
+ throw new RuntimeException(ie);
+ } catch(InvocationTargetException ite) {
+ throw new RuntimeException(ite.getTargetException());
+ }
+ return result[0];
+ }
+
+}
diff --git a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/TemplateClassWizard.java b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/TemplateClassWizard.java
new file mode 100644
index 00000000000..4428c6182cb
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/TemplateClassWizard.java
@@ -0,0 +1,132 @@
+/*******************************************************************************
+ * 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
+ *******************************************************************************/
+package org.eclipse.cdt.ui.templateengine;
+
+import java.util.Arrays;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExecutableExtension;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
+
+public class TemplateClassWizard extends TemplatesChoiceWizard implements INewWizard, IExecutableExtension {
+
+ public static final String WIZARD_ID = TemplateClassWizard.class.getName();
+
+ private IWizardDataPage[] pagesBeforeTemplatePages;
+ private IWizardDataPage[] pagesAfterTemplatePages;
+ private IWizardDataPage[] pagesAfterTemplateSelection;
+
+ private ProjectSelectionPage projectSelectionPage;
+
+ private IConfigurationElement configElement;
+
+ public TemplateClassWizard() {
+ super();
+ setWindowTitle(Messages.getString("TemplateClassWizard.0")); //$NON-NLS-1$
+ //TODO: Fix the imagedescriptor later.
+// setDefaultPageImageDescriptor(TemplateEnginePlugin.imageDescriptorFromPlugin(TemplateEnginePlugin.getDefault().getWizardIconPluginID(), TemplateEnginePlugin.getDefault().getWizardIconFile()));
+ }
+
+ public String getListSelectionTitle()
+ {
+ return Messages.getString("TemplateClassWizard.1"); //$NON-NLS-1$
+ }
+
+ public String getListSelectionDescription()
+ {
+ return Messages.getString("TemplateClassWizard.2"); //$NON-NLS-1$
+ }
+
+ public String getListSelectionLabel()
+ {
+ return Messages.getString("TemplateClassWizard.3"); //$NON-NLS-1$
+ }
+
+ protected IWizardDataPage[] getPagesBeforeTemplatePages() {
+ if (pagesBeforeTemplatePages == null) {
+ projectSelectionPage = new ProjectSelectionPage();
+ projectSelectionPage.setTitle(Messages.getString("TemplateClassWizard.4")); //$NON-NLS-1$
+ projectSelectionPage.setDescription(Messages.getString("TemplateClassWizard.5")); //$NON-NLS-1$
+ projectSelectionPage.init(selection);
+ pagesBeforeTemplatePages = new IWizardDataPage[] {projectSelectionPage};
+ }
+ return pagesBeforeTemplatePages;
+ }
+
+ protected IWizardDataPage[] getPagesAfterTemplatePages() {
+ if (pagesAfterTemplatePages == null) {
+ pagesAfterTemplatePages = new IWizardDataPage[] {};
+ }
+ return pagesAfterTemplatePages;
+ }
+
+ public Template[] getTemplates() {
+ SortedSet templateList = new TreeSet(Template.TEMPLATE_ID_CASE_INSENSITIVE_COMPARATOR);
+
+ templateList.addAll(Arrays.asList(TemplateEngineUI.getDefault().getTemplates()));
+
+ return (Template[]) templateList.toArray(new Template[templateList.size()]);
+ }
+
+ public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException {
+ configElement = config;
+ }
+
+ public boolean performFinish() {
+ boolean retVal = super.performFinish();
+ BasicNewProjectResourceWizard.updatePerspective(configElement);
+ return retVal;
+ }
+
+ protected IWizardDataPage[] getPagesAfterTemplateSelection() {
+ if (pagesAfterTemplateSelection == null) {
+ pagesAfterTemplateSelection = new IWizardDataPage[] {};
+ }
+ return pagesAfterTemplateSelection;
+ }
+
+ public String getDescription(Object object) {
+ if (object instanceof Template)
+ {
+ return ((Template)object).getDescription();
+ }
+ return ""; //$NON-NLS-1$
+ }
+
+ public boolean showTemplatesInTreeView() {
+ return false;
+ }
+
+ public Object[] getChildren(Object parentElement) {
+ return null;
+ }
+
+ public Object getParent(Object element) {
+ return null;
+ }
+
+ public boolean hasChildren(Object element) {
+ return false;
+ }
+
+ public Object[] getElements(Object inputElement) {
+ return getTemplates();
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/TemplateDrivenWizard.java b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/TemplateDrivenWizard.java
new file mode 100644
index 00000000000..b41197a2215
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/TemplateDrivenWizard.java
@@ -0,0 +1,184 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.ui.templateengine;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation;
+
+import org.eclipse.cdt.core.templateengine.process.ProcessFailureException;
+import org.eclipse.cdt.ui.CUIPlugin;
+
+
+/**
+ * Any wizard intending to use template (@see org.eclipse.cdt.core.templateenginee.Template) based pages
+ * can extend this wizard and use it. Alternatively, a wizard intending to show a choice of templates
+ * should use TemplatesChoiceWizard (@see org.eclipse.cdt.core.templateenginee.ui.TemplatesChoiceWizard)
+ *
+ */
+public abstract class TemplateDrivenWizard extends Wizard {
+ protected List/**/ pagesBeforeTemplatePages = new ArrayList/**/();
+ protected List/**/ pagesAfterTemplatePages = new ArrayList/**/();
+
+ protected Template template;
+ protected int pageIndex;
+ protected Map/**/ templatePages;
+ protected Composite pageContainer;
+ protected List/**/ templatePagesOrderVector;
+
+ public final void addPage(IWizardPage page) {
+ page.setWizard(this);
+ }
+
+ public final void addPages() {
+ IWizardPage[] pages = getPagesBeforeTemplatePages();
+ for(int i=0; i pagesBeforeTemplatePages.size() + templatePagesOrderVector.size()) {//current is some page after template pages other than the first post-template page
+ pageIndex--;
+ return (IWizardPage) pagesAfterTemplatePages.get(pageIndex - pagesBeforeTemplatePages.size() - templatePagesOrderVector.size());
+ } else if (pageIndex > pagesBeforeTemplatePages.size()) {//current is some template page other than the first
+ pageIndex--;
+ return (IWizardPage) templatePages.get(templatePagesOrderVector.get(pageIndex - pagesBeforeTemplatePages.size()));
+ } else if (pageIndex > 0) {
+ pageIndex--;
+ return (IWizardPage) pagesBeforeTemplatePages.get(pageIndex);
+ }
+ return null;
+ }
+
+ public IWizardPage getNextPage(IWizardPage page) {
+ if (pageIndex < pagesBeforeTemplatePages.size() - 1) {//current is a page before template pages that is not the final one
+ pageIndex++;
+ return (IWizardPage) pagesBeforeTemplatePages.get(pageIndex);
+ } else if (pageIndex < pagesBeforeTemplatePages.size() + templatePagesOrderVector.size() - 1) {
+ if(pageIndex == pagesBeforeTemplatePages.size() - 1) {//current is final page before template pages
+ Template template = getTemplate();
+ if (this.template != null && !this.template.equals(template)) {//template changed
+ this.template = template;
+ //TODO: dispose old template pages
+ templatePages = template.getUIPages();
+ templatePagesOrderVector = template.getPagesOrderVector();
+ }
+ }//else current is some template page other than the final one
+ pageIndex++;
+ IWizardPage nextPage = (IWizardPage) templatePages.get(templatePagesOrderVector.get(pageIndex - pagesBeforeTemplatePages.size()));
+ nextPage.setWizard(this);
+ if (nextPage.getControl() == null) {
+ nextPage.createControl(pageContainer);
+ }
+ return nextPage;
+ } else if (pageIndex < pagesBeforeTemplatePages.size() + templatePagesOrderVector.size() + pagesAfterTemplatePages.size() - 1) {//current is final template page or a page after the final template page
+ pageIndex++;
+ return (IWizardPage) pagesAfterTemplatePages.get(pageIndex - pagesBeforeTemplatePages.size() - templatePagesOrderVector.size());
+ }
+ return null;
+ }
+
+ public final boolean canFinish() {
+ for(Iterator i = pagesBeforeTemplatePages.iterator(); i.hasNext(); ) {
+ IWizardPage page = (IWizardPage) i.next();
+ if (!page.isPageComplete()) {
+ return false;
+ }
+ }
+ if (templatePages == null) {
+ return false;
+ }
+ for(Iterator i = templatePages.values().iterator(); i.hasNext(); ) {
+ IWizardPage page = (IWizardPage) i.next();
+ if (!page.isPageComplete()) {
+ return false;
+ }
+ }
+ for(Iterator i = pagesAfterTemplatePages.iterator(); i.hasNext(); ) {
+ IWizardPage page = (IWizardPage) i.next();
+ if (!page.isPageComplete()) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public boolean performFinish() {
+ IRunnableWithProgress op= new WorkspaceModifyDelegatingOperation(new IRunnableWithProgress() {
+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ finishPage(monitor);
+ }
+ });
+
+ try {
+ getContainer().run(true, false, op);
+ } catch (InvocationTargetException e) {
+ return false;
+ } catch (InterruptedException e) {
+ return false;
+ }
+ return true;
+ }
+
+ private boolean finishPage(IProgressMonitor monitor) {
+ IStatus[] statuses = template.executeTemplateProcesses(monitor, false);
+ if (statuses.length == 1 && statuses[0].getException() instanceof ProcessFailureException) {
+ TemplateEngineUIUtil.showError(statuses[0].getMessage(), statuses[0].getException());
+ return false;
+ } else {
+ String msg = Messages.getString("TemplateDrivenWizard.0"); //$NON-NLS-1$
+ TemplateEngineUIUtil.showStatusDialog(msg, new MultiStatus(CUIPlugin.getPluginId(), IStatus.OK, statuses, msg, null));
+ return true;
+ }
+ }
+
+ public final void createPageControls(Composite pageContainer) {
+ super.createPageControls(pageContainer);
+ this.pageContainer = pageContainer;
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/TemplateEngineUI.java b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/TemplateEngineUI.java
new file mode 100644
index 00000000000..dbaab4cb63a
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/TemplateEngineUI.java
@@ -0,0 +1,110 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.ui.templateengine;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.cdt.core.templateengine.TemplateCore;
+import org.eclipse.cdt.core.templateengine.TemplateEngine;
+import org.eclipse.cdt.core.templateengine.TemplateInfo;
+
+
+/**
+ * TemplateEngine is implemented as a Singleton. TemplateEngine is responsible for
+ * creating SharedDefaults and initializing the SharedDefaults. Template instances
+ * are obtained from TemplateEngine.
+ *
+ * @since 4.0
+ */
+public class TemplateEngineUI {
+
+ /**
+ * static reference to the Singleton TemplateEngine instance.
+ */
+ private static TemplateEngineUI TEMPLATE_ENGINE_UI = new TemplateEngineUI();
+
+ private TemplateEngineUI() {
+ }
+
+ public static TemplateEngineUI getDefault() {
+ return TEMPLATE_ENGINE_UI;
+ }
+
+ /**
+ * This method will be called by Contianer UIs (Wizard, PropertyPage,
+ * PreferencePage). Create a Template instance, update the ValueStore, with
+ * SharedDefaults. This method calls the getTemplate(URL), after getting URL
+ * for the given String TemplateDescriptor.
+ */
+ public TemplateCore getFirstTemplate(String projectType) {
+ return getFirstTemplate(projectType, null, null);
+ }
+
+ public TemplateCore getFirstTemplate(String projectType, String toolChain, String usageFilter) {
+ try {
+ return new Template(TemplateEngine.getDefault().getTemplateInfos(projectType, toolChain, usageFilter)[0]);
+ } catch (Exception e) {
+ // ignore
+ }
+ return null;
+ }
+
+ public Template[] getTemplates(String projectType, String toolChain, String usageFilter) {
+ TemplateInfo[] templateInfoArray = TemplateEngine.getDefault().getTemplateInfos(projectType, toolChain, usageFilter);
+ List/**/ templatesList = new ArrayList/**/();
+ for (int i=0; i*/ templatesList = new ArrayList/**/();
+ for (int i=0; i*/ statuses = ((ProcessFailureException) t).getStatuses();
+ if (statuses == null || statuses.isEmpty()) {
+ Throwable p = t;
+ do {
+ p = p.getCause();
+ if (p != null) {
+ statuses = ((ProcessFailureException) p).getStatuses();
+ }
+ } while ((statuses == null || statuses.isEmpty()) && p != null && p instanceof ProcessFailureException);
+ if (statuses == null || statuses.isEmpty()) {
+ status = new Status(IStatus.ERROR, CUIPlugin.getPluginId(), IStatus.ERROR, t.getMessage(), t);
+ } else {
+ status = new MultiStatus(CUIPlugin.getPluginId(), IStatus.ERROR, (IStatus[]) statuses.toArray(new IStatus[statuses.size()]), t.getMessage(), t);
+ }
+ } else {
+ status = new MultiStatus(CUIPlugin.getPluginId(), IStatus.ERROR, (IStatus[]) statuses.toArray(new IStatus[statuses.size()]), t.getMessage(), t);
+ }
+ } else if (t instanceof CoreException) {
+ status = ((CoreException) t).getStatus();
+ if (status != null && message.equals(status.getMessage())) {
+ message = null;
+ }
+ } else {
+ status = new Status(IStatus.ERROR, CUIPlugin.getPluginId(), -1, TemplateEngineMessages.getString("TemplateEngine.internalError") + message, t); //$NON-NLS-1$
+ }
+ } else {
+ status = new Status(IStatus.ERROR, CUIPlugin.getPluginId(), -1, TemplateEngineMessages.getString("TemplateEngine.internalError") + message, null); //$NON-NLS-1$
+ }
+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ if(window == null){
+ IWorkbenchWindow windows[] = PlatformUI.getWorkbench().getWorkbenchWindows();
+ window = windows[0];
+ }
+ ErrorDialog.openError(window.getShell(), TemplateEngineMessages.getString("TemplateEngine.templateEngine"), message, status); //$NON-NLS-1$
+ }
+
+ /**
+ * Shows the Status meassage in Dialog Box.
+ * @param message
+ * @param status
+ *
+ * @since 4.0
+ */
+ public static void showStatusDialog(String message, IStatus status) {
+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ if(window == null){
+ IWorkbenchWindow windows[] = PlatformUI.getWorkbench().getWorkbenchWindows();
+ window = windows[0];
+ }
+ ErrorDialog.openError(window.getShell(), TemplateEngineMessages.getString("TemplateEngine.templateEngine"), message, status); //$NON-NLS-1$
+ }
+
+}
diff --git a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/TemplateListSelectionPage.java b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/TemplateListSelectionPage.java
new file mode 100644
index 00000000000..1b8e89cc978
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/TemplateListSelectionPage.java
@@ -0,0 +1,271 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.ui.templateengine;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.StructuredViewer;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.wizard.IWizard;
+import org.eclipse.jface.wizard.IWizardNode;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.jface.wizard.WizardSelectionPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.SashForm;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+
+
+/**
+ * TemplateListSelectionPage
+ */
+class TemplateListSelectionPage extends WizardSelectionPage implements ISelectionChangedListener {
+
+ private String labelText;
+ private FormBrowser descriptionBrowser;
+ private TreeViewer wizardSelectionTreeViewer = null;
+ private TableViewer wizardSelectionTableViewer = null;
+ private StructuredViewer wizardSelectionViewer = null;
+ private TemplatesChoiceWizard parentWizard;
+ private Template[] templates;
+
+ public TemplateListSelectionPage(TemplatesChoiceWizard parentWizard) {
+ super("Template Selection"); //$NON-NLS-1$
+ setTitle(parentWizard.getListSelectionTitle());
+ setDescription(parentWizard.getListSelectionDescription());
+ this.labelText = parentWizard.getListSelectionLabel();
+ descriptionBrowser = new FormBrowser();
+ descriptionBrowser.setText(""); //$NON-NLS-1$
+ this.parentWizard = parentWizard;
+ }
+
+ public void createDescriptionIn(Composite composite) {
+ descriptionBrowser.createControl(composite);
+ Control c = descriptionBrowser.getControl();
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ gd.widthHint = 200;
+ c.setLayoutData(gd);
+ }
+
+ public String getLabel() {
+ return labelText;
+ }
+
+ public void setDescriptionText(String text) {
+ descriptionBrowser.setText(text);
+ }
+
+ public void setDescriptionEnabled(boolean enabled) {
+ Control control = descriptionBrowser.getControl();
+ if (control != null) {
+ control.setEnabled(enabled);
+ }
+ }
+
+ public void moveToNextPage() {
+ getContainer().showPage(getNextPage());
+ }
+
+ public void createControl(Composite parent) {
+ Composite container = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.verticalSpacing = 10;
+ container.setLayout(layout);
+ container.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ Label label = new Label(container, SWT.NONE);
+ label.setText(getLabel());
+ GridData gd = new GridData();
+ label.setLayoutData(gd);
+
+ SashForm sashForm = new SashForm(container, SWT.VERTICAL);
+ gd = new GridData(GridData.FILL_BOTH);
+ gd.widthHint = 300;
+ gd.minimumHeight = 230;
+ sashForm.setLayoutData(gd);
+
+ boolean useTree = parentWizard.showTemplatesInTreeView();
+
+ if (useTree)
+ {
+ wizardSelectionTreeViewer = new TreeViewer(sashForm, SWT.BORDER);
+ wizardSelectionTreeViewer.setContentProvider(parentWizard);
+ wizardSelectionTreeViewer.addDoubleClickListener(new IDoubleClickListener() {
+ public void doubleClick(DoubleClickEvent event) {
+ selectionChanged(new SelectionChangedEvent(wizardSelectionTreeViewer, wizardSelectionTreeViewer.getSelection()));
+ moveToNextPage();
+ }
+ });
+ wizardSelectionTreeViewer.setInput(templates);
+ wizardSelectionTreeViewer.addSelectionChangedListener(this);
+ wizardSelectionTreeViewer.getTree().setData("name", "templates"); //$NON-NLS-1$ //$NON-NLS-2$
+ wizardSelectionViewer = wizardSelectionTreeViewer;
+
+ }
+ else
+ {
+ wizardSelectionTableViewer = new TableViewer(sashForm, SWT.BORDER);
+ wizardSelectionTableViewer.setContentProvider(parentWizard);
+ wizardSelectionTableViewer.addDoubleClickListener(new IDoubleClickListener() {
+ public void doubleClick(DoubleClickEvent event) {
+ selectionChanged(new SelectionChangedEvent(wizardSelectionTableViewer, wizardSelectionTableViewer.getSelection()));
+ moveToNextPage();
+ }
+ });
+ wizardSelectionTableViewer.setInput(templates);
+ wizardSelectionTableViewer.addSelectionChangedListener(this);
+ wizardSelectionTableViewer.getTable().setData("name", "templates"); //$NON-NLS-1$ //$NON-NLS-2$
+ wizardSelectionViewer = wizardSelectionTableViewer;
+
+ }
+ wizardSelectionViewer.getControl().setData(".uid", "wizardSelectionViewer"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ createDescriptionIn(sashForm);
+ sashForm.setWeights(new int[] {75, 25});
+
+ Dialog.applyDialogFont(container);
+ setControl(container);
+ }
+
+ public void selectionChanged(SelectionChangedEvent event) {
+ setErrorMessage(null);
+ IStructuredSelection selection = (IStructuredSelection) event.getSelection();
+ Template currentWizardSelection = null;
+ Object selectedObject = null;
+ Iterator iter = selection.iterator();
+ if (iter.hasNext()) {
+ selectedObject = iter.next();
+ if (selectedObject instanceof Template)
+ currentWizardSelection = (Template) selectedObject;
+ }
+ if (currentWizardSelection == null) {
+ setDescriptionText(parentWizard.getDescription(selectedObject));
+ setSelectedNode(null);
+ return;
+ }
+ final Template finalSelection = currentWizardSelection;
+ setSelectedNode(new WizardNode(this, finalSelection));
+ setDescriptionText(parentWizard.getDescription(finalSelection));
+ getContainer().updateButtons();
+ }
+
+ public Template getTemplate() {
+ IWizardNode selectedNode = getSelectedNode();
+ if (selectedNode != null) {
+ return ((WizardNode)selectedNode).getTemplate();
+ }
+ return null;
+ }
+
+ public IWizardPage getNextPage(boolean shouldCreate) {
+ if (!shouldCreate) {
+ return super.getNextPage();
+ }
+ IWizardNode selectedNode = getSelectedNode();
+ selectedNode.dispose();
+ IWizard wizard = selectedNode.getWizard();
+ if (wizard == null) {
+ super.setSelectedNode(null);
+ return null;
+ }
+ if (shouldCreate) {
+ wizard.addPages();
+ }
+
+ return wizard.getStartingPage();
+ }
+
+ public boolean canFlipToNextPage() {
+ IStructuredSelection ssel = (IStructuredSelection)wizardSelectionViewer.getSelection();
+ return ssel != null && !ssel.isEmpty() && (ssel.getFirstElement() instanceof Template);
+ }
+
+ public void setVisible(boolean visible) {
+ if (visible) {
+ Template[] templates = parentWizard.getTemplates();
+ if (templatesHaveChanged(templates)) {
+ this.templates = templates;
+ wizardSelectionViewer.setInput(templates);
+ wizardSelectionViewer.refresh();
+ if (wizardSelectionTreeViewer != null) {
+ wizardSelectionTreeViewer.expandAll();
+ }
+
+ // select the first element by default
+ if (wizardSelectionTableViewer != null) {
+ wizardSelectionTableViewer.setSelection(new StructuredSelection(wizardSelectionTableViewer.getElementAt(0)), true);
+ }
+ if (wizardSelectionTreeViewer != null) {
+ wizardSelectionTreeViewer.setSelection(new StructuredSelection(wizardSelectionTreeViewer.getTree().getItem(0).getData()), true);
+ }
+ }
+ }
+ super.setVisible(visible);
+ if (visible) {
+ if (wizardSelectionTreeViewer != null) {
+ wizardSelectionTreeViewer.getTree().setFocus();
+ }
+ if (wizardSelectionTableViewer != null) {
+ wizardSelectionTableViewer.getTable().setFocus();
+ }
+ }
+ }
+
+ private boolean templatesHaveChanged(Template[] newTemplates) {
+ // doing this rather than an array compare because even when
+ // the templates are the same the objects are not. we really
+ // just need to compare the template info.
+ boolean changed = false;
+ if (newTemplates != null && templates != null && newTemplates.length == templates.length) {
+ for (int i=0; i*/ getDataInPreviousPages() {
+ return parentWizard.getAllDataInNonTemplatePages();
+ }
+
+ public IWizardDataPage[] getPagesAfterTemplatePages()
+ {
+ return parentWizard.getPagesAfterTemplatePages();
+ }
+
+ public IWizardDataPage[] getPagesAfterTemplateSelection() throws InstantiationException, IllegalAccessException, ClassNotFoundException
+ {
+ return parentWizard.getPagesAfterTemplateSelectionWithExtraPages(getTemplate());
+ }
+
+ public void adjustTemplateValues(Template template) {
+ parentWizard.adjustTemplateValues(template);
+ }
+
+}
diff --git a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/TemplatesChoiceWizard.java b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/TemplatesChoiceWizard.java
new file mode 100644
index 00000000000..0c1275e8b16
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/TemplatesChoiceWizard.java
@@ -0,0 +1,204 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.ui.templateengine;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchWizard;
+import org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation;
+
+import org.eclipse.cdt.core.templateengine.TemplateInfo;
+import org.eclipse.cdt.core.templateengine.process.ProcessFailureException;
+import org.eclipse.cdt.ui.CUIPlugin;
+
+
+/**
+ * A wizard intending to show a choice of templates (@see org.eclipse.cdt.core.templateenginee.Template)
+ * before switching to the pages driven by the chosen template should extend from TemplatesChoiceWizard.
+ * Alternatively, when a choice of templates needn't be shown, TemplateDrivenWizard is a better fit.
+ * (@see org.eclipse.cdt.ui.templateengine.TemplateDrivenWizard)
+ *
+ */
+public abstract class TemplatesChoiceWizard extends Wizard implements ITemplatesListProvider, IWorkbenchWizard {
+ private static final boolean DEBUG = false;
+ private TemplateListSelectionPage templateListSelectionPage;
+ protected IWorkbench workbench;
+ protected IStructuredSelection selection;
+
+ public final void addPages() {
+ IWizardPage[] pages = getPagesBeforeTemplatePages();
+ for(int i=0; i*/ pageList = new ArrayList/**/(Arrays.asList(pages));
+ IWizardDataPage[] extraPages = extraPagesProvider.createAdditionalPages(this, workbench, selection);
+ pageList.addAll(Arrays.asList(extraPages));
+ pages = (IWizardDataPage[]) pageList.toArray(new IWizardDataPage[pageList.size()]);
+ }
+ }
+ return pages;
+ }
+
+ IWizardDataPage[] getExtraCreatedPages(Template template) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
+ TemplateInfo templateInfo = template.getTemplateInfo();
+ String pagesProvider = templateInfo.getExtraPagesProvider();
+ if (pagesProvider != null) {
+ IPagesAfterTemplateSelectionProvider extraPagesProvider = (IPagesAfterTemplateSelectionProvider) Class.forName(pagesProvider).newInstance();
+ if (extraPagesProvider != null) {
+ List/**/ pageList = new ArrayList/**/();
+ IWizardDataPage[] extraPages = extraPagesProvider.getCreatedPages(this);
+ pageList.addAll(Arrays.asList(extraPages));
+ return (IWizardDataPage[]) pageList.toArray(new IWizardDataPage[pageList.size()]);
+ }
+ }
+ return new IWizardDataPage[0];
+ }
+
+ public boolean performFinish() {
+ IRunnableWithProgress op= new WorkspaceModifyDelegatingOperation(new IRunnableWithProgress() {
+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ finishPage(monitor);
+ }
+ });
+
+ try {
+ getContainer().run(true, false, op);
+ } catch (InvocationTargetException e) {
+ return false;
+ } catch (InterruptedException e) {
+ return false;
+ }
+ return true;
+
+ }
+
+ private boolean finishPage(IProgressMonitor monitor) {
+ IStatus[] statuses = templateListSelectionPage.getTemplate().executeTemplateProcesses(monitor, false);
+ if (statuses.length == 1 && statuses[0].getException() instanceof ProcessFailureException) {
+ TemplateEngineUIUtil.showError(statuses[0].getMessage(), statuses[0].getException());
+ return false;
+ } else {
+ if (DEBUG) {
+ String msg = Messages.getString("TemplatesChoiceWizard.3"); //$NON-NLS-1$
+ TemplateEngineUIUtil.showStatusDialog(msg, new MultiStatus(CUIPlugin.getPluginId(), IStatus.OK, statuses, msg, null));
+ }
+ return true;
+ }
+ }
+
+ /**
+ * Returns the Data in Non-Template Pages.
+ * @return Map,
+ */
+ public Map/**/ getAllDataInNonTemplatePages() {
+ Map/**/ map = new HashMap/**/();
+
+ IWizardDataPage[] pages = getPagesBeforeTemplatePages();
+ for(int i=0; i*/ pages = template.getUIPages();
+ for(Iterator i = template.getPagesOrderVector().iterator(); i.hasNext(); ){
+ String id = (String) i.next();
+ addPage((UIWizardPage) pages.get(id));
+ }
+
+ wpages = parentPage.getPagesAfterTemplatePages();
+ for(int i=0; i*/ valueStore = template.getValueStore();
+ finishPressed = true;
+ getContainer().updateButtons();
+ IWizardPage[] wpages = getPages();
+ for(int i=0; i 31) {
+ return new Status(IStatus.ERROR, CUIPlugin.getPluginId(), IStatus.ERROR, projectName + ERROR_SUFFIX_TOO_LONG, null);
+ }
+
+ for (int i = 1, l = baseName.length(); i < l; i++) {
+ char c = baseName.charAt(i);
+ if (!Character.isLetterOrDigit(c) && c != '_' && c != ' ') {
+ return new Status(IStatus.ERROR, CUIPlugin.getPluginId(), IStatus.ERROR, projectName + ERROR_SUFFIX, null);
+ }
+ }
+
+ return OK_STATUS;
+ }
+
+}
diff --git a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/pages/TemplateInputDialog.java b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/pages/TemplateInputDialog.java
new file mode 100644
index 00000000000..3622f2472a7
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/pages/TemplateInputDialog.java
@@ -0,0 +1,328 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.ui.templateengine.pages;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.MessageBox;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+import org.eclipse.cdt.core.templateengine.TemplateEngineUtil;
+
+
+/**
+ * Creates a JFace Dialog for the user to get name-value pair to perform
+ * SharedDefaults settings. The class takes care of user input validation.
+ */
+
+public class TemplateInputDialog extends Dialog {
+
+ /**
+ * Controls settings in the GUI
+ */
+ private static final String NAME = Messages.getString("TemplateInputDialog.0");// To be externalised //$NON-NLS-1$
+ private static final String VALUE = Messages.getString("TemplateInputDialog.1");// To be externalised //$NON-NLS-1$
+
+ /**
+ * Shell display messages for ADD and EDIT functionality
+ */
+
+ private static final String ADD_SHELL_MESSAGE = Messages.getString("TemplateInputDialog.2"); //$NON-NLS-1$
+ private static final String EDIT_SHELL_MESSAGE = Messages.getString("TemplateInputDialog.3"); //$NON-NLS-1$
+
+ /**
+ * Label Error Message
+ */
+ private Label errMessageLabel;
+ private String labelMessage = Messages.getString("TemplateInputDialog.4"); //$NON-NLS-1$
+
+ /**
+ * Text fields properties
+ */
+ private static final int TEXT_LIMIT = 100;
+
+ /**
+ * Dialog creation instances for display
+ */
+ private TemplatePreferencePage templatePreferencePage;
+ private TemplateInputDialog sharedDialog;
+ private Shell shell;
+ private Display display;
+
+ /**
+ * Dialog control instances
+ */
+ private Label valueLabel;
+ private Label nameLabel;
+ private Text valueText;
+ private Text nameText;
+ private Button oKButton;
+
+ /**
+ * Indentifies ADD/EDIT function
+ */
+ private int option;
+
+ /**
+ * Parent composite
+ */
+ private Composite parent;
+
+ /**
+ * JFace Dialog Constructor, constructs controls of the super class
+ *
+ * @param parentShell
+ */
+
+ protected TemplateInputDialog(Shell parentShell) {
+ super(parentShell);
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
+ */
+
+ protected void configureShell(Shell shell) {
+ super.configureShell(shell);
+ this.shell = shell;
+ shell.setBounds(420, 280, 300, 160);
+ display = shell.getDisplay();
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
+ */
+
+ protected Control createDialogArea(Composite parent) {
+
+ this.parent = parent;
+ Composite composite = (Composite) super.createDialogArea(parent);
+ GridLayout gridLayout = new GridLayout(2, false);
+ composite.setLayout(gridLayout);
+ createControls(composite);
+ return composite;
+ }
+
+ /**
+ * Opens the Dialog to accept user input for shared values.
+ *
+ * @param myDialog
+ * @param dataOption
+ */
+
+ public void open(TemplateInputDialog myDialog, int dataOption) {
+ this.option = dataOption;
+ sharedDialog = myDialog;
+ sharedDialog.create();
+ Button oK = getButton(IDialogConstants.OK_ID);
+ oK.setEnabled(false);
+ if (option == TemplatePreferencePage.OPTION_ADD) {
+
+ shell.setText(ADD_SHELL_MESSAGE);
+ } else if (option == TemplatePreferencePage.OPTION_EDIT) {
+
+ shell.setText(EDIT_SHELL_MESSAGE);
+ }
+
+ sharedDialog.open();
+ }
+
+ /**
+ * Creates control under the parent composite
+ *
+ * @param composite
+ */
+
+ private void createControls(Composite composite) {
+
+ // Name Label
+ nameLabel = new Label(composite, SWT.NONE);
+ nameLabel.setText(NAME);
+
+ // Name Text Field
+ nameText = new Text(composite, SWT.BORDER | SWT.SINGLE);
+ nameText.setTextLimit(TEXT_LIMIT);
+ GridData textData = new GridData(GridData.FILL_HORIZONTAL);
+ textData.horizontalSpan = GridData.BEGINNING;
+ nameText.setLayoutData(textData);
+ addTextListener(nameText);
+
+ // Value Label
+ valueLabel = new Label(composite, SWT.NONE);
+ valueLabel.setText(VALUE);
+
+ // Value Text Field
+ valueText = new Text(composite, SWT.BORDER | SWT.SINGLE);
+ valueText.setTextLimit(TEXT_LIMIT);
+ GridData valueData = new GridData(GridData.FILL_HORIZONTAL);
+ valueData.horizontalSpan = GridData.BEGINNING;
+ valueData.verticalSpan = 5;
+ valueText.setLayoutData(valueData);
+ addTextListener(valueText);
+
+ // Label for Error Message
+ Color color = display.getSystemColor(SWT.COLOR_RED); // Get a red Color
+ Composite labelComposite = new Composite(parent, SWT.NONE);
+ labelComposite.setLayout(new GridLayout());
+ labelComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ errMessageLabel = new Label(labelComposite, SWT.COLOR_DARK_RED);
+ errMessageLabel.setForeground(color);
+ errMessageLabel.setText(labelMessage);
+ errMessageLabel.setVisible(false);
+
+ if (option == TemplatePreferencePage.OPTION_EDIT) {
+ nameLabel.setEnabled(false);
+ nameText.setEnabled(false);
+
+ String name = TemplatePreferencePage.getSelectedItemNameFromTable();
+ if (name != null) {
+ nameText.setText(name);
+ }
+ }
+ }
+
+ /**
+ * Adds Modify listeners to the Text fields
+ *
+ * @param aText
+ */
+ public void addTextListener(final Text aText) {
+
+ ModifyListener mListener = new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ String nameField = aText.getText();
+ textChanged(nameField);
+ }
+ };
+
+ aText.addModifyListener(mListener);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.dialogs.Dialog#okPressed() This method is
+ * overridden to perform custom events on OK button.
+ */
+
+ protected void okPressed() {
+ if (option == TemplatePreferencePage.OPTION_ADD) {
+ String name = nameText.getText();
+ String value = valueText.getText();
+
+ if (name != TemplatePreferencePage.Blank && value != TemplatePreferencePage.Blank) {
+ templatePreferencePage = new TemplatePreferencePage(name, value);
+ templatePreferencePage.addNewDataIntoTable();
+
+ if (TemplatePreferencePage.isDup) {
+ nameText.setText(TemplatePreferencePage.Blank);
+ nameText.setFocus();
+ TemplatePreferencePage.isDup = false;
+ } else if (!TemplatePreferencePage.isDup) {
+ nameText.setFocus();
+ sharedDialog.close();
+ }
+ }
+ }
+
+ if (option == TemplatePreferencePage.OPTION_EDIT) {
+ String name = nameText.getText();
+ String value = valueText.getText();
+
+ if (!value.equals(TemplatePreferencePage.Blank)) {
+ templatePreferencePage = new TemplatePreferencePage(name, value);
+ templatePreferencePage.updateDataInTheTable();
+ }
+ sharedDialog.close();
+ }
+ }
+
+ /**
+ * Pops up Message dialog if duplicate entry is found and returns
+ * confirmation.
+ *
+ * @return result
+ */
+
+ public int popDuplicate() {
+
+ MessageBox mBox = new MessageBox(new Shell(), SWT.ICON_INFORMATION);
+ mBox.setText(TemplatePreferencePage.Message);
+ mBox.setMessage(TemplatePreferencePage.DuplicateEntry);
+ int result = mBox.open();
+ return result;
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.dialogs.Dialog#cancelPressed()
+ */
+ protected void cancelPressed() {
+
+ sharedDialog.close();
+ }
+
+ /**
+ *
+ * Implements the modify listener for the text field Name and Value fields.
+ *
+ * @param textField
+ */
+
+ private void textChanged(String textField) {
+
+ errMessageLabel.setVisible(false);
+ try {
+
+ // Diable OK button if special characters are entererd.
+ if (textField.matches(TemplatePreferencePage.Blank)) {
+
+ oKButton = getButton(IDialogConstants.OK_ID);
+ errMessageLabel.setText(labelMessage);
+ errMessageLabel.setVisible(true);
+ oKButton.setEnabled(false);
+
+ }
+
+ // Enable OK button if and only if data is entered.
+ else if (!nameText.getText().equals(TemplatePreferencePage.Blank)
+ && !valueText.getText().equals(TemplatePreferencePage.Blank)) {
+
+ oKButton = getButton(IDialogConstants.OK_ID);
+ oKButton.setEnabled(true);
+ }
+
+ } catch (Exception exp) {
+ TemplateEngineUtil.log(exp);
+ }
+
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/pages/TemplatePreferencePage.java b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/pages/TemplatePreferencePage.java
new file mode 100644
index 00000000000..730bea8e8aa
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/pages/TemplatePreferencePage.java
@@ -0,0 +1,589 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.ui.templateengine.pages;
+
+import java.util.List;
+
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.jface.viewers.ColumnLayoutData;
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.TableLayout;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.MessageBox;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.eclipse.ui.PlatformUI;
+import org.w3c.dom.Element;
+
+import org.eclipse.cdt.core.templateengine.SharedDefaults;
+import org.eclipse.cdt.core.templateengine.TemplateEngine;
+import org.eclipse.cdt.core.templateengine.TemplateEngineHelper;
+import org.eclipse.cdt.core.templateengine.TemplateEngineUtil;
+import org.eclipse.cdt.ui.CUIPlugin;
+
+
+/**
+ * This class represents a preference page that is contributed to the
+ * Preferences dialog. By Provided GUI for SharedDefaults settings for the
+ * Templates present in the Template Engine
+ */
+
+public class TemplatePreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
+
+ /**
+ * Preference Page buttons
+ */
+
+ private static final String EditButton = " Edit... "; //$NON-NLS-1$
+ private static final String DeleteButton = " Remove "; //$NON-NLS-1$
+ private static final String PageDescription = Messages.getString("TemplatePreferencePage.0");//$NON-NLS-1$
+ public static final String Blank = "";//$NON-NLS-1$
+
+ /**
+ * Validation Messages
+ */
+ public static final String Message = Messages.getString("TemplatePreferencePage.1");//$NON-NLS-1$
+ protected static final String DuplicateEntry = Messages.getString("TemplatePreferencePage.2");//$NON-NLS-1$
+ private static final String DeleteValidator = Messages.getString("TemplatePreferencePage.3");//$NON-NLS-1$
+ private static final String DeleteShellMessage = Messages.getString("TemplatePreferencePage.4");//$NON-NLS-1$
+
+ /**
+ * Button ToolTips
+ */
+ private static final String TableToolTip = Messages.getString("TemplatePreferencePage.5");//$NON-NLS-1$
+ private static final String EditToolTip = Messages.getString("TemplatePreferencePage.6");//$NON-NLS-1$
+ private static final String DeleteToolTip = Messages.getString("TemplatePreferencePage.7");//$NON-NLS-1$
+
+ /**
+ * Class instances
+ */
+ private static TemplateInputDialog inputDialog;
+ private static SharedDefaults sharedDefaults = SharedDefaults.getInstance();
+
+ /**
+ * Table Attributes
+ */
+ private int columnWidth = 100;
+ private int columnWeight = 50;
+ private String columnNames[];
+ private static List/**/ sharedElementList;
+ private int attrListSize;
+
+ private ColumnLayoutData columnLayouts[] = { new ColumnWeightData(columnWeight, columnWidth),
+ new ColumnWeightData(columnWeight, columnWidth) };
+
+ /**
+ * InfoHelp for SharedDefault
+ */
+ private String pageID;
+ private String SharedContextHelpID = "shared_defaults_help";//$NON-NLS-1$
+
+ /**
+ * Button instance for ADD/EDIT/DELETE
+ */
+
+ private Button editButton;
+ private Button deleteButton;
+
+ /**
+ * Checks for row(s) deletion
+ */
+ private static boolean isDeleted;
+
+ /**
+ * Checks for redundant data
+ */
+ private boolean isRedundant;
+
+ /**
+ * Takes isRedundant reference to get reflected in different class scope See
+ * TemplateInputDialog class
+ */
+ public static boolean isDup;
+ private static String delItemNames[] = null;
+ private static Table table;
+
+ /**
+ * Add/Edit option values
+ */
+ protected static final int OPTION_ADD = 0;
+ protected static final int OPTION_EDIT = 1;
+
+ /**
+ * Dialog input values arriving from TemplateInputDialog class
+ */
+ private String name;
+ private String value;
+
+ /**
+ * Constructor to initialize defaults
+ */
+
+ public TemplatePreferencePage() {
+
+ noDefaultAndApplyButton();
+ initializeDefaults();
+ }
+
+ /**
+ * Sets the values of the Message Dialog
+ *
+ * @param aName
+ * @param aValue
+ */
+ public TemplatePreferencePage(String aName, String aValue) {
+ this.name = aName;
+ this.value = aValue;
+ }
+
+ /**
+ * Sets default settings and gathers attributes from the XML for Table
+ * properties
+ */
+
+ private void initializeDefaults() {
+ columnNames = new String[] { TemplateEngineHelper.ID, TemplateEngineHelper.VALUE };
+ // Setting InfoPop help (plugin-id+ContextID).
+ pageID = CUIPlugin.getPluginId() + "." + //$NON-NLS-1$
+ SharedContextHelpID;
+
+ setTableAttributes();
+
+ }
+
+ /**
+ * Creates controls on the Preference Page Adds the created Table and Button
+ * composite to the parent composite.
+ *
+ * @param parent
+ * @return subComposite
+ */
+
+ protected Control createContents(Composite parent) {
+
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.marginHeight = 0;
+ layout.marginWidth = 0;
+ composite.setLayout(layout);
+
+ Label pageLabel = new Label(composite, SWT.NONE);
+ pageLabel.setText(PageDescription);
+
+ Composite subComposite = new Composite(parent, SWT.NONE);
+ GridLayout subLayout = new GridLayout(2, false);
+ GridData gridData = new GridData(GridData.FILL_BOTH);
+ subComposite.setLayout(subLayout);
+ subComposite.setLayoutData(gridData);
+
+ addFirstSection(subComposite);
+ addSecondSection(subComposite);
+
+ // Info help for SharedDefault is displayed when Functional Key (F1) is
+ // triggered.
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(super.getControl(), pageID);
+ return subComposite;
+
+ }
+
+ /**
+ * Adds table into the first composite present under parent Updates the
+ * Table with backend persistence data.
+ *
+ * @param parent
+ */
+
+ private void addFirstSection(Composite parent) {
+ createTable(parent);
+ setTableAttributes();
+ addXMLDataIntoTable();
+ }
+
+ /**
+ * Creates second composite for buttons present under the parent
+ *
+ * @param parent
+ */
+
+ private void addSecondSection(Composite parent) {
+ Composite composite = createDefaultComposite(parent);
+ addButtonControls(composite);
+ }
+
+ /**
+ * Creates default composite area for the Buttons
+ *
+ * @param parent
+ * @return composite
+ */
+
+ private Composite createDefaultComposite(Composite parent) {
+
+ Composite composite = new Composite(parent, SWT.NULL);
+ FillLayout layout = new FillLayout(SWT.VERTICAL);
+ layout.spacing = 5;
+ layout.marginWidth = 0;
+ layout.marginHeight = 0;
+ composite.setLayout(layout);
+
+ GridData gridData = new GridData();
+ gridData.verticalAlignment = GridData.BEGINNING;
+ composite.setLayoutData(gridData);
+
+ return composite;
+
+ }
+
+ /**
+ * Creates Table with XML properties as its settings
+ *
+ * @param composite
+ */
+
+ private void createTable(Composite composite) {
+
+ table = new Table(composite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER
+ | SWT.NO_REDRAW_RESIZE);
+
+ GridData gridData = new GridData(GridData.FILL_BOTH);
+ gridData.heightHint = convertHeightInCharsToPixels(10);
+ gridData.widthHint = convertWidthInCharsToPixels(10);
+
+ table.setLayoutData(gridData);
+ TableLayout layout = new TableLayout();
+ table.setLayout(layout);
+ table.setLinesVisible(true);
+ table.setHeaderVisible(true);
+ table.setToolTipText(TableToolTip);
+
+ // The attribute size becomes zero when no data
+ // remains in the table. To avoid fault creation of
+ // the table the attribute size to required columns
+ // in the table.
+ if (attrListSize == 0) {
+ attrListSize = 2;
+ }
+
+ for (int nCols = 0; nCols < attrListSize; nCols++) {
+ layout.addColumnData(columnLayouts[nCols]);
+ TableColumn tColumn = new TableColumn(table, SWT.LEFT, nCols);
+ tColumn.setWidth(columnWidth);
+ tColumn.setText(columnNames[nCols]);
+ }
+
+ addTableListener();
+ }
+
+ /**
+ * Table listener added to enable EDIT/DELETE functionality only when table
+ * listenes to an event.
+ */
+ private void addTableListener() {
+
+ SelectionListener sListener = new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ boolean isSelected = table.isSelected(table.getSelectionIndex());
+ int selectionCount = table.getSelectionCount();
+
+ // Enable EDIT/DELETE button when row(s) get selected
+ if (isSelected) {
+ editButton.setEnabled(true);
+ deleteButton.setEnabled(true);
+ }
+
+ // disable EDIT button if more than one row is selected
+ if (selectionCount > 1)
+ editButton.setEnabled(false);
+ }
+ };
+ table.addSelectionListener(sListener);
+ }
+
+ /**
+ * Adds XML backend data into the table Supports for pesistency.
+ */
+
+ private void addXMLDataIntoTable() {
+ for (int i = 0, l = sharedElementList.size(); i < l; i++) {
+ Element xmlElement = (Element) sharedElementList.get(i);
+ String name = xmlElement.getAttribute(TemplateEngineHelper.ID);
+ String value = xmlElement.getAttribute(TemplateEngineHelper.VALUE);
+
+ if (name.equals(Blank) && value.equals(Blank))
+ return;
+
+ String backEndData[] = new String[] { name, value };
+ TableItem backEndItem = new TableItem(table, SWT.NONE);
+
+ for (int data = 0; data < backEndData.length; data++) {
+ if (backEndData[data] != null)
+ backEndItem.setText(data, backEndData[data]);
+ }
+ }
+ }
+
+ /**
+ * Creates button controls on the first composite present under parent
+ * composite. Its aligned at rightmost end of Table and top of the second
+ * composite.
+ *
+ * @param composite
+ */
+
+ private void addButtonControls(Composite composite) {
+
+ editButton = new Button(composite, SWT.PUSH);
+ editButton.setText(EditButton);
+ editButton.setEnabled(false);
+ editButton.setToolTipText(EditToolTip);
+ addButtonListener(editButton);
+
+ deleteButton = new Button(composite, SWT.PUSH);
+ deleteButton.setText(DeleteButton);
+ deleteButton.setEnabled(false);
+ deleteButton.setToolTipText(DeleteToolTip);
+ addButtonListener(deleteButton);
+
+ }
+
+ /**
+ * Constructs button listeners to trigger specific functionality
+ *
+ * @param button
+ */
+ public void addButtonListener(final Button button) {
+
+ inputDialog = new TemplateInputDialog(getShell());
+ SelectionListener listener = new SelectionAdapter() {
+
+ public void widgetSelected(SelectionEvent e) {
+ if (e.getSource().equals(editButton)) {
+ String editItemString = getSelectedItemNameFromTable();
+ if (editItemString != null) {
+ if (editItemString != Blank) {
+ inputDialog.open(inputDialog, OPTION_EDIT);
+ }
+ }
+ }
+
+ if (e.getSource().equals(deleteButton)) {
+ deleteRow();
+ editButton.setEnabled(false);
+ deleteButton.setEnabled(false);
+ }
+ }
+ };
+ button.addSelectionListener(listener);
+ }
+
+ /**
+ * Adding new data into the table and adds the same data to the backend XML
+ * Checks for duplicate entries and null values
+ */
+
+ public void addNewDataIntoTable() {
+
+ String addData[] = new String[] { name, value };
+ if (!isDeleted) {
+ TableItem duplicateItems[] = table.getItems();
+ TableItem duplicateItem = null;
+
+ for (int nItems = 0; nItems < duplicateItems.length; nItems++) {
+ duplicateItem = duplicateItems[nItems];
+ String duplicateString = duplicateItem.getText();
+
+ if (duplicateString.equals(name)) {
+ int result = inputDialog.popDuplicate();
+ if (result == SWT.OK) {
+ isRedundant = true;
+ isDup = isRedundant;
+ break;
+ }
+ }
+ }
+
+ // Check if not redundant
+ if (!isRedundant) {
+ TableItem tableItem = new TableItem(table, SWT.NONE);
+
+ for (int data = 0; data < addData.length; data++) {
+ tableItem.setText(data, addData[data]);
+ }
+
+ isRedundant = false;
+ }
+ }
+
+ sharedDefaults.addToBackEndStorage(name, value);
+ }
+
+ /**
+ * Gets the size of the Attributes of an Element of XML file
+ *
+ * @param sharedElementList
+ * @return attrListSize
+ */
+ private int getAttributeSize() {
+ try {
+ int listSize = sharedElementList.size();
+ int i = 0;
+ while (i < listSize) {
+ Element xmlElement = (Element) sharedElementList.get(i++);
+ attrListSize = xmlElement.getAttributes().getLength();
+ }
+ } catch (Exception exp) {
+ TemplateEngineUtil.log(exp);
+ }
+ return attrListSize;
+ }
+
+ /**
+ * Setting the table attributes with the XML properties Sets XML-document
+ * Element List as the number of table rows and XML-document Attribute List
+ * as the number of table columns
+ */
+
+ private void setTableAttributes() {
+
+ try {
+ SharedDefaults sharedTemp = new SharedDefaults();
+ sharedElementList = TemplateEngine.getChildrenOfElement(sharedTemp.document.getDocumentElement());
+ attrListSize = getAttributeSize();
+ sharedDefaults.putAll(sharedTemp.getSharedDefaultsMap());
+
+ } catch (Exception exp) {
+ TemplateEngineUtil.log(exp);
+ }
+ }
+
+ public void init(IWorkbench workbench) {
+
+ }
+
+ /**
+ * Updating data with the changed value for a given ID in the table.
+ */
+
+ public void updateDataInTheTable() {
+
+ try {
+ int selectedItemIndex = table.getSelectionIndex();
+ TableItem selectedItem = table.getItem(selectedItemIndex);
+ String updateString[] = new String[] { name, value };
+ selectedItem.setText(updateString);
+ sharedDefaults.updateToBackEndStorage(name, value);
+ } catch (Exception exp) {
+ TemplateEngineUtil.log(exp);
+ }
+ }
+
+ /**
+ * Gives the item for the selected row in the table
+ *
+ * @return selectedItemName
+ */
+
+ public static String getSelectedItemNameFromTable() {
+
+ String selectedItemName = null;
+ int selectedItemIndex = 0;
+
+ try {
+ selectedItemIndex = table.getSelectionIndex();
+ }
+
+ catch (Exception exp) {
+ TemplateEngineUtil.log(exp);
+ }
+
+ TableItem selectedItem = table.getItem(selectedItemIndex);
+ selectedItemName = selectedItem.getText();
+ return selectedItemName;
+
+ }
+
+ /**
+ * Deletes the data for the specified row Data also gets deleted at the
+ * backend with Key-name as an identifier.
+ */
+ private void deleteRow() {
+
+ int result = 0;
+ String nonEmptyItemString = getSelectedItemNameFromTable();
+
+ if (nonEmptyItemString != null)
+ result = confirmdeleteContents(nonEmptyItemString);
+
+ if (result == SWT.OK) {
+ int itemSelected[] = table.getSelectionIndices();
+ table.remove(itemSelected);
+ }
+
+ else if (result == SWT.CANCEL)
+ isDeleted = false;
+
+ if (delItemNames != null) {
+ sharedDefaults.deleteBackEndStorage(delItemNames);
+ }
+
+ }
+
+ /**
+ * Sets confirmation for the data deletion at the fronend and backend
+ *
+ * @param selectedItems
+ * @return result
+ */
+
+ private int confirmdeleteContents(String selectedItems) {
+
+ int result = 0;
+ TableItem deleteItems[] = null;
+
+ if (selectedItems != Blank) {
+
+ deleteItems = table.getSelection();
+ delItemNames = new String[deleteItems.length];
+
+ for (int nDel = 0; nDel < deleteItems.length; nDel++) {
+
+ TableItem item = deleteItems[nDel];
+ delItemNames[nDel] = item.getText();
+
+ }
+
+ MessageBox mBox = new MessageBox(new Shell(), SWT.ICON_QUESTION | SWT.OK | SWT.CANCEL);
+ mBox.setText(DeleteShellMessage);
+ mBox.setMessage(DeleteValidator);
+ result = mBox.open();
+
+ }
+
+ return result;
+
+ }
+
+}
+
diff --git a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/pages/UIPage.java b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/pages/UIPage.java
new file mode 100644
index 00000000000..4bdc6540f12
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/pages/UIPage.java
@@ -0,0 +1,158 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.ui.templateengine.pages;
+
+import java.net.URL;
+import java.util.Map;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.dialogs.DialogPage;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.PlatformUI;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.templateengine.TemplateEngineUtil;
+import org.eclipse.cdt.ui.CUIPlugin;
+import org.eclipse.cdt.ui.templateengine.uitree.UIElement;
+import org.eclipse.cdt.ui.templateengine.uitree.uiwidgets.UIComposite;
+
+
+/**
+ *
+ * The UIPage extends DialogPage, it implements the createControl() abstract
+ * method. The UIPage is the base class for UIWizardPage. The UIPage contains a
+ * UIComposite, which extends a SWT composite. The SWT widgets are added to
+ * UIComposite.
+ */
+
+public abstract class UIPage extends DialogPage {
+
+ /**
+ * The Composite belonging to this page. The SWT widgets are added to this Composite. UIComposite instance is the top level control of this page. This top level control is initialized in createControl method.
+ */
+ private UIComposite uiComposite;
+
+ /**
+ * resources ID which will be displayed as F1 help in Title area.
+ */
+ protected static String RESOURCES_ID = CCorePlugin.PLUGIN_ID + ".resources"; //$NON-NLS-1$
+
+ /**
+ * The UIElement (group), to which this page corresponds. Every UIElement group corresponds to a UIPage. The children of this goup are UIElement's (SWT widgets). Which are added to the UIComposite.
+ */
+ private UIElement uiElement;
+
+ /**
+ * ValueStore for this instance of Template.
+ */
+ private Map/**/ valueStore;
+
+ /**
+ * Title set for this WizardPage.
+ */
+ protected String title;
+
+ /**
+ * Property Group Id corresponding this page
+ */
+ protected String pageId;
+
+ private ImageDescriptor imageDescriptor;
+
+ /**
+ *
+ * @param name
+ * Name of this UIPage.
+ * @param element
+ * The group UIElement.
+ */
+ protected UIPage(String name, UIElement element, Map/**/ valueStore) {
+ super(name);
+ setTitle(name);
+ setDescription((String) element.getAttributes().get(UIElement.DESCRIPTION));
+ try {
+ String imageLoc = (String) element.getAttributes().get(UIElement.IMAGELOCATION);
+ if (imageLoc != null) {
+ URL url = FileLocator.toFileURL(FileLocator.find(CCorePlugin.getDefault().getBundle(), new Path(imageLoc), null));
+ imageDescriptor = ImageDescriptor.createFromURL(url);
+ }
+ } catch (Exception e) {
+ TemplateEngineUtil.log(e);
+ }
+
+ super.setImageDescriptor(imageDescriptor);
+ //TODO: Fix the imagedescriptor later.
+// setImageDescriptor(TemplateEnginePlugin.imageDescriptorFromPlugin(TemplateEnginePlugin.getDefault().getWizardIconPluginID(), TemplateEnginePlugin.getDefault().getWizardIconFile()));
+
+ title = name;
+ uiElement = element;
+ this.valueStore = valueStore;
+ //TODO: Check the from which plugin the PLUGIN_ID comes from i.e. from CCorePlugin or CUIPlugin
+ pageId = CUIPlugin.getPluginId() + "." + //$NON-NLS-1$
+ (uiElement.getAttributes()).get(UIElement.ID);
+ }
+
+ /**
+ * Creates the top level control for this dialog page under the given parent
+ * composite.
+ *
+ * @param parent
+ * the parent composite
+ */
+ public void createControl(Composite parent) {
+ initializeDialogUnits(parent);
+ uiComposite = new UIComposite(parent, uiElement, valueStore);
+
+ // set the focus so that InfoPop is displayed when F1 is Pressed.
+ uiComposite.setFocus();
+
+ setControl(uiComposite);
+
+ // Setting InfoPop help context ID(plugin-id+ContextID).
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(super.getControl(), pageId);
+
+ }
+
+ /**
+ * The data contained in the Input elements (SWT widgets), on this page is
+ * extracted and put into an HashMap. The same is returned.
+ *
+ * @return HashMap. The data contained in the widgets on this page.
+ */
+ public Map/**/ getPageData() {
+ return uiComposite.getPageData();
+ }
+
+ /**
+ * This is an overridden definition for the same method in DialogPage. The
+ * top level control is returned.
+ *
+ * @return Control.
+ */
+ public Control getControl() {
+ return uiComposite;
+ }
+
+ // This method is provided for unit tesing the UIComposite instance.
+ /**
+ *
+ * This returns UICompostie as UIComposite instance. Unlike the getControl.
+ *
+ * @return UIComposite, used in this page.
+ */
+ public UIComposite getComposite() {
+ return uiComposite;
+ }
+
+}
diff --git a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/pages/UIPagesProvider.java b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/pages/UIPagesProvider.java
new file mode 100644
index 00000000000..605c0b25c2b
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/pages/UIPagesProvider.java
@@ -0,0 +1,170 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.ui.templateengine.pages;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.cdt.core.templateengine.TemplateEngineUtil;
+import org.eclipse.cdt.ui.templateengine.SimpleElementException;
+import org.eclipse.cdt.ui.templateengine.uitree.InputUIElement;
+import org.eclipse.cdt.ui.templateengine.uitree.SimpleUIElementGroup;
+import org.eclipse.cdt.ui.templateengine.uitree.UIElement;
+
+
+/**
+ * The UIPagesProvider creates a Map of UIPages. The Map will have ID as key,
+ * UIPage as value. The sequence of call to get Map of UIPages. 1.
+ * clearOrderVector() for all PropertyGroup Elements. 2. getUIPages(...)
+ *
+ */
+public class UIPagesProvider {
+
+ /**
+ * maintains the Page display order.
+ */
+ private List/**/ orderVector;
+
+
+ public UIPagesProvider() {
+ orderVector = new ArrayList();
+ }
+
+ /**
+ * after getting this clear the Vector.
+ *
+ * @return Vector
+ */
+ public List/**/ getOrderVector() {
+ return orderVector;
+ }
+
+ /**
+ * re-initialize the Vector.
+ */
+ public void clearOrderVector() {
+ orderVector = new ArrayList/**/();
+ }
+
+ /**
+ * This class has methods to return an HashMap of UIPages. The UIPages will
+ * correspond to UIElement group passed as parameter to this method. For a
+ * group UIElement, the children count is taken. An array of UIPage for the
+ * count is created. The same is initialized with UIPages.
+ *
+ * @param uiElement
+ * UIElement group root element. Which can be converted to a
+ * UIPage.
+ * @param valueStore
+ * @return HashMap, UIPages corresonding to param aUIElement.
+ */
+ public Map/**/ getWizardUIPages(UIElement uiElement, Map/**/ valueStore) {
+ int childCount = 0;
+
+ try {
+ childCount = uiElement.getChildCount();
+ } catch (SimpleElementException e) {
+ TemplateEngineUtil.log(e);
+ }
+
+ // HashMap of UIPages
+ HashMap/**/ pageMap = new HashMap/**/();
+
+ // If uiElement contains other group elements as children.
+ if (hasChildUIGroupElement(uiElement)) {
+
+ for (int i = 0; i < childCount; i++) {
+ try {
+ pageMap.putAll(getWizardUIPages(uiElement.getChild(i), valueStore)); // recursion
+ } catch (SimpleElementException e) {
+ TemplateEngineUtil.log(e);
+ }
+ }
+ }
+ else {
+ if ((hasChildUIElement(uiElement))) {
+ String title = (String) uiElement.getAttributes().get(UIElement.TITLE);
+ String description = (String) (uiElement.getAttributes()).get(UIElement.DESCRIPTION);
+ UIWizardPage uiPage = new UIWizardPage(title, description, uiElement, valueStore);
+
+ pageMap.put((uiElement.getAttributes()).get(UIElement.ID), uiPage);
+ addToOrderVector((String) (uiElement.getAttributes()).get(UIElement.ID));
+ }
+ }
+ return pageMap;
+ }
+
+ /**
+ * whether the given (node in UIElementTree) UIElement contains children of
+ * group type.
+ *
+ * @param parent
+ * @return boolean, true if it does, false otherwise.
+ */
+ public boolean hasChildUIGroupElement(UIElement parent) {
+ boolean retVal = false;
+ try {
+ if (parent.getChildCount() > 0) {
+ for (int i = 0; i < parent.getChildCount(); i++) {
+ if (parent.getChild(i) instanceof SimpleUIElementGroup) {
+ retVal = true;
+ break;
+ }
+ }
+ }
+ } catch (SimpleElementException see) {
+ retVal = false;
+ }
+ return retVal;
+ }
+
+ /**
+ * whether the given (node in UIElementTree) UIElement contains children of
+ * UIElement type.
+ *
+ * @param parent
+ * @return boolean, true if it does, false otherwise.
+ */
+ public boolean hasChildUIElement(UIElement parent) {
+ boolean retVal = false;
+ try {
+ if (parent.getChildCount() > 0) {
+ for (int i = 0; i < parent.getChildCount(); i++) {
+ if (parent.getChild(i) instanceof InputUIElement) {
+ retVal = true;
+ break;
+ }
+ }
+ }
+ } catch (SimpleElementException see) {
+ retVal = false;
+ }
+ return retVal;
+ }
+
+ /**
+ * If the order vector contains the page id return, do not add it to order
+ * vector. HashMap will not allow duplicate keys.
+ *
+ * @param pageId
+ */
+ private void addToOrderVector(String pageId) {
+ String containerIds = null;
+ for (int i = 0; i < orderVector.size(); i++) {
+ containerIds = (String) orderVector.get(i);
+ if (containerIds.equalsIgnoreCase(pageId))
+ return;
+ }
+ orderVector.add(pageId);
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/pages/UIWizardPage.java b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/pages/UIWizardPage.java
new file mode 100644
index 00000000000..6dd79be032e
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/pages/UIWizardPage.java
@@ -0,0 +1,330 @@
+/*******************************************************************************
+ * 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.ui.templateengine.pages;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.wizard.IWizard;
+import org.eclipse.jface.wizard.IWizardContainer;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+
+import org.eclipse.cdt.ui.templateengine.event.PatternEvent;
+import org.eclipse.cdt.ui.templateengine.event.PatternEventListener;
+import org.eclipse.cdt.ui.templateengine.uitree.UIElement;
+
+
+/**
+ * UIWizardPage provides implementation IWizardPage. UIWizardPage is a
+ * WizardPage.
+ */
+
+public class UIWizardPage extends UIPage implements IWizardPage, PatternEventListener {
+
+ /**
+ * This map will contain reference to the source widgets, which has generated the
+ * SWT events. If this map contains an event source, the error message will not be cleared.
+ */
+ HashMap/*