| /** |
| * ******************************************************************************* |
| * 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.PercentageDistribution; |
| import org.eclipse.app4mc.amalthea.generator.configuration.RTMGCFactory; |
| import org.eclipse.swt.widgets.Composite; |
| |
| public class PercentageDistributionGroup extends DistributionGroup { |
| |
| public PercentageDistributionGroup(Composite parent, String name) { |
| this(parent, name, 1); |
| } |
| |
| public PercentageDistributionGroup(Composite parent, String name, int avg) { |
| this(parent, name, DistributionType.CONST, avg, avg, avg); |
| } |
| |
| public PercentageDistributionGroup(Composite parent, String name, int min, int max) { |
| this(parent, name, DistributionType.UNIFORM, min, Math.round((min + max) / 2f), max); |
| } |
| |
| public PercentageDistributionGroup(Composite parent, String name, int min, int avg, int max) { |
| this(parent, name, DistributionType.WEIBULL, min, avg, max); |
| } |
| |
| private PercentageDistributionGroup(Composite parent, String name, DistributionType type, int min, int avg, int max) { |
| super(parent, name); |
| this.minSpinner.setDigits(2); |
| this.minSpinner.setMaximum(10000); |
| this.minSpinner.setIncrement(1); |
| this.avgSpinner.setDigits(2); |
| this.avgSpinner.setMaximum(10000); |
| this.avgSpinner.setIncrement(1); |
| this.maxSpinner.setDigits(2); |
| this.maxSpinner.setMaximum(10000); |
| this.maxSpinner.setIncrement(1); |
| |
| super.set(type, min, avg, max); |
| } |
| |
| public void set(PercentageDistribution distribution) { |
| if(null != distribution) { |
| DistributionType type = distribution.getType(); |
| int min = (int) distribution.getMinPercentage(); |
| int avg = (int) distribution.getAvgPercentage(); |
| int max = (int) distribution.getMaxPercentage(); |
| super.set(type, min, avg, max); |
| } |
| } |
| |
| public PercentageDistribution get() { |
| PercentageDistribution distribution = RTMGCFactory.eINSTANCE.createPercentageDistribution(); |
| distribution.setMinPercentage(this.minSpinner.getSelection()); |
| distribution.setAvgPercentage(this.avgSpinner.getSelection()); |
| distribution.setMaxPercentage(this.maxSpinner.getSelection()); |
| distribution.setType(DistributionType.get(this.distributionCombo.getSelectionIndex())); |
| return distribution; |
| } |
| } |