blob: f892c2be04680b030460caf672fcb85808be1221 [file] [log] [blame]
/*****************************************************************************
* Copyright (c) 2010, 2013, 2019 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:
* Tatiana Fesenko (CEA LIST) - Initial API and implementation
* Christian W. Damus (CEA) - Support creating models in repositories (CDO)
* Ansgar Radermacher (CEA) - Robotics variant
*
*****************************************************************************/
package org.eclipse.papyrus.robotics.wizards.wizards;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.emf.common.util.URI;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.papyrus.robotics.wizards.WizardConstants;
import org.eclipse.papyrus.uml.diagram.wizards.Activator;
import org.eclipse.papyrus.uml.diagram.wizards.messages.Messages;
import org.eclipse.papyrus.uml.diagram.wizards.pages.PapyrusProjectCreationPage;
import org.eclipse.papyrus.uml.diagram.wizards.pages.SelectArchitectureContextPage;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
/**
* The Wizard creates a new Project and a Papyrus-for-Robotics Model inside it.
*/
public class NewRoboticsProjectWizard extends NewRoboticsModelWizard {
private static final String MODELS = "models"; //$NON-NLS-1$
private static final String DOT = "."; //$NON-NLS-1$
private static final String SLASH = "/"; //$NON-NLS-1$
private static final String TASKS = "tasks"; //$NON-NLS-1$
private static final String SKILLS = "skills"; //$NON-NLS-1$
private static final String SYSTEMS = "systems"; //$NON-NLS-1$
private static final String SERVICES = "services"; //$NON-NLS-1$
private static final String COMPONENTS = "components"; //$NON-NLS-1$
private static final String TASKBASEDHARA = "taskbased-hara"; //$NON-NLS-1$
/** The Constant WIZARD_ID. */
public static final String WIZARD_ID = "org.eclipse.papyrus.robotics.wizards.createproject"; //$NON-NLS-1$
/** The new project page. */
private PapyrusProjectCreationPage myProjectPage;
@Override
public boolean isCreateProjectWizard() {
return true;
}
/**
* Inits the.
*
* @param workbench
* the workbench
* @param selection
* the selection {@inheritDoc}
*/
@Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
super.init(workbench, selection);
setWindowTitle(Messages.NewPapyrusProjectWizard_new_papyrus_project);
setMyProjectPage(new PapyrusProjectCreationPage(Messages.NewPapyrusProjectWizard_0));
getMyProjectPage().setDescription(Messages.NewPapyrusProjectWizard_1);
setDefaultPageImageDescriptor(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/papyrus/PapyrusProjectWizban_75x66.gif")); //$NON-NLS-1$
}
/**
* Adds the pages.
*
* {@inheritDoc}
*/
@Override
public void addPages() {
// Gives the CreateModelWizard the newProjectPage to display it after the selectDiagramCategoryPage
setNewProjectPage(getMyProjectPage());
selectArchitectureContextPage = new SelectArchitectureContextPage();
super.addPages();
}
/**
* Perform finish.
*
* @return true, if successful {@inheritDoc}
*/
@Override
public boolean performFinish() {
IProject newProjectHandle;
try {
newProjectHandle = createNewProject();
} catch (CoreException e) {
Activator.log.error(Messages.NewPapyrusProjectWizard_exception_on_opening, e);
return false;
}
if (newProjectHandle == null) {
return false;
}
return super.performFinish();
}
/**
* Creates the new project.
*
* @return the i project
* @throws CoreException
* the core exception
*/
protected IProject createNewProject() throws CoreException {
// get a project handle
final IProject project = getMyProjectPage().getProjectHandle();
// get a project descriptor
java.net.URI projectLocationURI = null;
if (!getMyProjectPage().useDefaults()) {
projectLocationURI = getMyProjectPage().getLocationURI();
}
IProjectDescription projectDescription = null;
NullProgressMonitor progressMonitor = new NullProgressMonitor();
if (!project.exists()) {
projectDescription = ResourcesPlugin.getWorkspace().newProjectDescription(project.getName());
if (projectLocationURI != null) {
projectDescription.setLocationURI(projectLocationURI);
}
project.create(projectDescription, new SubProgressMonitor(progressMonitor, 1));
project.open(new SubProgressMonitor(progressMonitor, 1));
IFolder models = project.getFolder(MODELS);
models.create(true, true, null);
IFolder components = models.getFolder(COMPONENTS);
components.create(true, true, null);
IFolder systems = models.getFolder(SYSTEMS);
systems.create(true, true, null);
IFolder services = models.getFolder(SERVICES);
services.create(true, true, null);
IFolder skills = models.getFolder(SKILLS);
skills.create(true, true, null);
IFolder btrees = models.getFolder(TASKS);
btrees.create(true, true, null);
IFolder taskbasedhara = models.getFolder(TASKBASEDHARA);
taskbasedhara.create(true, true, null);
} else {
// projectDescription = project.getDescription();
project.open(new SubProgressMonitor(progressMonitor, 1));
}
return project;
}
@Override
protected URI createNewModelURI(String categoryId) {
// handle extension
String extension = getExtension();
String id = selectViewPointPage.getSelectedID();
String folder = ""; //$NON-NLS-1$
if (id.endsWith(WizardConstants.COMPONENT_DEVELOPMENT_VIEWPOINT)) {
folder = COMPONENTS;
} else if (id.endsWith(WizardConstants.SERVICE_DESIGN_VIEWPOINT)) {
folder = SERVICES;
} else if (id.endsWith(WizardConstants.SYSTEM_CONFIG_VIEWPOINT)) {
folder = SYSTEMS;
} else if (id.endsWith(WizardConstants.BEHAVIOR_DESIGN_VIEWPOINT)) {
folder = SKILLS;
} else if (id.endsWith(WizardConstants.BEHAVIOR_TREE_VIEWPOINT)) {
folder = TASKS;
} else if (id.endsWith(WizardConstants.TASKBASED_HARA_VIEWPOINT)) {
folder = TASKBASEDHARA;
}
IPath newFilePath = getMyProjectPage().getProjectHandle().getFullPath().append(MODELS + SLASH + folder + SLASH + getMyProjectPage().getFileName() + DOT + extension);
return URI.createPlatformResourceURI(newFilePath.toString(), true);
}
public PapyrusProjectCreationPage getMyProjectPage() {
return myProjectPage;
}
public void setMyProjectPage(PapyrusProjectCreationPage myProjectPage) {
this.myProjectPage = myProjectPage;
}
protected WizardNewProjectCreationPage createNewProjectCreationPage() {
return this.myProjectPage;
}
}