| /******************************************************************************* |
| * Copyright (c) 2014 Bosch Software Innovations GmbH and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * and Eclipse Distribution License v1.0 which accompany this distribution. |
| * |
| * The Eclipse Public License is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * The Eclipse Distribution License is available at |
| * http://www.eclipse.org/org/documents/edl-v10.php. |
| * |
| * Contributors: |
| * Bosch Software Innovations GmbH - Please refer to git log |
| * |
| *******************************************************************************/ |
| package org.eclipse.vorto.fbeditor.ui.internal.wizards; |
| |
| import org.eclipse.core.resources.IFile; |
| import org.eclipse.core.resources.IProject; |
| import org.eclipse.core.resources.IWorkspace; |
| import org.eclipse.core.resources.ResourcesPlugin; |
| import org.eclipse.core.runtime.CoreException; |
| import org.eclipse.core.runtime.IConfigurationElement; |
| import org.eclipse.core.runtime.IExecutableExtension; |
| import org.eclipse.jface.viewers.IStructuredSelection; |
| import org.eclipse.jface.wizard.Wizard; |
| import org.eclipse.swt.widgets.Display; |
| import org.eclipse.ui.INewWizard; |
| 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.ide.IDE; |
| import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard; |
| import org.eclipse.vorto.api.common.generation.FunctionBlockMetaData; |
| import org.eclipse.vorto.api.common.project.WizardUtil; |
| import org.eclipse.vorto.api.ui.changeevent.ProjectChangeEvent; |
| import org.eclipse.vorto.api.ui.changeevent.ProjectEventListenerRegistry; |
| import org.eclipse.vorto.api.ui.progresstask.TaskParameter; |
| import org.eclipse.vorto.api.ui.progresstask.service.ProgressTaskExecutionService; |
| import org.eclipse.vorto.fbeditor.ui.api.project.ProjectCreationTask; |
| |
| |
| public class IoTWizard extends Wizard implements INewWizard, |
| IExecutableExtension { |
| |
| private IoTWizardPage iotWizardPage; |
| private IConfigurationElement configurationElement; |
| |
| @Override |
| public void init(IWorkbench workbench, IStructuredSelection selection) { |
| } |
| |
| @Override |
| public void addPages() { |
| iotWizardPage = new IoTWizardPage("wizardPage"); |
| iotWizardPage.setTitle("Create Function Block Model"); |
| iotWizardPage |
| .setDescription("Please enter the details for creating function block model project."); |
| addPage(iotWizardPage); |
| } |
| |
| @Override |
| public boolean performFinish() { |
| TaskParameter param = getTaskParameter(); |
| |
| ProgressTaskExecutionService progressTaskExecutionService = ProgressTaskExecutionService |
| .getProgressTaskExecutionService(); |
| progressTaskExecutionService.syncRun(new ProjectCreationTask(param)); |
| |
| openFBModelWithDefaultEditor(); |
| |
| fireRefreshEvent(); |
| |
| BasicNewProjectResourceWizard |
| .updatePerspective(getConfigurationElement()); |
| |
| return true; |
| } |
| |
| private TaskParameter getTaskParameter() { |
| String projectName = iotWizardPage.getProjectName(); |
| String workspaceLocation = iotWizardPage.getWorkspaceLocation(); |
| FunctionBlockMetaData userInput = collectFbUserInput(); |
| |
| TaskParameter param = new TaskParameter(); |
| param.add(ProjectCreationTask.PROJECT_NAME, projectName); |
| param.add(ProjectCreationTask.WORK_SPACE, workspaceLocation); |
| param.add(ProjectCreationTask.FUNCTION_BLOCK_META_DATA, userInput); |
| return param; |
| } |
| |
| private FunctionBlockMetaData collectFbUserInput() { |
| FunctionBlockMetaData fbUserInput = new FunctionBlockMetaData( |
| iotWizardPage.getFunctionBlockName()); |
| fbUserInput.setVersion(iotWizardPage.getFunctionBlockVersion()); |
| String description = iotWizardPage.getFunctionBlockDescription(); |
| fbUserInput.setDescription(description); |
| return fbUserInput; |
| } |
| |
| private void openFBModelWithDefaultEditor() { |
| IWorkspace workspace = ResourcesPlugin.getWorkspace(); |
| String fbName = iotWizardPage.getFunctionBlockName(); |
| IProject project = workspace.getRoot().getProject( |
| iotWizardPage.getProjectName()); |
| final IFile fbfile = project.getFile("/src/models/" + fbName |
| + ".fbmodel"); |
| |
| Display.getDefault().asyncExec(new Runnable() { |
| @Override |
| public void run() { |
| IWorkbenchWindow activeWindow = PlatformUI.getWorkbench() |
| .getActiveWorkbenchWindow(); |
| if (activeWindow != null) { |
| IWorkbenchPage page = activeWindow.getActivePage(); |
| if (page != null) { |
| try { |
| IDE.openEditor(page, fbfile); |
| } catch (PartInitException e) { |
| e.printStackTrace(); |
| } |
| } |
| } |
| } |
| }); |
| |
| } |
| |
| public void fireRefreshEvent() { |
| ProjectEventListenerRegistry.getInstance().fire( |
| new ProjectChangeEvent()); |
| } |
| |
| @Override |
| public void setInitializationData(IConfigurationElement config, |
| String propertyName, Object data) throws CoreException { |
| |
| this.configurationElement = config; |
| |
| } |
| |
| public IConfigurationElement getConfigurationElement() { |
| if (this.configurationElement != null) { |
| return this.configurationElement; |
| } else { |
| return WizardUtil.getWizardConfigurationElement(this.getClass() |
| .getName()); |
| } |
| } |
| |
| } |