aboutsummaryrefslogtreecommitdiffstats
path: root/tools/eclipse/config_wizard/src/org/chibios
diff options
context:
space:
mode:
Diffstat (limited to 'tools/eclipse/config_wizard/src/org/chibios')
-rw-r--r--tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/handlers/CheckDescription.java55
-rw-r--r--tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/handlers/GenerateFiles.java131
-rw-r--r--tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/process/ApplicationGeneratorProcessRunner.java37
-rw-r--r--tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/utils/TemplateEngine.java260
-rw-r--r--tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/utils/TemplateException.java30
-rw-r--r--tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/wizards/ConfigurationNewWizard.java185
-rw-r--r--tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/wizards/ConfigurationNewWizardPage.java264
-rw-r--r--tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/wizards/NewApplicationProjectWizard.java158
-rw-r--r--tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/wizards/NewApplicationProjectWizardPage.java312
9 files changed, 0 insertions, 1432 deletions
diff --git a/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/handlers/CheckDescription.java b/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/handlers/CheckDescription.java
deleted file mode 100644
index 0d7e7e292..000000000
--- a/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/handlers/CheckDescription.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
- 2011,2012 Giovanni Di Sirio.
-
- This file is part of ChibiOS/RT.
-
- ChibiOS/RT is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- ChibiOS/RT is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-package org.chibios.tools.eclipse.config.handlers;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.handlers.HandlerUtil;
-import org.eclipse.jface.dialogs.MessageDialog;
-
-/**
- * Our sample handler extends AbstractHandler, an IHandler base class.
- * @see org.eclipse.core.commands.IHandler
- * @see org.eclipse.core.commands.AbstractHandler
- */
-public class CheckDescription extends AbstractHandler {
-
- /**
- * The constructor.
- */
- public CheckDescription() {
- }
-
- /**
- * the command has been executed, so extract extract the needed information
- * from the application context.
- */
- public Object execute(ExecutionEvent event) throws ExecutionException {
- IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
- MessageDialog.openInformation(
- window.getShell(),
- "ChibiOS-RT_Configuration_Support",
- "Hello, Eclipse world");
- return null;
- }
-}
diff --git a/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/handlers/GenerateFiles.java b/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/handlers/GenerateFiles.java
deleted file mode 100644
index aad5adfce..000000000
--- a/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/handlers/GenerateFiles.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
- 2011,2012 Giovanni Di Sirio.
-
- This file is part of ChibiOS/RT.
-
- ChibiOS/RT is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- ChibiOS/RT is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package org.chibios.tools.eclipse.config.handlers;
-
-import java.io.File;
-import java.io.IOException;
-
-import org.chibios.tools.eclipse.config.utils.TemplateEngine;
-import org.chibios.tools.eclipse.config.utils.TemplateException;
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.resources.IContainer;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-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.ui.IWorkbenchWindow;
-import org.eclipse.ui.handlers.HandlerUtil;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.jdom2.Document;
-import org.jdom2.Element;
-import org.jdom2.JDOMException;
-import org.jdom2.input.SAXBuilder;
-import org.osgi.framework.Bundle;
-
-import config_wizard.Activator;
-
-/**
- * Our sample handler extends AbstractHandler, an IHandler base class.
- *
- * @see org.eclipse.core.commands.IHandler
- * @see org.eclipse.core.commands.AbstractHandler
- */
-public class GenerateFiles extends AbstractHandler {
-
- /**
- * The constructor.
- */
- public GenerateFiles() {
- }
-
- /**
- * the command has been executed, so extract extract the needed information
- * from the application context.
- */
- public Object execute(ExecutionEvent event) throws ExecutionException {
-
- IWorkbenchWindow window = HandlerUtil
- .getActiveWorkbenchWindowChecked(event);
- ISelection selection = window.getSelectionService().getSelection();
- if (selection instanceof IStructuredSelection) {
-
- /* Retrieves the full path of the configuration file. */
- IPath cfgfilepath = ((IFile)((IStructuredSelection)selection)
- .getFirstElement()).getLocation();
-
- /* DOM tree creation. */
- SAXBuilder builder = new SAXBuilder();
- Document document;
- try {
- document = builder.build(cfgfilepath.toFile());
- } catch (JDOMException e) {
- return null;
- } catch (IOException e) {
- return null;
- }
-
- /* Retrieving configuration settings info.*/
- Element settings = document.getRootElement().getChild("configuration_settings");
- String templates_path = settings.getChildText("templates_path");
- String output_path = settings.getChildText("output_path");
-
- /* Calculating derived paths. */
- IPath tpath = new Path(templates_path);
- try {
- Bundle bundle = Platform.getBundle(Activator.PLUGIN_ID);
- tpath = new Path(FileLocator.toFileURL(
- FileLocator.find(bundle, tpath, null)).getFile());
- } catch (IOException e) {
- MessageDialog.openInformation(window.getShell(), "Path Error",
- e.getMessage());
- return null;
- }
-
- /* Templates execution. */
- try {
- TemplateEngine.process(cfgfilepath.toFile(),
- tpath.toFile(),
- new File(output_path));
- } catch (TemplateException e) {
- MessageDialog.openInformation(window.getShell(), "Processing Error",
- e.getMessage());
- return null;
- }
-
- /* Destination directory refresh.*/
- IContainer container = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(cfgfilepath).getParent();
- try {
- container.refreshLocal(IResource.DEPTH_INFINITE, null);
- } catch (CoreException e) {
- e.printStackTrace();
- }
- }
- return null;
- }
-}
diff --git a/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/process/ApplicationGeneratorProcessRunner.java b/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/process/ApplicationGeneratorProcessRunner.java
deleted file mode 100644
index e85442d81..000000000
--- a/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/process/ApplicationGeneratorProcessRunner.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
- 2011,2012 Giovanni Di Sirio.
-
- This file is part of ChibiOS/RT.
-
- ChibiOS/RT is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- ChibiOS/RT is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package org.chibios.tools.eclipse.config.process;
-
-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.runtime.IProgressMonitor;
-
-public class ApplicationGeneratorProcessRunner extends ProcessRunner {
-
- @Override
- public void process(TemplateCore template, ProcessArgument[] args,
- String processId, IProgressMonitor monitor)
- throws ProcessFailureException {
-
- }
-}
diff --git a/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/utils/TemplateEngine.java b/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/utils/TemplateEngine.java
deleted file mode 100644
index ce1e5325a..000000000
--- a/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/utils/TemplateEngine.java
+++ /dev/null
@@ -1,260 +0,0 @@
-/*
- ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
- 2011,2012 Giovanni Di Sirio.
-
- This file is part of ChibiOS/RT.
-
- ChibiOS/RT is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- ChibiOS/RT is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package org.chibios.tools.eclipse.config.utils;
-
-import java.io.IOException;
-import java.util.HashMap;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-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.swt.graphics.Color;
-import org.eclipse.swt.graphics.RGB;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.console.ConsolePlugin;
-import org.eclipse.ui.console.IConsole;
-import org.eclipse.ui.console.IConsoleConstants;
-import org.eclipse.ui.console.IConsoleManager;
-import org.eclipse.ui.console.IConsoleView;
-import org.eclipse.ui.console.MessageConsole;
-import org.eclipse.ui.console.MessageConsoleStream;
-import org.osgi.framework.Bundle;
-import org.w3c.dom.Document;
-import org.xml.sax.SAXException;
-
-import config_wizard.Activator;
-
-import fmpp.Engine;
-import fmpp.ProcessingException;
-import fmpp.ProgressListener;
-import fmpp.setting.SettingException;
-import fmpp.setting.Settings;
-import freemarker.ext.dom.NodeModel;
-import freemarker.template.TemplateNodeModel;
-
-/**
- * FMPP wrapper class.
- */
-public class TemplateEngine {
-
- private final static String CONSOLE_NAME = "ChibiOS/RT Configuration Tool";
-
- private final static Color DEFAULT_MESSAGE = new Color(Display.getDefault(), new RGB(0, 0, 255));
- private final static Color DEFAULT_OUTPUT = new Color(Display.getDefault(), new RGB(0, 0, 0));
- private final static Color DEFAULT_WARNING = new Color(Display.getDefault(), new RGB(255, 255, 0));
- private final static Color DEFAULT_ERROR = new Color(Display.getDefault(), new RGB(255, 0, 0));
-
- private static Settings settings;
- private static MessageConsoleStream msg;
- private static MessageConsoleStream out;
- private static MessageConsoleStream err;
- private static MessageConsoleStream warn;
-
- /**
- * Runs the templates engine.
- *
- * @param xmldata
- * absolute path to XML data file
- * @param sourcedir
- * absolute path to templates directory
- * @param outputdir
- * output directory relative to xmldata
- *
- * @throws SettingException
- * @throws ProcessingException
- */
- public static void process(java.io.File xmldata,
- java.io.File sourcedir,
- java.io.File outputdir) throws TemplateException {
-
- /* Finds or creates a named console. */
- MessageConsole console = findConsole(CONSOLE_NAME);
- activateConsole(console);
- console.clearConsole();
- msg = console.newMessageStream();
- msg.setColor(DEFAULT_MESSAGE);
- out = console.newMessageStream();
- out.setColor(DEFAULT_OUTPUT);
- err = console.newMessageStream();
- err.setColor(DEFAULT_ERROR);
- warn = console.newMessageStream();
- warn.setColor(DEFAULT_WARNING);
-
- /*
- * Calculates the path for FTL libraries.
- */
- IPath libpath = new Path("resources/gencfg/lib");
- Bundle bundle = Platform.getBundle(Activator.PLUGIN_ID);
- try {
- libpath = new Path(FileLocator.toFileURL(FileLocator.find(bundle, libpath, null)).getFile());
- }
- catch (IOException e1) {
- err.println(": FTL libraries path not found.");
- return;
- }
-
- /*
- * Instantiates the FMPP Settings engine and associates a listener for
- * events to be logged.
- */
- try {
- settings = new Settings(xmldata.getParentFile());
- } catch (SettingException e) {
- e.printStackTrace();
- return;
- }
- settings.addProgressListener(new ProgressListener() {
- public void notifyProgressEvent(Engine engine, int event,
- java.io.File src, int pMode,
- java.lang.Throwable error,
- java.lang.Object param) {
-
- if (error != null) {
- err.println(": " + error.getMessage());
- return;
- }
-
- if (pMode == Engine.PMODE_IGNORE)
- return;
-
- switch (event) {
- case EVENT_BEGIN_PROCESSING_SESSION:
- msg.println("Starting session");
- msg.println();
- break;
- case EVENT_END_PROCESSING_SESSION:
- msg.println();
- msg.println("Finished");
- break;
- case EVENT_BEGIN_FILE_PROCESSING:
- out.println("> Processing " + src.getName());
- break;
- case EVENT_END_FILE_PROCESSING:
- break;
- case EVENT_IGNORING_DIR:
- out.println("> Ignoring directory " + src.getName());
- break;
- case EVENT_SOURCE_NOT_MODIFIED:
- out.println("> Skipping " + src.getName());
- break;
- case EVENT_WARNING:
- warn.println(": " + (String)param);
- break;
- }
- }
- });
-
- /* Loading data model. */
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- dbf.setNamespaceAware(true);
- dbf.setValidating(false);
- DocumentBuilder db;
- try {
- db = dbf.newDocumentBuilder();
- } catch (ParserConfigurationException e) {
- throw new TemplateException(e.getMessage());
- }
- Document dom1, dom_snippets;
- try {
- dom1 = db.parse(xmldata);
- java.io.File xmlsnippets = libpath.addTrailingSeparator().append("code_snippets.xml").toFile();
- dom_snippets = db.parse(xmlsnippets);
- } catch (SAXException e) {
- throw new TemplateException(e.getMessage());
- } catch (IOException e) {
- throw new TemplateException(e.getMessage());
- }
-
- NodeModel.removeComments(dom1);
- NodeModel.mergeAdjacentText(dom1);
- NodeModel.removeComments(dom_snippets);
- TemplateNodeModel doc1 = NodeModel.wrap(dom1);
- NodeModel.mergeAdjacentText(dom_snippets);
- TemplateNodeModel doc_snippets = NodeModel.wrap(dom_snippets);
-
- HashMap<String, TemplateNodeModel> xmls = new HashMap<String, TemplateNodeModel>();
- xmls.put("doc1", doc1);
- xmls.put("doc_snippets", doc_snippets);
-
- /* Setting libraries path. */
- HashMap<String, String> libs = new HashMap<String, String>();
- libs.put("lib", libpath.toString());
-
- /* Other settings. */
- try {
- settings.add("freemarkerLinks", libs);
- settings.add("data", xmls);
- settings.add("sourceRoot", sourcedir.toString());
- settings.add("outputRoot", outputdir.toString());
- settings.add("ignoreCvsFiles", true);
- settings.add("ignoreSvnFiles", true);
- } catch (SettingException e) {
- throw new TemplateException(e.getMessage());
- }
-
- /* Processor execution. */
- try {
- settings.execute();
- } catch (SettingException e) {
- throw new TemplateException(e.getMessage());
- } catch (ProcessingException e) {
- throw new TemplateException(e.getMessage());
- }
- }
-
- private static MessageConsole findConsole(String name) {
- ConsolePlugin plugin = ConsolePlugin.getDefault();
- IConsoleManager conMan = plugin.getConsoleManager();
- IConsole[] existing = conMan.getConsoles();
- for (int i = 0; i < existing.length; i++)
- if (name.equals(existing[i].getName()))
- return (MessageConsole) existing[i];
-
- /* No console found, so create a new one. */
- MessageConsole myConsole = new MessageConsole(name, null);
- conMan.addConsoles(new IConsole[] { myConsole });
- return myConsole;
- }
-
- private static void activateConsole(MessageConsole console) {
- IWorkbench wb = PlatformUI.getWorkbench();
- IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
- IWorkbenchPage page = win.getActivePage();
- IConsoleView view;
- try {
- view = (IConsoleView) page.showView(IConsoleConstants.ID_CONSOLE_VIEW);
- } catch (PartInitException e) {
- e.printStackTrace();
- return;
- }
- view.display(console);
- }
-}
diff --git a/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/utils/TemplateException.java b/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/utils/TemplateException.java
deleted file mode 100644
index 73746de1d..000000000
--- a/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/utils/TemplateException.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
- 2011,2012 Giovanni Di Sirio.
-
- This file is part of ChibiOS/RT.
-
- ChibiOS/RT is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- ChibiOS/RT is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package org.chibios.tools.eclipse.config.utils;
-
-public class TemplateException extends Exception {
-
- private static final long serialVersionUID = -3317410595937500925L;
-
- public TemplateException(String msg) {
- super(msg);
- }
-}
diff --git a/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/wizards/ConfigurationNewWizard.java b/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/wizards/ConfigurationNewWizard.java
deleted file mode 100644
index 28ee7e6e7..000000000
--- a/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/wizards/ConfigurationNewWizard.java
+++ /dev/null
@@ -1,185 +0,0 @@
-/*
- ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
- 2011,2012 Giovanni Di Sirio.
-
- This file is part of ChibiOS/RT.
-
- ChibiOS/RT is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- ChibiOS/RT is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package org.chibios.tools.eclipse.config.wizards;
-
-import java.lang.reflect.InvocationTargetException;
-import java.io.*;
-
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.wizard.Wizard;
-import org.eclipse.ui.INewWizard;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.core.runtime.*;
-import org.eclipse.jface.operation.*;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.ui.*;
-import org.eclipse.ui.ide.IDE;
-import org.osgi.framework.Bundle;
-
-import config_wizard.Activator;
-
-/**
- * This is a sample new wizard. Its role is to create a new file resource in the
- * provided container. If the container resource (a folder or a project) is
- * selected in the workspace when the wizard is opened, it will accept it as the
- * target container. The wizard creates one file with the extension "chcfg". If
- * a sample multi-page editor (also available as a template) is registered for
- * the same extension, it will be able to open it.
- */
-
-public class ConfigurationNewWizard extends Wizard implements INewWizard {
- private ConfigurationNewWizardPage page;
- private ISelection selection;
-
- private String containerName;
- private String projectFileName;
- private String defaultDataFile;
-
- /**
- * Constructor for ConfigurationNewWizard.
- */
- public ConfigurationNewWizard() {
- super();
- setNeedsProgressMonitor(true);
- }
-
- /**
- * Adding the page to the wizard.
- */
- public void addPages() {
- page = new ConfigurationNewWizardPage(selection);
- addPage(page);
- }
-
- /**
- * Checks if the wizard page allows to finish.
- */
- public boolean canFinish() {
-
- return page.canFinish();
- }
-
- /**
- * This method is called when 'Finish' button is pressed in the wizard. We
- * will create an operation and run it using wizard as execution context.
- */
- public boolean performFinish() {
-
- containerName = page.getContainerName();
- projectFileName = page.getProjectFileName();
- defaultDataFile = page.getDefaultDataFile();
-
- IRunnableWithProgress op = new IRunnableWithProgress() {
- public void run(IProgressMonitor monitor)
- throws InvocationTargetException {
- try {
- doFinish(monitor);
- } catch (CoreException e) {
- throw new InvocationTargetException(e);
- } finally {
- monitor.done();
- }
- }
- };
- try {
- getContainer().run(true, false, op);
- } catch (InterruptedException e) {
- return false;
- } catch (InvocationTargetException e) {
- Throwable realException = e.getTargetException();
- MessageDialog.openError(getShell(), "Error", realException.getMessage());
- return false;
- }
- return true;
- }
-
- /**
- * The worker method. It will find the container, create the file if missing
- * or just replace its contents, and open the editor on the newly created
- * file.
- */
- private void doFinish(IProgressMonitor monitor) throws CoreException {
-
- IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
- IResource resource = root.findMember(new Path(containerName));
- if (!resource.exists() || !(resource instanceof IContainer)) {
- throwCoreException("Container \"" + containerName + "\" does not exist.");
- }
- IContainer container = (IContainer)resource;
- monitor.beginTask("Creating " + projectFileName, 3);
-
- /* Step #1, creates the project file.*/
- final IFile projectFile = container.getFile(new Path(projectFileName));
- Bundle bundle = Platform.getBundle(Activator.PLUGIN_ID);
- IPath path = new Path(defaultDataFile);
- String s;
- try {
- s = FileLocator.toFileURL(FileLocator.find(bundle, path, null)).getFile();
- InputStream stream = new FileInputStream(s);
- if (projectFile.exists()) {
- projectFile.setContents(stream, true, true, monitor);
- } else {
- projectFile.create(stream, true, monitor);
- }
- stream.close();
- } catch (IOException e) {
- }
- monitor.worked(1);
-
- /* Step #2, opens the XML data file.*/
- monitor.setTaskName("Opening XML data file for editing...");
- getShell().getDisplay().asyncExec(new Runnable() {
- public void run() {
- IWorkbenchPage page = PlatformUI.getWorkbench()
- .getActiveWorkbenchWindow().getActivePage();
- try {
- IDE.openEditor(page, projectFile, true);
- } catch (PartInitException e) {
- }
- }
- });
- monitor.worked(1);
-
- /* Step #3, refreshing local resources.*/
- container.refreshLocal(IResource.DEPTH_INFINITE, monitor);
- monitor.worked(1);
- }
-
- private void throwCoreException(String message) throws CoreException {
- IStatus status = new Status(IStatus.ERROR,
- "org.chibios.tools.eclipse.config", IStatus.OK,
- message, null);
- throw new CoreException(status);
- }
-
- /**
- * We will accept the selection in the workbench to see if we can initialize
- * from it.
- *
- * @see IWorkbenchWizard#init(IWorkbench, IStructuredSelection)
- */
- public void init(IWorkbench workbench, IStructuredSelection selection) {
- this.selection = selection;
- }
-}
diff --git a/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/wizards/ConfigurationNewWizardPage.java b/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/wizards/ConfigurationNewWizardPage.java
deleted file mode 100644
index d503d9748..000000000
--- a/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/wizards/ConfigurationNewWizardPage.java
+++ /dev/null
@@ -1,264 +0,0 @@
-/*
- ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
- 2011,2012 Giovanni Di Sirio.
-
- This file is part of ChibiOS/RT.
-
- ChibiOS/RT is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- ChibiOS/RT is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package org.chibios.tools.eclipse.config.wizards;
-
-import java.io.IOException;
-
-import org.eclipse.core.resources.IContainer;
-import org.eclipse.core.resources.IResource;
-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.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-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.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.swt.widgets.Combo;
-
-import org.osgi.framework.Bundle;
-
-import org.jdom2.Document;
-import org.jdom2.Element;
-import org.jdom2.JDOMException;
-import org.jdom2.input.SAXBuilder;
-
-import config_wizard.Activator;
-
-/**
- * The "New" wizard page allows setting the container for the new file as well
- * as the file name. The page will only accept file name without the extension
- * OR with the extension that matches the expected one (chcfg).
- */
-
-public class ConfigurationNewWizardPage extends WizardPage {
-
- private ISelection selection;
- private IContainer resourceContainer;
-
- private Document processorsDocument;
- private String currentDefaultDataFile;
-
- private Composite container;
- private Combo configurationTemplatesCombo;
- private Text confProjectFilenameText;
-
- /**
- * Constructor for SampleNewWizardPage.
- */
- public ConfigurationNewWizardPage(ISelection selection) {
-
- super("wizardPage");
- setTitle("ChibiOS/RT Configuration Project File");
- setDescription("This wizard creates a ChibiOS/RT configuration resource. Configuration resources allow to generate project resources starting from high level descriptions written in XML.");
- this.selection = selection;
- }
-
- /**
- * @see IDialogPage#createControl(Composite)
- */
- @Override
- public void createControl(Composite parent) {
- container = new Composite(parent, SWT.NULL);
- GridLayout layout = new GridLayout();
- container.setLayout(layout);
- layout.numColumns = 2;
- layout.verticalSpacing = 9;
-
- Label lbl1 = new Label(container, SWT.NULL);
- lbl1.setText("Configuration template:");
-
- configurationTemplatesCombo = new Combo(container, SWT.READ_ONLY);
- configurationTemplatesCombo.setLayoutData(new GridData(SWT.FILL,
- SWT.CENTER, true,
- false, 1, 1));
-
- Label lbl2 = new Label(container, SWT.NULL);
- lbl2.setText("Configuration project filename:");
-
- confProjectFilenameText = new Text(container, SWT.BORDER | SWT.SINGLE);
- confProjectFilenameText.setText("config.chcfg");
- confProjectFilenameText
- .setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- confProjectFilenameText.addModifyListener(new ModifyListener() {
- public void modifyText(ModifyEvent e) {
- confProjectFilenameUpdated();
- }
- });
-
- /* Note, it must stay after the creation of the text fields. */
- configurationTemplatesCombo.addModifyListener(new ModifyListener() {
- public void modifyText(ModifyEvent e) {
- Element processor = getSelectedTemplate();
- String basefilename = processor.getChildText("basefilename");
- confProjectFilenameText.setText(basefilename.concat(".chcfg"));
- currentDefaultDataFile = processor.getChildText("default");
- }
- });
-
- initialize();
- setControl(container);
- }
-
- public String getContainerName() {
-
- return resourceContainer.getFullPath().toString();
- }
-
- public String getProjectFileName() {
-
- return confProjectFilenameText.getText();
- }
-
- public String getDefaultDataFile() {
-
- return currentDefaultDataFile;
- }
-
- public boolean canFinish() {
-
- return container.getEnabled();
- }
-
- /**
- * Tests if the current workbench selection is a suitable container to use.
- */
- private void initialize() {
-
- if (selection != null && selection.isEmpty() == false
- && selection instanceof IStructuredSelection) {
- IStructuredSelection ssel = (IStructuredSelection) selection;
- if (ssel.size() > 1)
- return;
- Object obj = ssel.getFirstElement();
- if (obj instanceof IResource) {
- if (obj instanceof IContainer)
- resourceContainer = (IContainer) obj;
- else
- resourceContainer = ((IResource) obj).getParent();
- }
- }
- else {
- MessageDialog.openError(getShell(),
- "Error", "Container for the resource not selected.");
- container.setEnabled(false);
- updateStatus("Container for the resource not selected.");
- }
-
- /* Retrieving the resource path of the processors.xml file. */
- String fpath;
- try {
- Bundle bundle = Platform.getBundle(Activator.PLUGIN_ID);
- IPath path = new Path("resources/gencfg/processors/processors.xml");
- fpath = FileLocator.toFileURL(FileLocator.find(bundle, path, null))
- .getFile();
- } catch (IOException e) {
- e.printStackTrace();
- return;
- }
-
- /* DOM tree creation. */
- SAXBuilder builder = new SAXBuilder();
- try {
- processorsDocument = builder.build(fpath);
- } catch (JDOMException e) {
- e.printStackTrace();
- return;
- } catch (IOException e) {
- e.printStackTrace();
- return;
- }
-
- /* Parsing the content of the processors.xml file in order to populate the
- panel objects.*/
- Element root = processorsDocument.getRootElement();
- for (Element processor : root.getChildren("processor")) {
- String name = processor.getChildText("name");
- configurationTemplatesCombo.add(name);
- }
- configurationTemplatesCombo.select(0);
- }
-
- /**
- * Checks the content of the confProjectFilenameText field.
- */
- private void confProjectFilenameUpdated() {
- String fileName = getProjectFileName();
-
- if (fileName.length() == 0) {
- updateStatus("File name must be specified");
- return;
- }
- if (fileName.replace('\\', '/').indexOf('/', 1) > 0) {
- updateStatus("File name must be valid");
- return;
- }
- int dotLoc = fileName.lastIndexOf('.');
- if (dotLoc != -1) {
- String ext = fileName.substring(dotLoc + 1);
- if (ext.equalsIgnoreCase("chcfg") == false) {
- updateStatus("Configuration project filename extension must be \"chcfg\"");
- return;
- }
- }
- updateStatus(null);
- }
-
- /**
- * Returns the XML Element associated to the current selection in the combo
- * box.
- *
- * @return An Element Object.
- */
- private Element getSelectedTemplate() {
-
- for (Element processor : processorsDocument.getRootElement()
- .getChildren("processor")) {
- String name = processor.getChildText("name");
- String item = configurationTemplatesCombo
- .getItem(configurationTemplatesCombo.getSelectionIndex());
- if (name.compareTo(item) == 0) {
- return processor;
- }
- }
- return null;
- }
-
- /**
- * Updates the status text in the Wizard page.
- *
- * @param message
- * the message to be shown
- */
- private void updateStatus(String message) {
-
- setErrorMessage(message);
- setPageComplete(message == null);
- }
-}
diff --git a/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/wizards/NewApplicationProjectWizard.java b/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/wizards/NewApplicationProjectWizard.java
deleted file mode 100644
index b94df01cc..000000000
--- a/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/wizards/NewApplicationProjectWizard.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
- 2011,2012 Giovanni Di Sirio.
-
- This file is part of ChibiOS/RT.
-
- ChibiOS/RT is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- ChibiOS/RT is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package org.chibios.tools.eclipse.config.wizards;
-
-import java.lang.reflect.InvocationTargetException;
-
-import org.eclipse.cdt.core.CCorePlugin;
-import org.eclipse.cdt.core.model.CoreModel;
-import org.eclipse.cdt.core.settings.model.ICProjectDescription;
-import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager;
-import org.eclipse.cdt.core.settings.model.extension.CConfigurationData;
-import org.eclipse.cdt.managedbuilder.core.IBuilder;
-import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
-import org.eclipse.cdt.managedbuilder.internal.core.Configuration;
-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.IWorkspaceRoot;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.wizard.Wizard;
-import org.eclipse.ui.INewWizard;
-import org.eclipse.ui.IWorkbench;
-
-@SuppressWarnings("restriction")
-public class NewApplicationProjectWizard extends Wizard implements INewWizard {
-
- private NewApplicationProjectWizardPage page;
- private ISelection selection;
-
- private String projectName;
- private String finalProjectPath;
- private String platform;
-
- /**
- * Constructor for ConfigurationNewWizard.
- */
- public NewApplicationProjectWizard() {
- super();
- setNeedsProgressMonitor(true);
- }
-
- /**
- * Adding the page to the wizard.
- */
- public void addPages() {
- page = new NewApplicationProjectWizardPage(selection);
- addPage(page);
- }
-
- @Override
- public void init(IWorkbench workbench, IStructuredSelection selection) {
- this.selection = selection;
- }
-
- @Override
- public boolean performFinish() {
-
- projectName = page.getProjectName();
- finalProjectPath = page.getFinalProjectPath();
- platform = page.getPlatform();
-
- IRunnableWithProgress op = new IRunnableWithProgress() {
- public void run(IProgressMonitor monitor)
- throws InvocationTargetException {
- try {
- doFinish(monitor);
- }
- catch (CoreException e) {
- throw new InvocationTargetException(e);
- }
- finally {
- monitor.done();
- }
- }
- };
- try {
- getContainer().run(true, false, op);
- }
- catch (InterruptedException e) {
- return false;
- }
- catch (InvocationTargetException e) {
- Throwable realException = e.getTargetException();
- MessageDialog.openError(getShell(), "Error", realException.getMessage());
- return false;
- }
- return true;
- }
-
- /**
- * The worker method. It will find the container, create the file if missing
- * or just replace its contents, and open the editor on the newly created
- * file.
- */
- private void doFinish(IProgressMonitor monitor) throws CoreException {
-
- IWorkspace workspace = ResourcesPlugin.getWorkspace();
- IWorkspaceRoot root = workspace.getRoot();
-
- monitor.beginTask("Creating " + projectName, 3);
-
- /* Step #1, creates the project file.*/
- IProject project = root.getProject(projectName);
- if (project.exists()) {
- monitor.done();
- MessageDialog.openError(getShell(), "Error", "Project " + projectName +
- " already exists in workspace");
- return;
- }
-
- IProjectDescription desc = project.getWorkspace().newProjectDescription(projectName);
- if (finalProjectPath != null)
- desc.setLocation(new Path(finalProjectPath));
- project.create(desc, null);
-
- /* Step #2, makes it a CDT project.*/
- desc = workspace.newProjectDescription(projectName);
- project = CCorePlugin.getDefault().createCDTProject(desc, project, null);
-
- ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
- ICProjectDescription cdesc = mngr.createProjectDescription(project, false);
- ManagedProject mproject = new ManagedProject(cdesc);
- Configuration cfg = new Configuration(mproject, null, "Default", "Default");
- IBuilder bld = cfg.getEditableBuilder();
- bld.setManagedBuildOn(false);
- CConfigurationData data = cfg.getConfigurationData();
- cdesc.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data);
-
- mngr.setProjectDescription(project, cdesc);
- monitor.worked(1);
- }
-}
diff --git a/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/wizards/NewApplicationProjectWizardPage.java b/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/wizards/NewApplicationProjectWizardPage.java
deleted file mode 100644
index b2daabeac..000000000
--- a/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/wizards/NewApplicationProjectWizardPage.java
+++ /dev/null
@@ -1,312 +0,0 @@
-/*
- ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
- 2011,2012 Giovanni Di Sirio.
-
- This file is part of ChibiOS/RT.
-
- ChibiOS/RT is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- ChibiOS/RT is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package org.chibios.tools.eclipse.config.wizards;
-
-import java.io.File;
-import java.io.IOException;
-
-import org.eclipse.core.resources.IProject;
-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.jface.viewers.ISelection;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.DirectoryDialog;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.widgets.Combo;
-
-import org.jdom2.Document;
-import org.jdom2.Element;
-import org.jdom2.JDOMException;
-import org.jdom2.input.SAXBuilder;
-import org.osgi.framework.Bundle;
-
-import config_wizard.Activator;
-
-public class NewApplicationProjectWizardPage extends WizardPage {
-
- private Composite container;
- private Text projectParentPathText;
- private Button btnBrowse;
- private Label lbl1;
- private Text projectNameText;
- private Button useCustomPathButton;
- private Label lbl3;
- private Text projectFinalPathText;
- private Label lbl4;
- private Combo platformCombo;
-
- /**
- * Constructor for SampleNewWizardPage.
- */
- public NewApplicationProjectWizardPage(ISelection selection) {
-
- super("wizardPage");
- setTitle("ChibiOS/RT New Application Project Wizard");
- setDescription("This wizard creates a new ChibiOS/RT application project.");
- }
-
- /**
- * @see IDialogPage#createControl(Composite)
- */
- @Override
- public void createControl(Composite parent) {
- container = new Composite(parent, SWT.NULL);
- GridLayout layout = new GridLayout();
- container.setLayout(layout);
- layout.numColumns = 3;
- layout.verticalSpacing = 9;
-
- /* Layout row 1.*/
- lbl1 = new Label(container, SWT.NONE);
- lbl1.setText("Project name:");
- projectNameText = new Text(container, SWT.BORDER);
- projectNameText.addModifyListener(new ModifyListener() {
- public void modifyText(ModifyEvent e) {
- projectPageUpdated();
- }
- });
- projectNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
- new Label(container, SWT.NONE);
-
- /* Layout row 2.*/
- useCustomPathButton = new Button(container, SWT.CHECK);
- useCustomPathButton.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- if (useCustomPathButton.getSelection()) {
- projectParentPathText.setText(ResourcesPlugin.getWorkspace().getRoot().getLocation().toString());
- projectParentPathText.setEnabled(false);
- btnBrowse.setEnabled(false);
- updateFinalProjectPathText();
- }
- else {
- projectParentPathText.setText(ResourcesPlugin.getWorkspace().getRoot().getLocation().toString());
- projectParentPathText.setEnabled(true);
- btnBrowse.setEnabled(true);
- updateFinalProjectPathText();
- }
- }
- });
- useCustomPathButton.setText("Use default location");
- new Label(container, SWT.NONE);
- new Label(container, SWT.NONE);
-
- /* Layout row 3.*/
- Label lbl2 = new Label(container, SWT.NULL);
- lbl2.setText("Project parent path:");
- projectParentPathText = new Text(container, SWT.BORDER | SWT.SINGLE);
- projectParentPathText.addModifyListener(new ModifyListener() {
- public void modifyText(ModifyEvent e) {
- projectPageUpdated();
- }
- });
- projectParentPathText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- btnBrowse = new Button(container, SWT.NONE);
- btnBrowse.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- /* Prompts the user for a parent directory for the new project.*/
- DirectoryDialog dlg = new DirectoryDialog(getShell());
- dlg.setFilterPath(projectParentPathText.getText());
- dlg.setText("New ChibiOS/RT Project");
- dlg.setMessage("Select the parent directory for the new ChibiOS/RT application project.");
- String parent = dlg.open();
- if (parent != null) {
- projectParentPathText.setText(parent);
- projectPageUpdated();
- }
- }
- });
- btnBrowse.setText("Browse...");
-
- /* Layout row 4.*/
- lbl3 = new Label(container, SWT.NONE);
- lbl3.setText("Final project path:");
- projectFinalPathText = new Text(container, SWT.BORDER);
- projectFinalPathText.setEditable(false);
- projectFinalPathText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
- new Label(container, SWT.NONE);
-
- /* Layout row 5.*/
- lbl4 = new Label(container, SWT.NONE);
- lbl4.setText("Target platform:");
- platformCombo = new Combo(container, SWT.READ_ONLY);
- platformCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
- new Label(container, SWT.NONE);
-
- initialize();
- setControl(container);
- }
-
- /**
- * Tests if the current workbench selection is a suitable container to use.
- */
- private void initialize() {
-
- /* Initial state of the check box and project path text.*/
- useCustomPathButton.setSelection(true);
- projectParentPathText.setText(ResourcesPlugin.getWorkspace().getRoot().getLocation().toString());
- projectParentPathText.setEnabled(false);
- btnBrowse.setEnabled(false);
-
- /* Retrieving the resource path of the processors.xml file. */
- String fpath;
- try {
- Bundle bundle = Platform.getBundle(Activator.PLUGIN_ID);
- IPath path = new Path("resources/gencfg/processors/processors.xml");
- fpath = FileLocator.toFileURL(FileLocator.find(bundle, path, null)).getFile();
- } catch (IOException e) {
- e.printStackTrace();
- return;
- }
-
- /* DOM tree creation. */
- SAXBuilder builder = new SAXBuilder();
- Document document;
- try {
- document = builder.build(fpath);
- } catch (JDOMException e) {
- e.printStackTrace();
- return;
- } catch (IOException e) {
- e.printStackTrace();
- return;
- }
-
- /* Parsing the content of the processors.xml file in order to populate the
- panel objects.*/
- Element root = document.getRootElement();
- for (Element processor : root.getChildren("processor")) {
- String class_attr = processor.getAttributeValue("class", "");
- if (class_attr.compareToIgnoreCase("build") == 0) {
- String name = processor.getAttributeValue("target", "internal error");
- platformCombo.add(name);
- }
- }
- platformCombo.select(0);
-
- /* Update checks on the fields.*/
- projectPageUpdated();
-
- /* Focus on the first editable field.*/
- projectNameText.setFocus();
- }
-
- public String getProjectName() {
-
- return projectNameText.getText();
- }
-
- public String getProjectParentPath() {
-
- return projectParentPathText.getText();
- }
-
- public String getFinalProjectPath() {
-
- if (useCustomPathButton.getSelection())
- return null;
- return projectFinalPathText.getText();
- }
-
- public String getPlatform() {
-
- return platformCombo.getText();
- }
-
- private void projectPageUpdated() {
-
- updateFinalProjectPathText();
-
- /* Checks the project location.*/
- File path = new File(projectParentPathText.getText());
- if (!path.exists()) {
- updateStatus("Project path is not valid.");
- return;
- }
- if (!path.isDirectory()) {
- updateStatus("Project path is a directory.");
- return;
- }
-
- /* Checks the project name.*/
- String name = projectNameText.getText();
- if (!isValidFilename(name)) {
- updateStatus("Invalid project name.");
- return;
- }
-
- /* Checks if the project already exists in the workspace.*/
- IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
- if (project.exists()) {
- updateStatus("Project exists.");
- return;
- }
-
- updateStatus(null);
- }
-
- /**
- * Updates the status text in the Wizard page.
- *
- * @param message
- * the message to be shown
- */
- private void updateStatus(String message) {
-
- setErrorMessage(message);
- setPageComplete(message == null);
- }
-
- private void updateFinalProjectPathText() {
-
- IPath parent = new Path(projectParentPathText.getText());
- IPath project = parent.addTrailingSeparator().append(projectNameText.getText());
- projectFinalPathText.setText(project.toString());
- }
-
- private boolean isValidFilename(String name) {
-
- if (name.length() == 0)
- return false;
- if ((name.indexOf("`") >= 0) || (name.indexOf("?") >= 0) ||
- (name.indexOf("*") >= 0) || (name.indexOf("<") >= 0) ||
- (name.indexOf(">") >= 0) || (name.indexOf("|") >= 0) ||
- (name.indexOf("\"") >= 0) || (name.indexOf(":") >= 0) ||
- (name.indexOf("#") >= 0) || (name.indexOf("\\") >= 0) ||
- (name.indexOf("/") >= 0) || (name.indexOf("|") >= 0))
- return false;
- return true;
- }
-}