| /******************************************************************************* |
| * 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.ui.wizards.saproject; |
| |
| import org.eclipse.core.resources.IProject; |
| import org.eclipse.core.runtime.IProgressMonitor; |
| import org.eclipse.core.runtime.IStatus; |
| import org.eclipse.ui.PlatformUI; |
| import org.polarsys.esf.core.common.messages.Messages; |
| import org.polarsys.esf.core.common.ui.selection.SelectAndRevealResourceJob; |
| import org.polarsys.esf.core.ui.CoreUIActivator; |
| |
| /** |
| * This class contains all the methods used to create a new project, |
| * from nothing. |
| * |
| * It has been split from wizard itself to separate the treatment from the UI. |
| * |
| * @author $Author: jdumont $ |
| * @version $Revision: 83 $ |
| * |
| */ |
| public class ProjectCreationCommand { |
| |
| /** Messages provider. */ |
| private static final Messages MESSAGES_PROVIDER = CoreUIActivator.getMessages(); |
| |
| /** Command creation title. */ |
| private static final String COMMAND_PROJECT_CREATION = |
| MESSAGES_PROVIDER.getString("ProjectCreationCommand.task.label"); //$NON-NLS-1$ |
| |
| /** Project creation state, containing all the parameters for the project creation. */ |
| private ProjectCreationState mProjectCreationState = null; |
| |
| /** Keep track of created project to return it. */ |
| private IProject mCreatedProject = null; |
| |
| /** |
| * Default constructor. |
| * |
| * @param pState Information used to run project creation |
| */ |
| public ProjectCreationCommand(final ProjectCreationState pState) { |
| mProjectCreationState = pState; |
| } |
| |
| /** |
| * Do project creation, step by step. |
| * |
| * @param pMonitor Monitor for display state of project creation |
| * @return {@link IStatus#OK} if creation is successful, otherwise {@link IStatus#ERROR} |
| */ |
| public IStatus execute(final IProgressMonitor pMonitor) { |
| IStatus vStatus = null; |
| |
| pMonitor.beginTask(COMMAND_PROJECT_CREATION, 4); |
| |
| // TODO : Perform project creation ... |
| |
| // Add to working sets |
| if (mProjectCreationState.getWorkingSetsArray().length > 0) { |
| // Add the project in the working sets specified |
| PlatformUI.getWorkbench().getWorkingSetManager() |
| .addToWorkingSets(mCreatedProject, mProjectCreationState.getWorkingSetsArray()); |
| } |
| |
| pMonitor.worked(1); |
| |
| // Then run an asynchronous job to show created project |
| if (vStatus == null || vStatus.isOK()) { |
| SelectAndRevealResourceJob vJob = new SelectAndRevealResourceJob(mCreatedProject); |
| vJob.schedule(); |
| } |
| |
| return vStatus; |
| } |
| |
| /** |
| * @return The created project. Can be null if project creation failed ! |
| */ |
| public IProject getCreatedProject() { |
| return mCreatedProject; |
| } |
| } |