| /** |
| * ******************************************************************************* |
| * 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.util.Arrays; |
| |
| import org.eclipse.app4mc.amalthea.generator.configuration.DistributionType; |
| import org.eclipse.app4mc.amalthea.generator.configuration.RTMGCFactory; |
| import org.eclipse.app4mc.amalthea.generator.configuration.Recurrence; |
| import org.eclipse.app4mc.amalthea.generator.configuration.RecurrenceType; |
| import org.eclipse.app4mc.amalthea.generator.configuration.TimeUnit; |
| import org.eclipse.swt.SWT; |
| import org.eclipse.swt.layout.GridData; |
| import org.eclipse.swt.widgets.Combo; |
| import org.eclipse.swt.widgets.Composite; |
| import org.eclipse.swt.widgets.Label; |
| |
| public class RecurrenceGroup extends IntegerTimeDistributionGroup { |
| |
| private final Combo recurrenceCombo; |
| |
| public RecurrenceGroup(Composite parent, String name) { |
| this(parent, name, 1, TimeUnit.PS); |
| } |
| |
| public RecurrenceGroup(Composite parent, String name, int avg, TimeUnit unit) { |
| this(parent, name, DistributionType.CONST, avg, avg, avg, unit); |
| } |
| |
| public RecurrenceGroup(Composite parent, String name, int min, int max, TimeUnit unit) { |
| this(parent, name, DistributionType.UNIFORM, min, Math.round((min + max) / 2f), max, unit); |
| } |
| |
| public RecurrenceGroup(Composite parent, String name, int min, int avg, int max, TimeUnit unit) { |
| this(parent, name, DistributionType.WEIBULL, min, avg, max, unit); |
| } |
| |
| protected RecurrenceGroup(Composite parent, String name, DistributionType type, int min, int avg, int max, TimeUnit unit) { |
| super(parent, name); |
| |
| super.set(type, min, avg, max, unit); |
| |
| Label label = new Label(this.group, SWT.NONE); |
| label.setText("Recurrence Type"); |
| label.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); |
| this.recurrenceCombo = new Combo(this.group, SWT.READ_ONLY); |
| this.recurrenceCombo.setItems(Arrays.stream(RecurrenceType.values()).map(Enum::name).toArray(String[]::new)); |
| this.recurrenceCombo.select(RecurrenceType.RANDOM_VALUE); |
| } |
| |
| //TODO: gurantee that min <= avg <= max |
| //TODO: enable/disable controls according distribution |
| public void set(Recurrence distribution) { |
| if(null != distribution) { |
| super.set(distribution); |
| this.recurrenceCombo.select(distribution.getRecurrenceType().getValue()); |
| } |
| } |
| |
| public Recurrence get() { |
| Recurrence distribution = RTMGCFactory.eINSTANCE.createRecurrence(); |
| distribution.setMin(this.minSpinner.getSelection()); |
| distribution.setAvg(this.avgSpinner.getSelection()); |
| distribution.setMax(this.maxSpinner.getSelection()); |
| distribution.setType(DistributionType.get(this.distributionCombo.getSelectionIndex())); |
| distribution.setUnit(TimeUnit.get(this.unitCombo.getSelectionIndex())); |
| distribution.setRecurrenceType(RecurrenceType.get(this.recurrenceCombo.getSelectionIndex())); |
| return distribution; |
| } |
| |
| } |