blob: 1a9849adcfaf3d45aa50334db503ee08d58fc4c8 [file] [log] [blame]
/**
* *******************************************************************************
* 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.IntegerTimeDistribution;
import org.eclipse.app4mc.amalthea.generator.configuration.RTMGCFactory;
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 IntegerTimeDistributionGroup extends IntegerDistributionGroup {
protected final Combo unitCombo;
public IntegerTimeDistributionGroup(Composite parent, String name) {
this(parent, name, 1, TimeUnit.PS);
}
public IntegerTimeDistributionGroup(Composite parent, String name, int avg, TimeUnit unit) {
this(parent, name, DistributionType.CONST, avg, avg, avg, unit);
}
public IntegerTimeDistributionGroup(Composite parent, String name, int min, int max, TimeUnit unit) {
this(parent, name, DistributionType.UNIFORM, min, Math.round((min + max) / 2f), max, unit);
}
public IntegerTimeDistributionGroup(Composite parent, String name, int min, int avg, int max, TimeUnit unit) {
this(parent, name, DistributionType.WEIBULL, min, avg, max, unit);
}
protected IntegerTimeDistributionGroup(Composite parent, String name, DistributionType type, int min, int avg, int max, TimeUnit unit) {
super(parent, name);
super.set(type, min, avg, max);
Label label = new Label(this.group, SWT.NONE);
label.setText("Unit");
label.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
this.unitCombo = new Combo(this.group, SWT.READ_ONLY);
this.unitCombo.setItems(Arrays.stream(TimeUnit.values()).map(Enum::name).toArray(String[]::new));
this.unitCombo.select(unit.getValue());
}
public void set(DistributionType type, int min, int avg, int max, TimeUnit unit) {
super.set(type, min, avg, max);
this.unitCombo.select(unit.getValue());
}
public void set(IntegerTimeDistribution distribution) {
if(null != distribution) {
TimeUnit unit = distribution.getUnit();
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, unit);
}
}
public IntegerTimeDistribution get() {
IntegerTimeDistribution distribution = RTMGCFactory.eINSTANCE.createIntegerTimeDistribution();
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()));
return distribution;
}
}