| /** |
| * ******************************************************************************* |
| * Copyright (c) 2017 Timing-Architects Embedded Systems 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 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Timing-Architects Embedded Systems GmbH - initial API and implementation |
| * |
| * ******************************************************************************* |
| */ |
| package org.eclipse.app4mc.amalthea.generator.ui; |
| |
| import java.io.File; |
| import java.io.FileInputStream; |
| import java.io.FileNotFoundException; |
| import java.io.IOException; |
| import java.util.HashMap; |
| import java.util.Map; |
| |
| import org.eclipse.app4mc.amalthea.generator.configuration.RTMGC; |
| import org.eclipse.app4mc.amalthea.generator.configuration.RTMGCFactory; |
| import org.eclipse.app4mc.amalthea.generator.configuration.RTMGCPackage; |
| import org.eclipse.emf.common.util.URI; |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.emf.ecore.xmi.XMIResource; |
| import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; |
| import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl; |
| import org.eclipse.jface.wizard.WizardPage; |
| import org.eclipse.swt.SWT; |
| import org.eclipse.swt.widgets.Composite; |
| import org.eclipse.swt.widgets.TabFolder; |
| import org.eclipse.swt.graphics.Point; |
| |
| public class ConfigurationPage extends WizardPage { |
| |
| private final GeneralConfigurationHelper generalHelper = new GeneralConfigurationHelper(this); |
| private final ActivationsConfigurationHelper activationsHelper = new ActivationsConfigurationHelper(); |
| private final LabelsConfigurationHelper labelsHelper = new LabelsConfigurationHelper(); |
| private final RunnablesConfigurationHelper runnablesHelper = new RunnablesConfigurationHelper(); |
| private final SemaphoresConfigurationHelper semaphoresHelper = new SemaphoresConfigurationHelper(); |
| private final TasksConfigurationHelper tasksHelper = new TasksConfigurationHelper(); |
| |
| protected ConfigurationPage() { |
| super("Configuration"); |
| setTitle("Configuration"); |
| setDescription("Configure the settings for the random model generation"); |
| } |
| |
| @Override |
| public void createControl(Composite parent) { |
| TabFolder folder = new TabFolder(parent, SWT.NONE); |
| |
| this.generalHelper.addTabItem(folder); |
| this.activationsHelper.addTabItem(folder); |
| this.labelsHelper.addTabItem(folder); |
| this.runnablesHelper.addTabItem(folder); |
| this.semaphoresHelper.addTabItem(folder); |
| this.tasksHelper.addTabItem(folder); |
| |
| // avoid that dialog gets too big |
| Point size = getShell().computeSize(510,540); |
| getShell().setSize(size); |
| |
| setControl(folder); |
| } |
| |
| @Override |
| public boolean isPageComplete() { |
| boolean result = true; |
| result &= this.activationsHelper.isValid(); |
| result &= this.generalHelper.isValid(); |
| result &= this.labelsHelper.isValid(); |
| result &= this.runnablesHelper.isValid(); |
| result &= this.semaphoresHelper.isValid(); |
| result &= this.tasksHelper.isValid(); |
| return result; |
| } |
| |
| @Override |
| public boolean canFlipToNextPage() { |
| return this.isPageComplete(); |
| } |
| |
| /* |
| * Fills the controls with data from a configuration file |
| */ |
| public void loadConfiguration(File file) { |
| if(null != file) { |
| // load values |
| // initialise the model |
| RTMGCPackage.eINSTANCE.eClass(); |
| // register the XMI resource factory for the rte extension |
| XMIResource.Factory.Registry reg = XMIResource.Factory.Registry.INSTANCE; |
| Map<String, Object> m = reg.getExtensionToFactoryMap(); |
| m.put("rtmgc", new XMIResourceFactoryImpl()); |
| // Obtain a new resource set |
| XMIResourceFactoryImpl resSet = new XMIResourceFactoryImpl(); |
| // Get the resource |
| XMIResourceImpl resource = (XMIResourceImpl)resSet.createResource(URI.createURI(file.getAbsolutePath(), true)); |
| // Get the first model element and cast it to the right type, in my |
| // example everything is hierarchical included in this first node |
| try { |
| resource.load(new FileInputStream(file), new HashMap<Object,Object>()); |
| } catch (FileNotFoundException e) { |
| // TODO Auto-generated catch block |
| e.printStackTrace(); |
| } catch (IOException e) { |
| // TODO Auto-generated catch block |
| e.printStackTrace(); |
| } |
| // get the root element |
| EObject object = resource.getContents().get(0); |
| if(object instanceof RTMGC) { |
| RTMGC rtmgc = (RTMGC) object; |
| this.activationsHelper.loadConfiguration(rtmgc); |
| this.generalHelper.loadConfiguration(rtmgc); |
| this.labelsHelper.loadConfiguration(rtmgc); |
| this.runnablesHelper.loadConfiguration(rtmgc); |
| this.semaphoresHelper.loadConfiguration(rtmgc); |
| this.tasksHelper.loadConfiguration(rtmgc); |
| } |
| } |
| } |
| |
| public RTMGC getConfiguration() { |
| RTMGC rtmgc = RTMGCFactory.eINSTANCE.createRTMGC(); |
| this.activationsHelper.updateConfiguration(rtmgc); |
| this.generalHelper.updateConfiguration(rtmgc); |
| this.labelsHelper.updateConfiguration(rtmgc); |
| this.runnablesHelper.updateConfiguration(rtmgc); |
| this.semaphoresHelper.updateConfiguration(rtmgc); |
| this.tasksHelper.updateConfiguration(rtmgc); |
| |
| return rtmgc; |
| } |
| |
| } |