Add wizard to generate document from gendoc template.
Change-Id: Iea260b074549e59f323318c4bc3d2b99458ec130
Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@cea.fr>
diff --git a/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.templates/META-INF/MANIFEST.MF b/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.templates/META-INF/MANIFEST.MF
index 7272ff0..54accab 100644
--- a/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.templates/META-INF/MANIFEST.MF
+++ b/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.templates/META-INF/MANIFEST.MF
@@ -7,9 +7,10 @@
Bundle-Vendor: %providerName
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
- org.eclipse.gendoc.wizard.papyrus;bundle-version="0.5.0",
- org.eclipse.gendoc.bundle.acceleo.papyrus;bundle-version="0.5.0",
- org.eclipse.gendoc.wizard;bundle-version="0.5.0",
- org.eclipse.gendoc.wizard.gmf;bundle-version="0.5.0"
+ org.eclipse.gendoc.wizard.papyrus;bundle-version="0.6.0",
+ org.eclipse.gendoc.bundle.acceleo.papyrus;bundle-version="0.6.0",
+ org.eclipse.gendoc.wizard;bundle-version="0.6.0",
+ org.eclipse.gendoc.wizard.gmf;bundle-version="0.6.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
+Export-Package: org.eclipse.papyrus.gendoc.custom.templates
diff --git a/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.ui/.classpath b/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.ui/.classpath
new file mode 100644
index 0000000..ad32c83
--- /dev/null
+++ b/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.ui/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.ui/.project b/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.ui/.project
new file mode 100644
index 0000000..03309b7
--- /dev/null
+++ b/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.ui/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.papyrus.requirements.gendoc.ui</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ </natures>
+</projectDescription>
diff --git a/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.ui/.settings/org.eclipse.jdt.core.prefs b/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.ui/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..ef8a789
--- /dev/null
+++ b/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.ui/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,12 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.ui/META-INF/MANIFEST.MF b/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.ui/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..9ffc6ff
--- /dev/null
+++ b/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.ui/META-INF/MANIFEST.MF
@@ -0,0 +1,23 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %pluginName
+Bundle-SymbolicName: org.eclipse.papyrus.requirements.gendoc.ui;singleton:=true
+Bundle-Version: 0.3.0.qualifier
+Bundle-Activator: org.eclipse.papyrus.requirements.gendoc.ui.Activator
+Bundle-Vendor: %providerName
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.core.resources,
+ org.eclipse.papyrus.infra.widgets;bundle-version="3.0.0",
+ org.eclipse.ui.ide,
+ org.eclipse.gendoc.services;bundle-version="0.6.0",
+ org.eclipse.gendoc.process;bundle-version="0.6.0",
+ org.eclipse.gendoc.tags.handlers;bundle-version="0.6.0",
+ org.eclipse.gendoc;bundle-version="0.6.0",
+ org.eclipse.papyrus.emf.facet.custom.metamodel
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Bundle-ActivationPolicy: lazy
+Export-Package: org.eclipse.papyrus.requirements.gendoc.ui,
+ org.eclipse.papyrus.requirements.gendoc.ui.handlers,
+ org.eclipse.papyrus.requirements.gendoc.ui.wizards,
+ org.eclipse.papyrus.requirements.gendoc.ui.wizards.pages
diff --git a/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.ui/about.html b/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.ui/about.html
new file mode 100644
index 0000000..d35d5ae
--- /dev/null
+++ b/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.ui/about.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
+<title>About</title>
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>June 5, 2007</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, "Program" will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party ("Redistributor") and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
+
+</body>
+</html>
diff --git a/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.ui/build.properties b/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.ui/build.properties
new file mode 100644
index 0000000..8dc1b37
--- /dev/null
+++ b/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.ui/build.properties
@@ -0,0 +1,10 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml,\
+ .settings/,\
+ build.properties,\
+ resources/,\
+ src/
+src.includes = src/
diff --git a/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.ui/plugin.properties b/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.ui/plugin.properties
new file mode 100644
index 0000000..0dbc965
--- /dev/null
+++ b/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.ui/plugin.properties
@@ -0,0 +1,4 @@
+#
+
+pluginName = Papyrus requirements Gendoc UI
+providerName = CEA LIST
diff --git a/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.ui/plugin.xml b/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.ui/plugin.xml
new file mode 100644
index 0000000..3422c42
--- /dev/null
+++ b/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.ui/plugin.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.gendoc.wizard.runner">
+ <GendocElement
+ Instance="org.eclipse.papyrus.requirements.gendoc.ui.RequirementsGendoc2Runner">
+ </GendocElement>
+ </extension>
+ <extension
+ point="org.eclipse.ui.commands">
+ <command
+ defaultHandler="org.eclipse.papyrus.requirements.gendoc.ui.handlers.GenerateRequirementsHandler"
+ id="org.eclipse.papyrus.requirements.gendoc.ui.generateRequirementsCommand"
+ name="Generate requirements report">
+ </command>
+ </extension>
+ <extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+ allPopups="false"
+ locationURI="popup:org.eclipse.papyrus.views.modelexplorer.modelexplorer.popup?after=tools">
+ <command
+ commandId="org.eclipse.papyrus.requirements.gendoc.ui.generateRequirementsCommand"
+ id="org.eclipse.papyrus.requirements.gendoc.ui.generateRequirementsCommand"
+ label="Generate requirements report"
+ style="push">
+ <visibleWhen
+ checkEnabled="false">
+ <with
+ variable="selection">
+ <and>
+ <iterate>
+ <adapt
+ type="org.eclipse.emf.ecore.EObject">
+ </adapt>
+ </iterate>
+ <count
+ value="1">
+ </count>
+ </and>
+ </with>
+ </visibleWhen>
+ </command>
+ </menuContribution>
+ </extension>
+
+</plugin>
diff --git a/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.ui/resources/icons/PapyrusWizban_75x66.gif b/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.ui/resources/icons/PapyrusWizban_75x66.gif
new file mode 100644
index 0000000..ffa3fef
--- /dev/null
+++ b/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.ui/resources/icons/PapyrusWizban_75x66.gif
Binary files differ
diff --git a/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.ui/src/org/eclipse/papyrus/requirements/gendoc/ui/Activator.java b/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.ui/src/org/eclipse/papyrus/requirements/gendoc/ui/Activator.java
new file mode 100644
index 0000000..2c57101
--- /dev/null
+++ b/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.ui/src/org/eclipse/papyrus/requirements/gendoc/ui/Activator.java
@@ -0,0 +1,80 @@
+/*****************************************************************************
+ * Copyright (c) 2017 CEA LIST 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:
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.requirements.gendoc.ui;
+
+import org.eclipse.papyrus.infra.core.log.LogHelper;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.papyrus.requirements.gendoc.ui"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ /** Logging helper. */
+ private static LogHelper logHelper;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ logHelper = new LogHelper(plugin);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ logHelper = null;
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+ /**
+ * Returns the log helper
+ *
+ * @return the log helper
+ */
+ public static LogHelper getLogHelper() {
+ return logHelper;
+ }
+
+}
diff --git a/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.ui/src/org/eclipse/papyrus/requirements/gendoc/ui/handlers/GenerateRequirementsHandler.java b/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.ui/src/org/eclipse/papyrus/requirements/gendoc/ui/handlers/GenerateRequirementsHandler.java
new file mode 100644
index 0000000..67f6623
--- /dev/null
+++ b/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.ui/src/org/eclipse/papyrus/requirements/gendoc/ui/handlers/GenerateRequirementsHandler.java
@@ -0,0 +1,91 @@
+/*****************************************************************************
+ * Copyright (c) 2017 CEA LIST 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:
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.requirements.gendoc.ui.handlers;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.papyrus.emf.facet.custom.metamodel.v0_2_0.internal.treeproxy.EObjectTreeElement;
+import org.eclipse.papyrus.requirements.gendoc.ui.wizards.GenerateRequirementsWizard;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ * The handler to generate the requirements file.
+ */
+public class GenerateRequirementsHandler extends AbstractHandler {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ */
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ final ISelection selection = HandlerUtil.getCurrentSelection(event);
+ if (selection instanceof IStructuredSelection) {
+
+ final IStructuredSelection selec = (IStructuredSelection) selection;
+ Object firstElement = selec.getFirstElement();
+
+ if(firstElement instanceof EObjectTreeElement) {
+ firstElement = ((EObjectTreeElement)firstElement).getEObject();
+ }
+
+ if (null != firstElement && firstElement instanceof EObject) {
+ final EObject selectedEObject = (EObject) firstElement;
+ final GenerateRequirementsWizard designPhaseReportWizard = new GenerateRequirementsWizard("Generate the requirements file", "This allows to generate the requirements document from a template file", getFile(selectedEObject.eResource())); //$NON-NLS-1$ //$NON-NLS-2$
+ designPhaseReportWizard.init(PlatformUI.getWorkbench(), (IStructuredSelection) selection);
+ final WizardDialog dialog = new WizardDialog(Display.getDefault().getActiveShell(), designPhaseReportWizard);
+ dialog.open();
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * This allows to get IFile from a resource.
+ *
+ * @param resource
+ * The initial resource from the EObject selected.
+ * @return The IFile corresponding.
+ */
+ protected IFile getFile(final Resource resource) {
+ if (null != resource) {
+ URI uri = resource.getURI();
+ uri = resource.getResourceSet().getURIConverter().normalize(uri);
+ final String scheme = uri.scheme();
+ if ("platform".equals(scheme) && uri.segmentCount() > 1 && "resource".equals(uri.segment(0))) { //$NON-NLS-1$ //$NON-NLS-2$
+ final StringBuffer platformResourcePath = new StringBuffer();
+ for (int j = 1, size = uri.segmentCount(); j < size; ++j) {
+ platformResourcePath.append('/'); // $NON-NLS-1$
+ platformResourcePath.append(uri.segment(j));
+ }
+ return ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(platformResourcePath.toString()));
+ }
+ }
+ return null;
+ }
+}
diff --git a/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.ui/src/org/eclipse/papyrus/requirements/gendoc/ui/wizards/GenerateRequirementsWizard.java b/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.ui/src/org/eclipse/papyrus/requirements/gendoc/ui/wizards/GenerateRequirementsWizard.java
new file mode 100644
index 0000000..a1bf31f
--- /dev/null
+++ b/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.ui/src/org/eclipse/papyrus/requirements/gendoc/ui/wizards/GenerateRequirementsWizard.java
@@ -0,0 +1,353 @@
+/*****************************************************************************
+ * Copyright (c) 2017 CEA LIST 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:
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.requirements.gendoc.ui.wizards;
+
+import java.io.File;
+import java.lang.reflect.InvocationTargetException;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+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.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.common.util.BasicDiagnostic;
+import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.gendoc.GendocProcess;
+import org.eclipse.gendoc.services.GendocServices;
+import org.eclipse.gendoc.services.IGendocDiagnostician;
+import org.eclipse.gendoc.services.IProgressMonitorService;
+import org.eclipse.gendoc.services.exception.GenDocException;
+import org.eclipse.gendoc.tags.handlers.IConfigurationService;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.papyrus.infra.widgets.util.ImageConstants;
+import org.eclipse.papyrus.requirements.gendoc.ui.Activator;
+import org.eclipse.papyrus.requirements.gendoc.ui.wizards.pages.GenerateRequirementsPage;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchWizard;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * The wizard for the design phase report generation.
+ */
+public class GenerateRequirementsWizard extends Wizard implements IWorkbenchWizard {
+
+ /**
+ * The page name.
+ */
+ private static final String DEFAULT_PAGE_NAME = "Generate the document"; //$NON-NLS-1$
+
+ /**
+ * The page description.
+ */
+ private static final String DEFAULT_PAGE_DESCRIPTION = "This allows to generate the document from a template file"; //$NON-NLS-1$
+
+ /**
+ * The output key for gendoc.
+ */
+ private final String OUTPUT_KEY = "generic_generation_output"; //$NON-NLS-1$
+
+ /**
+ * The model key for gendoc.
+ */
+ private final String MODEL_KEY = "generic_generation_model"; //$NON-NLS-1$
+
+ /**
+ * The page name.
+ */
+ private final String pageName;
+
+ /**
+ * The page description.
+ */
+ private final String pageDescription;
+
+ /**
+ * The wizard page.
+ */
+ private GenerateRequirementsPage generateDesignPhaseReportWizardPage;
+
+ /**
+ * The initial path.
+ */
+ private IFile papyrusFile;
+
+ /**
+ * Constructor.
+ *
+ * @param initialPath
+ * The initial path.
+ */
+ public GenerateRequirementsWizard(final IFile papyrusFile) {
+ this(DEFAULT_PAGE_NAME, DEFAULT_PAGE_DESCRIPTION, papyrusFile);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param pageName
+ * The page name.
+ * @param pageDescription
+ * the page description.
+ * @param initialPath
+ * The initial path.
+ */
+ public GenerateRequirementsWizard(final String pageName, final String pageDescription, final IFile papyrusFile) {
+ this.pageName = pageName;
+ this.pageDescription = pageDescription;
+ this.papyrusFile = papyrusFile;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.wizard.Wizard#createPageControls(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ public void createPageControls(Composite pageContainer) {
+ super.createPageControls(pageContainer);
+ // Set the papyrus icon to the wizard shell
+ getShell().setImage(
+ org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImage(ImageConstants.PAPYRUS_ICON_PATH));
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench,
+ * org.eclipse.jface.viewers.IStructuredSelection)
+ */
+ @Override
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ setWindowTitle(pageName);
+ final String pluginId = Activator.PLUGIN_ID;
+ final String path = "resources/icons/PapyrusWizban_75x66.gif"; //$NON-NLS-1$
+ final ImageDescriptor desc = org.eclipse.papyrus.infra.widgets.Activator.getDefault()
+ .getImageDescriptor(pluginId, path);
+ setDefaultPageImageDescriptor(desc);
+ setNeedsProgressMonitor(true);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.wizard.Wizard#addPages()
+ */
+ @Override
+ public void addPages() {
+ super.addPages();
+ // Initialize and add the wizard page
+ IPath parentPath = null;
+ if (null != this.papyrusFile && null != this.papyrusFile.getParent()) {
+ parentPath = this.papyrusFile.getParent().getFullPath();
+ }
+ generateDesignPhaseReportWizardPage = new GenerateRequirementsPage(pageName, pageDescription, parentPath); // $NON-NLS-1$
+ addPage(this.generateDesignPhaseReportWizardPage);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.wizard.Wizard#performFinish()
+ */
+ @Override
+ public boolean performFinish() {
+
+ final String outputFileName = generateDesignPhaseReportWizardPage.getOutputFileName();
+ final String templateFile = generateDesignPhaseReportWizardPage.getFilePath();
+ final IPath outputFolder = generateDesignPhaseReportWizardPage.getOutputFolder();
+
+ try {
+ getContainer().run(true, true, new IRunnableWithProgress() {
+ public void run(final IProgressMonitor monitor) {
+ generateDocument(papyrusFile, outputFileName, templateFile, ResourcesPlugin.getWorkspace().getRoot()
+ .findMember(outputFolder).getLocation().toOSString(), monitor);
+ }
+ });
+ } catch (final InvocationTargetException e) {
+ Activator.getLogHelper().error(e);
+ } catch (final InterruptedException e) {
+ Activator.getLogHelper().error(e);
+ }
+
+ return true;
+ }
+
+ /**
+ * Get the template path as URL.
+ *
+ * @return The URL of the template path.
+ * @throws MalformedURLException
+ * The possible Malformed URL exception.
+ */
+ protected URL getTemplate(final String templateFile) throws MalformedURLException {
+ URL result = null;
+ if (templateFile.startsWith("platform:/")) { //$NON-NLS-1$
+ result = new URL(templateFile);
+ } else {
+ final File file = new File(templateFile);
+ if (file.exists()) {
+ result = file.toURI().toURL();
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Build the output path.
+ *
+ * @param outputContainer
+ * The declared output container.
+ * @param outputFileName
+ * The output file name.
+ * @return The built output path.
+ */
+ protected String getOutputPath(final String outputContainer, final String outputFileName) {
+ return outputContainer + File.separator + outputFileName;
+ }
+
+ /**
+ * This allows to generate the docx file (with gendoc and poi).
+ *
+ * @param papyrusFile
+ * The file representing the papyrus model.
+ * @param templateFile
+ * The template file as String.
+ * @param outputContainer
+ * The output container chosen by the user.
+ */
+ protected void generateDocument(final IFile papyrusFile, final String outputFileName, final String templateFile,
+ final String outputContainer, final IProgressMonitor monitor) {
+
+ monitor.beginTask("Generate DesignPhase Report", -1);
+
+ final IGendocDiagnostician diagnostician = GendocServices.getDefault().getService(IGendocDiagnostician.class);
+ diagnostician.init();
+ final IProgressMonitorService monitorService = (IProgressMonitorService) GendocServices.getDefault()
+ .getService(IProgressMonitorService.class);
+ monitorService.setMonitor(new NullProgressMonitor());
+
+ try {
+ monitor.subTask("Generate document with model data");
+
+ final IConfigurationService configurationService = GendocServices.getDefault()
+ .getService(IConfigurationService.class);
+ configurationService.addParameter(OUTPUT_KEY, getOutputPath(outputContainer, outputFileName));
+ String input = URI.createPlatformResourceURI(papyrusFile.getFullPath().toString(), false).toString();
+ if (input.matches(".*\\.notation\\z")) { //$NON-NLS-1$
+ input = input.replaceAll(".notation\\z", ".uml"); //$NON-NLS-1$
+ } else {
+ input = input.replaceAll(".di\\z", ".uml"); //$NON-NLS-1$
+ }
+ configurationService.addParameter(MODEL_KEY, input);
+ final GendocProcess gendocProcess = new GendocProcess();
+ final String resultFile = gendocProcess.runProcess(getTemplate(templateFile));
+
+ doPostSubTasks(resultFile, monitor);
+
+ monitor.done();
+
+ // Refresh the project
+ for (final IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
+ if(null == resultFile || resultFile.isEmpty() || resultFile.contains(project.getFullPath().toOSString())){
+ project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
+ }
+ }
+
+ handleDiagnostic(diagnostician.getResultDiagnostic(), "The file has been generated but contains errors :\n", //$NON-NLS-1$
+ resultFile);
+ } catch (GenDocException e) {
+ monitor.done();
+ Activator.getLogHelper().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getUIMessage(), e));
+ diagnostician.addDiagnostic(
+ new BasicDiagnostic(Diagnostic.ERROR, Activator.PLUGIN_ID, 0, e.getUIMessage(), null));
+ handleDiagnostic(diagnostician.getResultDiagnostic(), "An error occured during generation.", null); //$NON-NLS-1$
+ } catch (Throwable t) {
+ monitor.done();
+ Activator.getLogHelper().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, t.getMessage(), t));
+ diagnostician.addDiagnostic(
+ new BasicDiagnostic(Diagnostic.ERROR, Activator.PLUGIN_ID, 0, t.getMessage(), t.getStackTrace()));
+ handleDiagnostic(diagnostician.getResultDiagnostic(), "An unexpected error occured during the generation.", //$NON-NLS-1$
+ null);
+ } finally {
+ GendocServices.getDefault().clear();
+ }
+ }
+
+ /**
+ * This allows to do some tasks after the gendoc process.
+ *
+ * @param resultFile
+ * The result file.
+ * @param monitor
+ * The progress monitor.
+ */
+ protected void doPostSubTasks(final String resultFile, final IProgressMonitor monitor) {
+ // Do nothing here
+ }
+
+ /**
+ * Handle diagnostic.
+ *
+ * @param resultDiagnostic
+ * The result diagnostic.
+ * @param message
+ * The message to display.
+ * @param resultFilePath
+ * The result file path.
+ */
+ public static void handleDiagnostic(final Diagnostic resultDiagnostic, final String message,
+ final String resultFilePath) {
+ if (resultDiagnostic.getSeverity() == Diagnostic.OK) {
+ Display.getDefault().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
+ "Document generator", message + resultFilePath); //$NON-NLS-1$
+ }
+ });
+ } else if (resultDiagnostic.getSeverity() == Diagnostic.WARNING) {
+ Display.getDefault().syncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ ErrorDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
+ "Document generator", message + resultFilePath + "\n but contains some warnings:\n", //$NON-NLS-1$ //$NON-NLS-2$
+ BasicDiagnostic.toIStatus(resultDiagnostic));
+ }
+ });
+ } else {
+ Display.getDefault().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ ErrorDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
+ "Document generator", message, BasicDiagnostic.toIStatus(resultDiagnostic)); //$NON-NLS-1$
+ }
+ });
+ }
+ }
+}
diff --git a/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.ui/src/org/eclipse/papyrus/requirements/gendoc/ui/wizards/pages/GenerateRequirementsPage.java b/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.ui/src/org/eclipse/papyrus/requirements/gendoc/ui/wizards/pages/GenerateRequirementsPage.java
new file mode 100644
index 0000000..f2701c1
--- /dev/null
+++ b/plugins/gendoc/org.eclipse.papyrus.requirements.gendoc.ui/src/org/eclipse/papyrus/requirements/gendoc/ui/wizards/pages/GenerateRequirementsPage.java
@@ -0,0 +1,374 @@
+/*****************************************************************************
+ * Copyright (c) 2017 CEA LIST 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:
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.requirements.gendoc.ui.wizards.pages;
+
+import java.io.File;
+
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.window.Window;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.papyrus.infra.widgets.editors.StringFileSelector;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+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.Display;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.dialogs.ContainerSelectionDialog;
+
+/**
+ * The wizard page for the requirements generation.
+ */
+public class GenerateRequirementsPage extends WizardPage {
+
+ /**
+ * The template file path.
+ */
+ private final String DEFAULT_TEMPLATE_FILE = "platform:/plugin/org.eclipse.papyrus.requirements.gendoc.templates/resources/RequirementDoc.docx"; //$NON-NLS-1$
+
+ /**
+ * Files allowed to be managed as template file.
+ */
+ private static final String[] allowedFiles = new String[] { "*.docx" }; //$NON-NLS-1$
+
+ /**
+ * The selected file path.
+ */
+ private String selectedFilePath;
+
+ /**
+ * The selected output folder.
+ */
+ private IPath outputFolder;
+
+ /**
+ * the output file name.
+ */
+ private String outputFileName;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param pageName
+ * The page name.
+ * @param pageDescription
+ * The page description.
+ */
+ public GenerateRequirementsPage(final String pageName, final String pageDescription) {
+ this(pageName, pageDescription, null);
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param pageName
+ * The page name.
+ * @param pageDescription
+ * The page description.
+ * @param initialPath
+ * The initial path where generate the document.
+ */
+ public GenerateRequirementsPage(final String pageName, final String pageDescription, final IPath initialPath) {
+ super(pageName, pageName, null);
+ setDescription(pageDescription);
+ // set the initial values
+ setFilePath(DEFAULT_TEMPLATE_FILE);
+ setOutputFolder(initialPath);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ public void createControl(Composite parent) {
+ final Composite localComposite = new Composite(parent, SWT.NONE);
+ setControl(localComposite);
+ localComposite.setLayout(new GridLayout(1, false));
+
+ // Create the template group
+ final Group outputFileNameGroup = new Group(localComposite, SWT.FILL);
+ outputFileNameGroup.setText("Output file"); //$NON-NLS-1$
+ outputFileNameGroup.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
+ outputFileNameGroup.setLayout(new GridLayout(2, false));
+
+ final Label outputFileNameLabel = new Label(outputFileNameGroup, SWT.NONE);
+ outputFileNameLabel.setText("Output file name:"); //$NON-NLS-1$
+
+ // Create the destination text (not editable, only by the button)
+ final Text outputFileNameText = new Text(outputFileNameGroup, SWT.BORDER);
+ final GridData outputFileNameTextLayoutData = new GridData(1, 1);
+ outputFileNameTextLayoutData.horizontalAlignment = SWT.FILL;
+ outputFileNameTextLayoutData.grabExcessHorizontalSpace = true;
+ outputFileNameTextLayoutData.verticalAlignment = SWT.FILL;
+ outputFileNameTextLayoutData.grabExcessVerticalSpace = true;
+ outputFileNameTextLayoutData.minimumHeight = 21;
+ outputFileNameText.setLayoutData(outputFileNameTextLayoutData);
+ outputFileNameText.addModifyListener(new ModifyListener() {
+ @Override
+ public void modifyText(ModifyEvent e) {
+ setOutputFileName(outputFileNameText.getText());
+ setPageComplete(isPageComplete());
+ }
+ });
+
+ // Create the template group
+ final Group templateGroup = new Group(localComposite, SWT.FILL);
+ templateGroup.setText("Template file"); //$NON-NLS-1$
+ templateGroup.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
+ templateGroup.setLayout(new GridLayout(2, false));
+
+ // Create the default template button
+ final Button defaultTemplate = new Button(templateGroup, SWT.RADIO);
+ final GridData defaultTemplateLayoutData = new GridData(SWT.FILL, SWT.NONE, true, false);
+ defaultTemplateLayoutData.horizontalSpan = 2;
+ defaultTemplate.setLayoutData(defaultTemplateLayoutData);
+ defaultTemplate.setText("Use default template file"); //$NON-NLS-1$
+ // Change the file path when the default template button is selected
+ defaultTemplate.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (defaultTemplate.getSelection()) {
+ setFilePath(DEFAULT_TEMPLATE_FILE);
+ setPageComplete(isPageComplete());
+ }
+ }
+ });
+ // Initialize the default template button as selected
+ defaultTemplate.setSelection(true);
+
+ // Create the custom template button
+ final Button customTemplate = new Button(templateGroup, SWT.RADIO);
+ customTemplate.setSelection(false);
+ customTemplate.setText("Use custom template file:"); //$NON-NLS-1$
+
+ // Create the file selector available only when the custom template button is
+ // selected
+ final StringFileSelector selector = new StringFileSelector(templateGroup, SWT.NONE);
+ final GridData customTemplateLayoutData = new GridData(1, 1);
+ customTemplateLayoutData.grabExcessVerticalSpace = true;
+ selector.setLayoutData(customTemplateLayoutData);
+ selector.setEnabled(customTemplate.getSelection());
+ selector.getText().setEditable(customTemplate.getSelection());
+ selector.setAllowFileSystem(true);
+ selector.setAllowWorkspace(false);
+ selector.setFilterExtensions(allowedFiles);
+ selector.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+ // Set a minimum width to the selector text
+ if (selector.getText().getLayoutData() instanceof GridData) {
+ ((GridData) selector.getText().getLayoutData()).minimumWidth = 300;
+ }
+ // Manage the selector modification
+ selector.getText().addModifyListener(new ModifyListener() {
+ @Override
+ public void modifyText(ModifyEvent e) {
+ if (customTemplate.getSelection()) {
+ setFilePath(selector.getText().getText());
+ setPageComplete(isPageComplete());
+ }
+ }
+ });
+
+ // Change the file path with the selector text when the custom template is
+ // selected
+ customTemplate.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ final boolean customTemplateSelection = customTemplate.getSelection();
+ selector.setEnabled(customTemplateSelection);
+ selector.getText().setEditable(customTemplateSelection);
+ if (customTemplateSelection) {
+ final Object value = selector.getValue();
+ if (value instanceof String) {
+ setFilePath((String) value);
+ }
+ }
+ setPageComplete(isPageComplete());
+ }
+ });
+
+ // Create the destination group
+ final Group destinationGroup = new Group(localComposite, SWT.FILL);
+ destinationGroup.setText("Destination"); //$NON-NLS-1$
+ destinationGroup.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
+ destinationGroup.setLayout(new GridLayout(3, false));
+
+ // Create the destination label
+ final Label destinationLabel = new Label(destinationGroup, SWT.NONE);
+ destinationLabel.setText("Destination:"); //$NON-NLS-1$
+
+ // Create the destination text (not editable, only by the button)
+ final Text destinationText = new Text(destinationGroup, SWT.BORDER);
+ final GridData destinationTextLayoutData = new GridData(1, 1);
+ destinationTextLayoutData.horizontalAlignment = SWT.FILL;
+ destinationTextLayoutData.grabExcessHorizontalSpace = true;
+ destinationTextLayoutData.verticalAlignment = SWT.FILL;
+ destinationTextLayoutData.grabExcessVerticalSpace = true;
+ destinationText.setLayoutData(destinationTextLayoutData);
+ destinationText.setEditable(false);
+
+ // Initialize the destination text with the initial output folder
+ if (null != outputFolder) {
+ destinationText.setText(outputFolder.toOSString());
+ }
+
+ // Create the destination browse button
+ final Button browseButton = new Button(destinationGroup, SWT.PUSH);
+ browseButton.setText("Browse..."); //$NON-NLS-1$
+ browseButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ final ContainerSelectionDialog dialog = new ContainerSelectionDialog(
+ Display.getCurrent().getActiveShell(), ResourcesPlugin.getWorkspace().getRoot(), true,
+ "Select output container: "); //$NON-NLS-1$
+ dialog.setTitle("Container Selection"); //$NON-NLS-1$
+ if (dialog.open() == Window.OK) {
+ final Object[] results = dialog.getResult();
+ if (results.length == 1) {
+ if (results[0] instanceof Path) {
+ setOutputFolder((org.eclipse.core.runtime.Path) results[0]);
+ destinationText.setText(outputFolder.toOSString());
+ setPageComplete(isPageComplete());
+ }
+ }
+ }
+ }
+ });
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.wizard.WizardPage#isPageComplete()
+ */
+ @Override
+ public boolean isPageComplete() {
+ final boolean isValidOutputFileName = getOutputFileName() != null && !getOutputFileName().isEmpty();
+ final boolean isValidFilePath = getFilePath() != null && !getFilePath().isEmpty();
+ final boolean isValidOutputFolder = getOutputFolder() != null && !getOutputFolder().toOSString().isEmpty();
+ final boolean isFileExist = getFilePath() != null && !getFilePath().startsWith("platform:/")
+ ? new File(getFilePath()).exists()
+ : true;
+
+ if (!isValidOutputFileName) {
+ setErrorMessage("The output file name must be filled"); //$NON-NLS-1$
+ } else if (!isValidFilePath) {
+ setErrorMessage("The template file must be filled"); //$NON-NLS-1$
+ } else if (!isFileExist) {
+ setErrorMessage("The template file does not exist"); //$NON-NLS-1$
+ } else if (!isValidOutputFolder) {
+ setErrorMessage("The destination must be filled"); //$NON-NLS-1$
+ } else {
+ setErrorMessage(null);
+ }
+
+ return isValidFilePath && isValidOutputFolder && isFileExist;
+ }
+
+ /**
+ * This allows to replace the percent char by spaces.
+ *
+ * @param theString
+ * The string containing space character.
+ * @return The string with percentage character.
+ */
+ protected String formatStringForURL(final String theString) {
+ return theString.replaceAll(" ", "%20").replaceAll("\\\\", "/"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ }
+
+ /**
+ * This allows to get the selected file.
+ *
+ * @return The selected file.
+ */
+ public String getFilePath() {
+ return this.selectedFilePath;
+ }
+
+ /**
+ * This allows to set the file path.
+ *
+ * @param filePath
+ * Find the file from the filePath and set it.
+ */
+ public void setFilePath(final String filePath) {
+ if (filePath == null || filePath.length() == 0) {
+ this.selectedFilePath = null;
+ } else {
+ this.selectedFilePath = formatStringForURL(filePath);
+ }
+ }
+
+ /**
+ * This allows to get the output folder.
+ *
+ * @return The output folder.
+ */
+ public IPath getOutputFolder() {
+ return this.outputFolder;
+ }
+
+ /**
+ * This allows to set the output folder.
+ *
+ * @param outputFolder
+ * Find the file from the output folder and set it.
+ */
+ public void setOutputFolder(final IPath outputFolder) {
+ if (outputFolder == null || outputFolder.toOSString().length() == 0) {
+ this.outputFolder = null;
+ } else {
+ this.outputFolder = outputFolder;
+ }
+ }
+
+ /**
+ * This allows to get the output file name.
+ *
+ * @return The output file name.
+ */
+ public String getOutputFileName() {
+ return this.outputFileName;
+ }
+
+ /**
+ * This allows to set the output file name.
+ *
+ * @param outputFileName
+ * Find the file from the output file name and set it.
+ */
+ public void setOutputFileName(final String outputFileName) {
+ if (outputFileName == null || outputFileName.isEmpty()) {
+ this.outputFileName = null;
+ } else {
+ this.outputFileName = outputFileName;
+ if(!this.outputFileName.endsWith(".docx")) { //$NON-NLS-1$
+ this.outputFileName = this.outputFileName + ".docx"; //$NON-NLS-1$
+ }
+ }
+ }
+
+}