package flintstones.valuation.linguistic.ui; import java.util.ArrayList; import javax.inject.Inject; import org.eclipse.e4.core.services.nls.Translation; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.wb.swt.SWTResourceManager; import flintstones.domain.fuzzyset.FuzzySet; import flintstones.domain.fuzzyset.label.LabelLinguisticDomain; import flintstones.entity.valuation.Valuation; import flintstones.model.ui.service.UiService; import flintstones.model.valuation.service.IValuationService; import flintstones.valuation.linguistic.LinguisticValuation; import flintstones.valuation.linguistic.ui.messages.Messages; import flintstones.valuation.ui.ValuationPanel; @SuppressWarnings("javadoc") public class ValuationPanelLinguistic extends ValuationPanel { private Combo labelCombo; private LabelLinguisticDomain label; @Inject IValuationService valuationService; @Inject @Translation private Messages messages; @Override protected void createControls() { UiService.setGridLayout(this.valuationPart, 1); createBlock1Title(); createBlock2LabelsCombo(); } private void createBlock1Title() { Label titleLabel = new Label(this.valuationPart, SWT.NONE); titleLabel.setFont(SWTResourceManager.getFont("Cantarell", 11, SWT.BOLD)); //$NON-NLS-1$ GridData gd = UiService.setGridData(titleLabel, 0, 0, true, false); gd.verticalIndent = 15; titleLabel.setText(this.messages.Linguistic_evaluation); titleLabel.setBackground(new Color(Display.getCurrent(), 255, 255, 255)); } private void createBlock2LabelsCombo() { ArrayList labelsName = ((FuzzySet) this.domain).getLabelSet().getLabelsName(); this.labelCombo = new Combo(this.valuationPart, SWT.BORDER | SWT.READ_ONLY); GridData gd = UiService.setGridData(this.labelCombo, 0, 1, false, false); gd.verticalIndent = 10; this.labelCombo.setItems(labelsName.toArray(new String[0])); this.labelCombo.setBackground(new Color(Display.getCurrent(), 255, 255, 255)); selectComboLabel(); this.labelCombo.addModifyListener(e -> { ValuationPanelLinguistic.this.label = ((FuzzySet) ValuationPanelLinguistic.this.domain) .getLabelSet() .getLabel(ValuationPanelLinguistic.this.labelCombo.getText()); ValuationPanelLinguistic.this.selectionChange(); }); } private void selectComboLabel() { int pos = 0; if (this.valuation != null && this.valuation instanceof LinguisticValuation) { this.label = ((LinguisticValuation) this.valuation).getLabel(); pos = ((FuzzySet) this.domain).getLabelSet().getPos(this.label); } else this.label = ((FuzzySet) this.domain).getLabelSet().getLabel(pos); this.labelCombo.select(pos); this.selectionChange(); } @Override public Object getSelection() { return this.labelCombo.getSelectionIndex(); } @Override public Valuation createNewValuation() { LinguisticValuation result = null; if (this.valuation == null) { result = (LinguisticValuation) this.valuationService.create(this.domain); result.setDomain(this.domain); } else result = (LinguisticValuation) this.valuation.clone(); result.setLabel(this.label); result.setEvaluated(true); return result; } }