| /******************************************************************************* |
| * Copyright (c) 2016 ALL4TEC & CEA LIST. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License 2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * ALL4TEC & CEA LIST - initial API and implementation |
| ******************************************************************************/ |
| package org.polarsys.esf.core.help.wizard.impl; |
| |
| import java.io.IOException; |
| import java.util.HashMap; |
| import java.util.Map; |
| |
| import org.eclipse.core.runtime.IPath; |
| import org.eclipse.core.runtime.IProgressMonitor; |
| import org.eclipse.core.runtime.IStatus; |
| import org.eclipse.core.runtime.Path; |
| import org.eclipse.emf.common.util.URI; |
| import org.polarsys.esf.core.common.messages.Messages; |
| import org.polarsys.esf.core.help.CoreHelpActivator; |
| import org.polarsys.esf.core.help.wizard.AbstractExampleWizard; |
| |
| /** |
| * Wizard to get ESF project example. |
| * This example is CircuitBreaker model. |
| * |
| * @author $Author: jdumont $ |
| * @version $Revision: 83 $ |
| */ |
| public class CircuitBreakerExampleWizard |
| extends AbstractExampleWizard { |
| |
| /** Message provider. */ |
| private static final Messages MESSAGES_PROVIDER = CoreHelpActivator.getMessages(); |
| |
| /** Name of example project. */ |
| private static final String PROJECT_TITLE = MESSAGES_PROVIDER |
| .getString("CircuitBreakerExampleWizard.example.project.title"); //$NON-NLS-1$ |
| |
| /** Message for wizard execution success. */ |
| private static final String SUCCESSFUL_IMPORT_MESSAGE = MESSAGES_PROVIDER |
| .getString("CircuitBreakerExampleWizard.example.job.success"); //$NON-NLS-1$ |
| |
| /** Name of the source model file. */ |
| private static final String SA_FILE = "Circuit Breaker.sa"; //$NON-NLS-1$ |
| |
| /** Name of the source library file. */ |
| private static final String LIBRARY_FILE = "Circuit Breaker.fearedevents"; //$NON-NLS-1$ |
| |
| /** Name of the global source examples directory. */ |
| private static final String EXAMPLES_DIR = "examples"; //$NON-NLS-1$ |
| |
| /** Name of the source Circuit Breaker example directory. */ |
| private static final String CIRCUITBREAKER_DIR = "Circuit Breaker"; //$NON-NLS-1$ |
| |
| /** Relative path for the directory containing the source example. */ |
| private static final URI SOURCE_EXAMPLE_DIR = |
| URI.createURI(EXAMPLES_DIR).appendSegment(CIRCUITBREAKER_DIR); //$NON-NLS-1$ |
| |
| /** Name of the folder containing the additional UML file. */ |
| private static final String PAPYRUS_DIR = "Papyrus"; //$NON-NLS-1$ |
| |
| /** Name of the source additional UML file. */ |
| private static final String UML_FILE = "Circuit Breaker.uml"; //$NON-NLS-1$ |
| |
| |
| /** |
| * Default constructor. |
| */ |
| public CircuitBreakerExampleWizard() { |
| |
| super( |
| PROJECT_TITLE, |
| SOURCE_EXAMPLE_DIR, |
| SA_FILE, |
| LIBRARY_FILE, |
| SUCCESSFUL_IMPORT_MESSAGE); |
| } |
| |
| |
| /** |
| * {@inheritDoc} |
| * |
| * Overridden to initialise the additional files map to create with the example. |
| * This includes the Papyrus model file. |
| * |
| * @param pMonitor Monitor used to follow job progression |
| * @return An error status if something goes wrong, or OK otherwise |
| */ |
| @Override |
| protected IStatus doFinish(final IProgressMonitor pMonitor) { |
| |
| // Initialise the map with the additional files information |
| Map<URI, IPath> vAdditionalFilesInfoMap = new HashMap<URI, IPath>(); |
| |
| try { |
| // Add the Papyrus UML file information to the map |
| // ... Build the source UML file URI |
| String vUMLFileSourcePath = |
| new Path(EXAMPLES_DIR).append(CIRCUITBREAKER_DIR) |
| .append(PAPYRUS_DIR).append(UML_FILE).toOSString(); |
| URI vUMLFileSourceURI = getFileURI(vUMLFileSourcePath); |
| |
| // ... Build the target directory path |
| IPath vUMLFileTargetDirectory = new Path(PAPYRUS_DIR); |
| |
| // ... Then add the information in the map |
| vAdditionalFilesInfoMap.put(vUMLFileSourceURI, vUMLFileTargetDirectory); |
| |
| } catch (final IOException vException) { |
| CoreHelpActivator.logError("Error during the additional files search", vException); //$NON-NLS-1$ |
| } |
| |
| // Register the built map in this wizard instance |
| setAdditionalFileInfoMap(vAdditionalFilesInfoMap); |
| |
| // Call the parent method to create the example |
| return super.doFinish(pMonitor); |
| } |
| |
| } |