| /** |
| * ******************************************************************************* |
| * 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 org.eclipse.app4mc.amalthea.generator.configuration.DistributionType; |
| import org.eclipse.app4mc.amalthea.generator.configuration.IntegerDistribution; |
| import org.eclipse.app4mc.amalthea.generator.configuration.RTMGCFactory; |
| import org.eclipse.swt.widgets.Composite; |
| |
| public class IntegerDistributionGroup extends DistributionGroup { |
| |
| public IntegerDistributionGroup(Composite parent, String name) { |
| this(parent, name, 1); |
| } |
| |
| public IntegerDistributionGroup(Composite parent, String name, int avg) { |
| this(parent, name, DistributionType.CONST, avg, avg, avg); |
| } |
| |
| public IntegerDistributionGroup(Composite parent, String name, int min, int max) { |
| this(parent, name, DistributionType.UNIFORM, min, Math.round((min + max) / 2f), max); |
| } |
| |
| public IntegerDistributionGroup(Composite parent, String name, int min, int avg, int max) { |
| this(parent, name, DistributionType.WEIBULL, min, avg, max); |
| } |
| |
| private IntegerDistributionGroup(Composite parent, String name, DistributionType type, int min, int avg, int max) { |
| super(parent, name); |
| |
| this.minSpinner.setMaximum(Integer.MAX_VALUE); |
| this.minSpinner.setIncrement(1); |
| this.avgSpinner.setMaximum(Integer.MAX_VALUE); |
| this.avgSpinner.setIncrement(1); |
| this.maxSpinner.setMaximum(Integer.MAX_VALUE); |
| this.maxSpinner.setIncrement(1); |
| |
| super.set(type, min, avg, max); |
| } |
| |
| public void set(IntegerDistribution distribution) { |
| if(null != distribution) { |
| DistributionType type = distribution.getType(); |
| int min = (int) distribution.getMin(); |
| int avg = (int) distribution.getAvg(); |
| int max = (int) distribution.getMax(); |
| this.set(type, min, avg, max); |
| } |
| } |
| |
| public IntegerDistribution get() { |
| IntegerDistribution distribution = RTMGCFactory.eINSTANCE.createIntegerDistribution(); |
| distribution.setMin(this.minSpinner.getSelection()); |
| distribution.setAvg(this.avgSpinner.getSelection()); |
| distribution.setMax(this.maxSpinner.getSelection()); |
| distribution.setType(DistributionType.get(this.distributionCombo.getSelectionIndex())); |
| return distribution; |
| } |
| } |