public code v1
This commit is contained in:
+199
@@ -0,0 +1,199 @@
|
||||
|
||||
package flintstones.domain.fuzzyset.ui.dialog;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.e4.core.services.nls.Translation;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import flintstones.domain.fuzzyset.FuzzySet;
|
||||
import flintstones.domain.fuzzyset.ui.chart.LinguisticDomainChart;
|
||||
import flintstones.domain.fuzzyset.ui.messages.Messages;
|
||||
import flintstones.entity.domain.ui.dialog.DomainDialog;
|
||||
import flintstones.helper.ui.components.WCollector;
|
||||
import flintstones.helper.ui.components.WLabel;
|
||||
import flintstones.helper.ui.components.listeners.WEvent;
|
||||
import flintstones.helper.ui.components.listeners.WItemBeforeOperation;
|
||||
import flintstones.helper.ui.components.listeners.WItemChanged;
|
||||
import flintstones.model.domain.ui.service.IDomainUIService;
|
||||
import flintstones.model.ui.service.UiService;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class AutoGenerateLinguisticDomainDialog extends DomainDialog implements WItemChanged, WItemBeforeOperation {
|
||||
|
||||
private static final String NUMBER_LABELS = "labels";
|
||||
|
||||
private Composite base;
|
||||
private Composite chartRow;
|
||||
|
||||
private LinguisticDomainChart domainChart;
|
||||
|
||||
// NEW
|
||||
WCollector collector;
|
||||
|
||||
// ERROR
|
||||
private final HashMap<String, WLabel> errorLabels = new HashMap<>();
|
||||
|
||||
@Inject
|
||||
@Translation
|
||||
private Messages messages;
|
||||
|
||||
@Inject
|
||||
IDomainUIService uiDomainService;
|
||||
|
||||
public AutoGenerateLinguisticDomainDialog() {
|
||||
super();
|
||||
}
|
||||
|
||||
protected void beforeUI() {
|
||||
|
||||
// LOCAL
|
||||
FuzzySet domain = (FuzzySet) getMyDomain();
|
||||
domain.setName(domain.getName() == null ? "" : domain.getName()); //$NON-NLS-1$
|
||||
|
||||
// CHART
|
||||
this.domainChart = (LinguisticDomainChart) this.uiDomainService.createChart(domain.getType());
|
||||
this.domainChart.initialize(domain, this.chartRow, 470, 150, SWT.BORDER);
|
||||
this.redraw();
|
||||
}
|
||||
|
||||
private FuzzySet getMyDomain() {
|
||||
return (FuzzySet) getDomain();
|
||||
}
|
||||
|
||||
private void addErrorLabel(Composite base, String asociatedItemId) {
|
||||
Composite subBase = new Composite(base, SWT.NONE);
|
||||
UiService.setGridLayout(subBase, 1);
|
||||
UiService.setGridDataAuto(subBase);
|
||||
WLabel nameLabelError = new WLabel(subBase, SWT.NONE);
|
||||
UiService.setGridData(nameLabelError, -1, 0, true, false);
|
||||
UiService.setFont(nameLabelError, UiService.FONT_TEXT_ERROR);
|
||||
this.errorLabels.put(asociatedItemId, nameLabelError);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Control createDialogArea(Composite base) {
|
||||
super.createDialogArea(base);
|
||||
|
||||
for (Control c : base.getChildren())
|
||||
c.dispose();
|
||||
//
|
||||
UiService.setGridLayout(base, 1);
|
||||
UiService.setGridData(base, 9, 9, true, true);
|
||||
|
||||
this.drawBlock1DomainName(base);
|
||||
this.drawBlock2CollectorLabels(base);
|
||||
this.drawBlock3Chart(base);
|
||||
|
||||
return this.base;
|
||||
}
|
||||
|
||||
private void drawBlock1DomainName(Composite base) {
|
||||
this.addNameField(base);
|
||||
}
|
||||
|
||||
|
||||
private void drawBlock2CollectorLabels(Composite base) {
|
||||
// TITLE BLOCK 2
|
||||
Composite row2 = new Composite(base, SWT.NONE);
|
||||
UiService.setGridData(row2, 9, -1, true, false);
|
||||
UiService.setGridLayout(row2, 2);
|
||||
|
||||
Label collectorTitle = new Label(row2, 0);
|
||||
collectorTitle.setText(messages.Labels_name);
|
||||
UiService.setGridData(collectorTitle, -1, 0, false, false);
|
||||
UiService.setFont(collectorTitle, UiService.FONT_SECTION_TITLE);
|
||||
|
||||
// ERROR BLOCK 1: name
|
||||
this.addErrorLabel(row2, AutoGenerateLinguisticDomainDialog.NUMBER_LABELS);
|
||||
|
||||
collector = new WCollector(base);
|
||||
collector.setBeforeOperationListener(this);
|
||||
collector.setChangeListener(this);
|
||||
}
|
||||
|
||||
private void drawBlock3Chart(Composite base) {
|
||||
|
||||
// LABEL
|
||||
Composite row1 = new Composite(base, SWT.NONE);
|
||||
UiService.setGridLayout(row1, 1);
|
||||
UiService.setGridData(row1, 9, 9, true, true);
|
||||
|
||||
Label nameLabel = new Label(row1, SWT.NONE);
|
||||
nameLabel.setText(this.messages.Preview);
|
||||
UiService.setGridData(nameLabel, -1, 0, true, false);
|
||||
UiService.setFont(nameLabel, UiService.FONT_SECTION_TITLE);
|
||||
|
||||
// CHART
|
||||
this.chartRow = new Composite(row1, SWT.NONE);
|
||||
UiService.setGridData(this.chartRow, 9, 9, true, true);
|
||||
UiService.setGridLayout(this.chartRow, 1);
|
||||
}
|
||||
|
||||
private void redraw() {
|
||||
// ROW 3
|
||||
FuzzySet domain = getMyDomain();
|
||||
this.domainChart.setDomain(domain);
|
||||
|
||||
boolean ok = checkLabelsName();
|
||||
setSaveEnabled(ok);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private boolean checkLabelsName() {
|
||||
boolean checkLabelsAreValid = true;
|
||||
|
||||
String[] labels = collector.getData();
|
||||
if(labels.length < FuzzySet.MINIMUM_NUMBER_LABELS) {
|
||||
String msg = MessageFormat.format(messages.Labels_empty, FuzzySet.MINIMUM_NUMBER_LABELS);
|
||||
errorLabels.get(AutoGenerateLinguisticDomainDialog.NUMBER_LABELS).setText(msg);
|
||||
checkLabelsAreValid = false;
|
||||
}
|
||||
|
||||
if(checkLabelsAreValid)
|
||||
errorLabels.get(AutoGenerateLinguisticDomainDialog.NUMBER_LABELS).clear();
|
||||
|
||||
return checkLabelsAreValid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldBeExecuted(WEvent operationType, String before, String after) {
|
||||
String[] labels = collector.getData();
|
||||
|
||||
if (operationType.equals(WEvent.ADD))
|
||||
return !Arrays.asList(labels).contains(before);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Point getInitialSize() {
|
||||
return new Point(510, 700);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureShell(Shell newShell) {
|
||||
super.configureShell(newShell);
|
||||
newShell.setText(this.messages.Auto_generated_domain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWidgetChange() {
|
||||
FuzzySet domain = getMyDomain();
|
||||
String[] labels = collector.getData();
|
||||
domain.createTrapezoidalFunction(labels);
|
||||
domainChart.setDomain(domain);
|
||||
checkLabelsName();
|
||||
redraw();
|
||||
}
|
||||
|
||||
}
|
||||
+519
@@ -0,0 +1,519 @@
|
||||
|
||||
package flintstones.domain.fuzzyset.ui.dialog;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.e4.core.contexts.IEclipseContext;
|
||||
import org.eclipse.e4.core.services.nls.Translation;
|
||||
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
||||
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
||||
import org.eclipse.jface.viewers.StructuredSelection;
|
||||
import org.eclipse.jface.viewers.TableViewer;
|
||||
import org.eclipse.jface.viewers.TableViewerColumn;
|
||||
import org.eclipse.nebula.widgets.opal.commons.SWTGraphicUtil;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.ModifyListener;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.events.SelectionListener;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.swt.widgets.Table;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
||||
import flintstones.domain.fuzzyset.FuzzySet;
|
||||
import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction;
|
||||
import flintstones.domain.fuzzyset.label.LabelLinguisticDomain;
|
||||
import flintstones.domain.fuzzyset.ui.chart.LinguisticDomainChart;
|
||||
import flintstones.domain.fuzzyset.ui.dialog.provider.FuzzyNameColumnLabelProvider;
|
||||
import flintstones.domain.fuzzyset.ui.dialog.provider.FuzzySemanticColumnLabelProvider;
|
||||
import flintstones.domain.fuzzyset.ui.dialog.provider.FuzzyTableContentProvider;
|
||||
import flintstones.domain.fuzzyset.ui.messages.Messages;
|
||||
import flintstones.entity.domain.ui.dialog.DomainDialog;
|
||||
import flintstones.helper.DoubleHelper;
|
||||
import flintstones.helper.ui.components.ValidatedField;
|
||||
import flintstones.helper.ui.components.WCollector;
|
||||
import flintstones.helper.ui.components.listeners.WEvent;
|
||||
import flintstones.helper.ui.components.listeners.WItemBeforeOperation;
|
||||
import flintstones.helper.ui.components.listeners.WItemChanged;
|
||||
import flintstones.helper.ui.components.listeners.WItemOperation;
|
||||
import flintstones.model.domain.ui.service.IDomainUIService;
|
||||
import flintstones.model.ui.service.UiService;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class ManualLinguisticDomainDialog extends DomainDialog implements WItemChanged, WItemBeforeOperation {
|
||||
|
||||
private int selectionIndex = -1;
|
||||
private boolean isCreating; // If not creating then modify.
|
||||
|
||||
// STATIC/PARENT
|
||||
private Composite container;
|
||||
private Composite chartRow;
|
||||
private Composite collectorComposite;
|
||||
boolean isCollectorEnabled = true;
|
||||
|
||||
private LabelLinguisticDomain label = new LabelLinguisticDomain();
|
||||
|
||||
private TableViewer tableViewer;
|
||||
|
||||
private LinguisticDomainChart domainChart;
|
||||
|
||||
private Button addButton;
|
||||
private Button modifyButton;
|
||||
private Button removeButton;
|
||||
private Button deselectButton;
|
||||
|
||||
// NEW
|
||||
WCollector collector;
|
||||
ValidatedField tagField;
|
||||
|
||||
@Inject
|
||||
@Translation
|
||||
private Messages messages;
|
||||
|
||||
@Inject
|
||||
IDomainUIService uiDomainService;
|
||||
|
||||
@Inject
|
||||
IEclipseContext context;
|
||||
|
||||
public ManualLinguisticDomainDialog() {
|
||||
super();
|
||||
}
|
||||
|
||||
private FuzzySet getMyDomain() {
|
||||
return (FuzzySet) getDomain();
|
||||
}
|
||||
|
||||
protected void beforeUI() {
|
||||
|
||||
// LOCAL
|
||||
FuzzySet domain = getMyDomain();
|
||||
domain.setName(domain.getName() == null ? "" : domain.getName()); //$NON-NLS-1$
|
||||
this.tableViewer.setInput(domain);
|
||||
|
||||
// CHART
|
||||
this.domainChart = (LinguisticDomainChart) this.uiDomainService.createChart(domain.getType());
|
||||
this.domainChart.initialize(domain, this.chartRow, 600, 150, SWT.BORDER);
|
||||
this.redraw();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Control createDialogArea(Composite parent) {
|
||||
|
||||
this.container = (Composite) super.createDialogArea(parent);
|
||||
|
||||
this.drawBlock1DomainName();
|
||||
this.drawBlock2CollectorLabels();
|
||||
this.drawBlock3Chart();
|
||||
|
||||
return this.container;
|
||||
}
|
||||
|
||||
private void drawBlock1DomainName() {
|
||||
this.addNameField(container);
|
||||
}
|
||||
|
||||
private boolean checkLabelName() {
|
||||
|
||||
// 1. label name should not be not empty
|
||||
if (this.label.getName().equals("")) { //$NON-NLS-1$
|
||||
tagField.setError(messages.Empty_value);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 2. label name should be new except if we are modifying a created label
|
||||
if (getMyDomain().getLabelSet().getLabel(this.label.getName()) != null) {
|
||||
if(this.selectionIndex != -1) { // label selected
|
||||
|
||||
if(getMyDomain().getLabelSet().getPos(this.label.getName()) != this.selectionIndex) { // name repeated with other label
|
||||
tagField.setError(messages.Duplicated_name);
|
||||
return false;
|
||||
}
|
||||
|
||||
} else {
|
||||
tagField.setError(messages.Duplicated_name);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 3. No problems in label
|
||||
tagField.setError("");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean checkNumLabels() {
|
||||
return getMyDomain().getLabelSet().getCardinality() >= 3;
|
||||
}
|
||||
|
||||
private void drawBlock2CollectorLabels() {
|
||||
|
||||
UiService.setMargin(container, 0);
|
||||
|
||||
tagField = new ValidatedField(container, messages.Labels, "");
|
||||
tagField.getInput().addModifyListener(this.nameLabelsInputOnChange());
|
||||
|
||||
Composite tableViewerComposite = new Composite(this.container, SWT.NONE);
|
||||
UiService.setGridLayout(tableViewerComposite, 2);
|
||||
UiService.setGridData(tableViewerComposite, 9, 9, true, false);
|
||||
|
||||
createCollectorLabels(tableViewerComposite);
|
||||
createTableViewer(tableViewerComposite);
|
||||
|
||||
Composite globalButtonsComposite = new Composite(container, SWT.NONE);
|
||||
UiService.setGridLayout(globalButtonsComposite, 2);
|
||||
UiService.setGridData(globalButtonsComposite, 9, 9, true, false);
|
||||
|
||||
createButtons(globalButtonsComposite);
|
||||
}
|
||||
|
||||
private ModifyListener nameLabelsInputOnChange() {
|
||||
return e -> {
|
||||
String name = ((Text) e.getSource()).getText().trim();
|
||||
label.setName(name);
|
||||
|
||||
redraw();
|
||||
};
|
||||
}
|
||||
|
||||
private void createButtons(Composite globalButtonsComposite) {
|
||||
Composite buttonsComposite = new Composite(globalButtonsComposite, SWT.NONE);
|
||||
UiService.setGridLayout(buttonsComposite, 3);
|
||||
UiService.setGridData(buttonsComposite, 9, 9, true, false);
|
||||
|
||||
addButton = new Button(buttonsComposite, SWT.NONE);
|
||||
addButton.setText(this.messages.Add);
|
||||
addButton.setImage(UiService.getIcon(UiService.IMAGE_CONTROLS_ADD).createImage());
|
||||
addButton.setEnabled(false);
|
||||
addButton.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
addTag();
|
||||
}
|
||||
});
|
||||
|
||||
modifyButton = new Button(buttonsComposite, SWT.NONE);
|
||||
modifyButton.setText(messages.Modify);
|
||||
modifyButton.setImage(UiService.getIcon(UiService.IMAGE_CONTROLS_EDIT).createImage());
|
||||
modifyButton.setEnabled(false);
|
||||
modifyButton.addSelectionListener(modifySelectionListener());
|
||||
|
||||
removeButton = new Button(buttonsComposite, SWT.NONE);
|
||||
removeButton.setText(messages.Remove);
|
||||
removeButton.setImage(UiService.getIcon(UiService.IMAGE_CONTROLS_REMOVE).createImage());
|
||||
removeButton.setEnabled(false);
|
||||
removeButton.addSelectionListener(removeSelectionListener());
|
||||
|
||||
Composite deselectButtonComposite = new Composite(globalButtonsComposite, SWT.NONE);
|
||||
UiService.setGridLayout(deselectButtonComposite, 1);
|
||||
UiService.setGridData(deselectButtonComposite, 9, 9, true, false);
|
||||
|
||||
deselectButton = new Button(deselectButtonComposite, SWT.NONE);
|
||||
deselectButton.setText(messages.Deselect);
|
||||
deselectButton.setImage(UiService.getIcon(UiService.IMAGE_CONTROLS_DESELECT).createImage());
|
||||
deselectButton.setEnabled(false);
|
||||
UiService.setGridData(deselectButton, 1, 0, true, false);
|
||||
deselectButton.addSelectionListener(deselectSelectionListener());
|
||||
}
|
||||
|
||||
private void createTableViewer(Composite tableViewerComposite) {
|
||||
this.tableViewer = new TableViewer(tableViewerComposite, SWT.BORDER | SWT.FULL_SELECTION);
|
||||
this.tableViewer.setContentProvider(new FuzzyTableContentProvider());
|
||||
|
||||
Table table = this.tableViewer.getTable();
|
||||
table.setHeaderVisible(true);
|
||||
table.setLinesVisible(true);
|
||||
GridData gd_table = UiService.setGridData(table, -1, 1, false, false);
|
||||
gd_table.heightHint = 160;
|
||||
this.tableViewer.setInput(getMyDomain());
|
||||
|
||||
TableViewerColumn tableViewerNameCol = new TableViewerColumn(this.tableViewer, SWT.NONE);
|
||||
tableViewerNameCol.getColumn().setWidth(140);
|
||||
tableViewerNameCol.getColumn().setText(this.messages.Name);
|
||||
tableViewerNameCol.setLabelProvider(new FuzzyNameColumnLabelProvider());
|
||||
|
||||
TableViewerColumn tableViewerSemanticCol = new TableViewerColumn(this.tableViewer, SWT.NONE);
|
||||
tableViewerSemanticCol.getColumn().setWidth(140);
|
||||
tableViewerSemanticCol.getColumn().setText(this.messages.Semantic);
|
||||
tableViewerSemanticCol.setLabelProvider(new FuzzySemanticColumnLabelProvider());
|
||||
|
||||
this.tableViewer.addSelectionChangedListener(tableSelectionListener());
|
||||
}
|
||||
|
||||
private ISelectionChangedListener tableSelectionListener() {
|
||||
return new ISelectionChangedListener() {
|
||||
@Override
|
||||
public void selectionChanged(SelectionChangedEvent event) {
|
||||
|
||||
int posSelectedLabel = tableViewer.getTable().getSelectionIndex();
|
||||
|
||||
if(selectionIndex != posSelectedLabel && posSelectedLabel != -1)
|
||||
loadLabelInfo(posSelectedLabel);
|
||||
|
||||
addButton.setEnabled(checkAddButton());
|
||||
modifyButton.setEnabled(checkModifyButton());
|
||||
removeButton.setEnabled(checkRemoveButton());
|
||||
deselectButton.setEnabled(true);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void loadLabelInfo(int posSelectedLabel) {
|
||||
LabelLinguisticDomain selectedLabel = getMyDomain().getLabelSet().getLabel(posSelectedLabel);
|
||||
|
||||
TrapezoidalFunction semantic = (TrapezoidalFunction) selectedLabel.getSemantic();
|
||||
ArrayList<String> values = new ArrayList<String>(Arrays.asList(
|
||||
Double.toString(semantic.getA()),
|
||||
Double.toString(semantic.getB()),
|
||||
Double.toString(semantic.getC()),
|
||||
Double.toString(semantic.getD())));
|
||||
|
||||
collector.setValues(values);
|
||||
|
||||
selectionIndex = posSelectedLabel;
|
||||
|
||||
tagField.setText(selectedLabel.getName());
|
||||
}
|
||||
|
||||
private void createCollectorLabels(Composite tableViewerComposite) {
|
||||
|
||||
collectorComposite = new Composite(tableViewerComposite, 0);
|
||||
UiService.setGridLayout(collectorComposite, 1);
|
||||
UiService.setGridDataAuto(collectorComposite);
|
||||
UiService.setMargin(collectorComposite, 0);
|
||||
|
||||
collector = new WCollector(collectorComposite);
|
||||
collector.setBeforeOperationListener(this);
|
||||
collector.setChangeListener(this);
|
||||
collector.setOperationListener(new WItemOperation() {
|
||||
|
||||
@Override
|
||||
public String getModifiedValue(WEvent operationType, String before, String after) {
|
||||
|
||||
if (operationType.equals(WEvent.ADD)) {
|
||||
return DoubleHelper.NormalizeZeroToOne(before) + ""; //$NON-NLS-1$
|
||||
}
|
||||
return after;
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void addTag() {
|
||||
setSemanticToLabel(label);
|
||||
getMyDomain().addLabel(label);
|
||||
domainChart.refreshChart();
|
||||
tableViewer.setInput(getMyDomain());
|
||||
|
||||
addButton.setEnabled(false);
|
||||
|
||||
clearLabelInfo();
|
||||
}
|
||||
|
||||
private void clearLabelInfo() {
|
||||
collector.clear();
|
||||
label = new LabelLinguisticDomain();
|
||||
tagField.setText("");
|
||||
|
||||
addButton.setEnabled(false);
|
||||
removeButton.setEnabled(false);
|
||||
modifyButton.setEnabled(false);
|
||||
deselectButton.setEnabled(false);
|
||||
}
|
||||
|
||||
private void setSemanticToLabel(LabelLinguisticDomain selectedLabel) {
|
||||
String[] labels = collector.getData();
|
||||
TrapezoidalFunction semantic = new TrapezoidalFunction(Double.parseDouble(labels[0]),
|
||||
Double.parseDouble(labels[1]), Double.parseDouble(labels[2]), Double.parseDouble(labels[3]));
|
||||
selectedLabel.setSemantic(semantic);
|
||||
}
|
||||
|
||||
private SelectionListener modifySelectionListener() {
|
||||
return new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
LabelLinguisticDomain selectedLabel = getMyDomain().getLabelSet().getLabel(selectionIndex);
|
||||
selectedLabel.setName(tagField.getText());
|
||||
setSemanticToLabel(selectedLabel);
|
||||
|
||||
getMyDomain().getLabelSet().removeLabel(selectedLabel);
|
||||
getMyDomain().getLabelSet().addLabel(selectedLabel);
|
||||
|
||||
domainChart.refreshChart();
|
||||
tableViewer.setInput(getMyDomain());
|
||||
|
||||
redraw();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private SelectionListener removeSelectionListener() {
|
||||
return new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
getMyDomain().removeLabel(ManualLinguisticDomainDialog.this.selectionIndex);
|
||||
domainChart.refreshChart();
|
||||
tableViewer.setInput(getMyDomain());
|
||||
selectionIndex = -1;
|
||||
|
||||
clearLabelInfo();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private SelectionListener deselectSelectionListener() {
|
||||
return new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
tableViewer.setSelection(StructuredSelection.EMPTY);
|
||||
tableViewer.getTable().deselectAll();
|
||||
selectionIndex = -1;
|
||||
|
||||
clearLabelInfo();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void drawBlock3Chart() {
|
||||
|
||||
// LABEL
|
||||
Composite row1 = new Composite(container, SWT.NONE);
|
||||
UiService.setGridLayout(row1, 1);
|
||||
UiService.setGridData(row1, 9, 9, true, true);
|
||||
|
||||
Label nameLabel = new Label(row1, SWT.NONE);
|
||||
nameLabel.setText(this.messages.Preview);
|
||||
UiService.setGridData(nameLabel, -1, 0, true, false);
|
||||
UiService.setFont(nameLabel, UiService.FONT_SECTION_TITLE);
|
||||
|
||||
// CHART
|
||||
this.chartRow = new Composite(row1, SWT.NONE);
|
||||
UiService.setGridData(this.chartRow, 9, 9, true, true);
|
||||
UiService.setGridLayout(this.chartRow, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Point getInitialSize() {
|
||||
return new Point(670, 720);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureShell(Shell newShell) {
|
||||
super.configureShell(newShell);
|
||||
String title = this.isCreating ? this.messages.Manually_create_domain : this.messages.Manually_create_domain;
|
||||
|
||||
newShell.setText(title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldBeExecuted(WEvent operationType, String before, String after) {
|
||||
|
||||
if (operationType.equals(WEvent.ADD)) {
|
||||
String[] labels = collector.getData();
|
||||
|
||||
if (labels.length == 4) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
Double num = Double.parseDouble(before);
|
||||
if (num < 0.0)
|
||||
return false;
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWidgetChange() {
|
||||
ArrayList<String> semanticPoints = orderSemanticPoints();
|
||||
collector.setValues(semanticPoints);
|
||||
addButton.setEnabled(checkAddButton());
|
||||
}
|
||||
|
||||
private void redraw() {
|
||||
|
||||
// ROW 2
|
||||
String labelName = this.label.getName();
|
||||
tagField.setText(labelName);
|
||||
|
||||
if (tagField.getText().equals("")) {
|
||||
if (isCollectorEnabled) {
|
||||
SWTGraphicUtil.disableAllChildrenWidgets(collectorComposite);
|
||||
isCollectorEnabled = false;
|
||||
}
|
||||
} else {
|
||||
if (!isCollectorEnabled) {
|
||||
SWTGraphicUtil.enableAllChildrenWidgets(collectorComposite);
|
||||
isCollectorEnabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
// ROW 3
|
||||
this.domainChart.setDomain(getMyDomain());
|
||||
boolean ok = checkNumLabels();
|
||||
setSaveEnabled(ok);
|
||||
}
|
||||
|
||||
private ArrayList<String> orderSemanticPoints() {
|
||||
Double[] orderedSemanticPoints = parseSemanticPoints();
|
||||
Arrays.sort(orderedSemanticPoints);
|
||||
|
||||
ArrayList<String> semanticPoints = new ArrayList<>();
|
||||
for (Double point : orderedSemanticPoints)
|
||||
semanticPoints.add(Double.toString(point));
|
||||
|
||||
return semanticPoints;
|
||||
}
|
||||
|
||||
private Double[] parseSemanticPoints() {
|
||||
String[] semanticStringPoints = collector.getData();
|
||||
Double[] semanticDoublePoints = new Double[semanticStringPoints.length];
|
||||
|
||||
int cont = 0;
|
||||
for (String point : semanticStringPoints) {
|
||||
semanticDoublePoints[cont] = Double.parseDouble(point);
|
||||
cont++;
|
||||
}
|
||||
|
||||
return semanticDoublePoints;
|
||||
}
|
||||
|
||||
private boolean checkAddButton() {
|
||||
String[] labels = collector.getData();
|
||||
|
||||
boolean checkLabelName = checkLabelName();
|
||||
boolean checkNumLabels = labels.length != 4 ? false : true;
|
||||
|
||||
|
||||
return checkLabelName && checkNumLabels && selectionIndex == -1;
|
||||
}
|
||||
|
||||
private boolean checkModifyButton() {
|
||||
if(this.selectionIndex != -1) {
|
||||
int pos = getMyDomain().getLabelSet().getPos(this.label.getName());
|
||||
if(pos == this.selectionIndex || pos == -1)// name repeated with the selected label or name not repeated
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean checkRemoveButton() {
|
||||
return (selectionIndex != -1) ? true : false;
|
||||
}
|
||||
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package flintstones.domain.fuzzyset.ui.dialog.provider;
|
||||
|
||||
import org.eclipse.jface.viewers.ColumnLabelProvider;
|
||||
|
||||
import flintstones.domain.fuzzyset.label.LabelLinguisticDomain;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class FuzzyNameColumnLabelProvider extends ColumnLabelProvider {
|
||||
|
||||
@Override
|
||||
public String getText(Object element) {
|
||||
LabelLinguisticDomain label = (LabelLinguisticDomain) element;
|
||||
return label.getName();
|
||||
}
|
||||
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package flintstones.domain.fuzzyset.ui.dialog.provider;
|
||||
|
||||
import org.eclipse.jface.viewers.ColumnLabelProvider;
|
||||
|
||||
import flintstones.domain.fuzzyset.label.LabelLinguisticDomain;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class FuzzySemanticColumnLabelProvider extends ColumnLabelProvider {
|
||||
|
||||
@Override
|
||||
public String getText(Object element) {
|
||||
LabelLinguisticDomain label = (LabelLinguisticDomain) element;
|
||||
return label.getSemantic().toString();
|
||||
}
|
||||
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package flintstones.domain.fuzzyset.ui.dialog.provider;
|
||||
|
||||
import org.eclipse.jface.viewers.IStructuredContentProvider;
|
||||
import org.eclipse.jface.viewers.Viewer;
|
||||
|
||||
import flintstones.domain.fuzzyset.FuzzySet;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class FuzzyTableContentProvider implements IStructuredContentProvider {
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getElements(Object inputElement) {
|
||||
return ((FuzzySet) inputElement).getLabelSet()
|
||||
.getLabels()
|
||||
.toArray();
|
||||
}
|
||||
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
// This file has been auto-generated
|
||||
package flintstones.domain.fuzzyset.ui.messages;
|
||||
|
||||
import org.eclipse.e4.core.services.nls.Message;
|
||||
|
||||
@Message
|
||||
@SuppressWarnings("javadoc")
|
||||
public class Messages {
|
||||
|
||||
public String PlainFuzzySetChart_template_left;
|
||||
public String PlainFuzzySetChart_template_right;
|
||||
public String Domain_name;
|
||||
public String Insert_label_names_with_separator_colon;
|
||||
public String Preview;
|
||||
public String Auto_generated_domain;
|
||||
public String Empty_domain;
|
||||
public String Duplicated_id;
|
||||
public String Empty_value;
|
||||
public String Labels;
|
||||
public String Name;
|
||||
public String Semantic;
|
||||
public String Manually_create_domain;
|
||||
public String Add;
|
||||
public String Add_label;
|
||||
public String Modify;
|
||||
public String Modify_label;
|
||||
public String Remove;
|
||||
public String Remove_label;
|
||||
public String Label_name;
|
||||
public String Labels_name;
|
||||
public String Labels_empty;
|
||||
public String Trapezoidal;
|
||||
public String Values;
|
||||
public String Duplicated_name;
|
||||
public String Invalid_value;
|
||||
public String Value_lower_than_the_previous;
|
||||
public String Deselect;
|
||||
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
Auto_generated_domain=Auto-generated domain
|
||||
Empty_domain=Empty domain
|
||||
Insert_label_names_with_separator_colon=Insert label names with separator ':'
|
||||
PlainFuzzySetChart_template_left={0}_left
|
||||
PlainFuzzySetChart_template_right={0}_right
|
||||
Duplicated_name=Duplicated name
|
||||
Invalid_value=Invalid value
|
||||
Label_name=Label name
|
||||
Labels_name=Labels name
|
||||
Trapezoidal=Trapezoidal
|
||||
Value_lower_than_the_previous=Value lower than the previous
|
||||
Labels_empty=Introduce at least {0} labels
|
||||
Values=Values
|
||||
Add=Add
|
||||
Add_label=Add label
|
||||
Domain_name=Domain name
|
||||
Duplicated_id=Duplicated name
|
||||
Empty_value=Empty value
|
||||
Labels=Labels
|
||||
Manually_create_domain= Create domain manually
|
||||
Modify=Modify
|
||||
Modify_label=Modify label
|
||||
Name=Name
|
||||
Preview=Preview
|
||||
Remove=Remove
|
||||
Remove_label=Remove label
|
||||
Semantic=Semantic
|
||||
Deselect=Deselect
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
Auto_generated_domain=Dominio auto generado
|
||||
Domain_name=Nombre de dominio
|
||||
Duplicated_id=Id duplicado
|
||||
Empty_domain=Dominio vacio
|
||||
Empty_value=Valor vacio
|
||||
Insert_label_names_with_separator_colon=Inserta las etiquetas separadas por ':'
|
||||
PlainFuzzySetChart_template_left={0}_left
|
||||
PlainFuzzySetCharttemplate_right={0}_right
|
||||
Duplicated_name=Nombre duplicado
|
||||
Invalid_value=Valor no valido
|
||||
Label_name=Nombre de la etiqueta
|
||||
Labels_name=Nombre de las etiquetas
|
||||
Preview=Previsualización
|
||||
Semantic=Semantica
|
||||
Trapezoidal=Trapezoidal
|
||||
Value_lower_than_the_previous=Valor inferior que el previo
|
||||
Labels_empty=Introduce al menos {0} etiquetas
|
||||
Values=Valores
|
||||
Add=Añadir
|
||||
Add_label=Añadir etiqueta
|
||||
Labels=Etiquetas
|
||||
Manually_create_domain=Crear dominio manualmente
|
||||
Modify=Modificar
|
||||
Modify_label=Modificar etiqueta
|
||||
Name=Nombre
|
||||
Remove=Eliminar
|
||||
Remove_label=Eliminar etiqueta
|
||||
Deselect=Deseleccionar
|
||||
Reference in New Issue
Block a user