public code v1

This commit is contained in:
Francisco Jesús Martínez Mimbrera
2026-05-23 00:32:57 +02:00
commit 759a8968a2
4357 changed files with 163763 additions and 0 deletions
@@ -0,0 +1,7 @@
<?flintstones.helper.data.xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>flintstones.group</groupId>
<artifactId>flintstones.bundles</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>flintstones.domain.fuzzyset.ui.dialog</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<name>[bundle] Ui</name>
</project>
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>flintstones.domain.fuzzyset.ui.dialog</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1779484362539</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
@@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
@@ -0,0 +1,25 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: flintstones.domain.fuzzyset.ui.dialog;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: flintstones.domain.fuzzyset;visibility:=reexport,
org.eclipse.jface;visibility:=reexport,
flintstones.domain.numeric.real,
flintstones.helper.ui,
org.eclipse.wb.swt,
flintstones.entity.domain,
javax.inject,
org.eclipse.e4.core.contexts,
org.eclipse.e4.core.di,
flintstones.entity.domain.ui.chart;visibility:=reexport,
flintstones.model.domain.ui.service,
flintstones.entity.domain.ui.dialog,
flintstones.domain.fuzzyset.ui.dialog,
flintstones.domain.fuzzyset.ui.chart,
flintstones.model.ui.service,
flintstones.model.domain.service,
org.eclipse.nebula.widgets.opal.commons,
flintstones.helper.data
Automatic-Module-Name: flintstones.domain.fuzzyset.ui
@@ -0,0 +1,10 @@
#Properties file for flintstones.domain.fuzzyset.ui
Bundle-Name = Ui
chart_ui.icon.linguistic = domain-L.png
chart_ui.icon.hesitant = domain-L.png
new_dialog.description.linguistic.manual = Create domain manually
new_dialog.description.linguistic.auto = Create auto-generated domain
new_dialog.description.hesitant.manual = Create domain manually
new_dialog.description.hesitant.auto = Create auto-generated domain
modify_dialog.description.linguistic.modifymanual = mod manual
modify_dialog.description.linguistic.modifyauto = mod auto
@@ -0,0 +1,10 @@
#Properties file for flintstones.domain.fuzzyset.ui
Bundle-Name = Ui
chart_ui.icon.linguistic = domain-L.png
chart_ui.icon.hesitant = domain-L.png
new_dialog.description.linguistic.manual = Crear dominio manualmente
new_dialog.description.linguistic.auto = Crear dominio autogenerado
new_dialog.description.hesitant.manual = Crear dominio manualmente
new_dialog.description.hesitant.auto = Crear dominio autogenerado
modify_dialog.description.linguistic.modifymanual = mod manual
modify_dialog.description.linguistic.modifyauto = mod auto
@@ -0,0 +1,7 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.xml,\
OSGI-INF/l10n/bundle.properties,\
OSGI-INF/
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<?eclipse version="3.4"?>
<plugin>
<extension
point="flintstones.domain.ui.new.dialog.extensionpoint">
<new_dialog
description="%new_dialog.description.linguistic.manual"
domain="flintstones.domain.linguistic"
uid="flintstones.domain.linguistic.newmanual"
implementation="flintstones.domain.fuzzyset.ui.dialog.ManualLinguisticDomainDialog">
</new_dialog>
<new_dialog
description="%new_dialog.description.linguistic.auto"
domain="flintstones.domain.linguistic"
uid="flintstones.domain.linguistic.newauto"
implementation="flintstones.domain.fuzzyset.ui.dialog.AutoGenerateLinguisticDomainDialog">
</new_dialog>
<new_dialog
description="%new_dialog.description.hesitant.manual"
domain="flintstones.domain.hesitant"
uid="flintstones.domain.hesitant.newmanual"
implementation="flintstones.domain.fuzzyset.ui.dialog.ManualLinguisticDomainDialog">
</new_dialog>
<new_dialog
description="%new_dialog.description.hesitant.auto"
domain="flintstones.domain.hesitant"
uid="flintstones.domain.linguistic.newauto"
implementation="flintstones.domain.fuzzyset.ui.dialog.AutoGenerateLinguisticDomainDialog">
</new_dialog>
</extension>
<extension
point="flintstones.domain.ui.modify.dialog.extensionpoint">
<modify_dialog
description="%modify_dialog.description.linguistic.modifymanual"
domain="flintstones.domain.linguistic"
uid="flintstones.domain.linguistic.modifymanual"
implementation="flintstones.domain.fuzzyset.ui.dialog.ManualLinguisticDomainDialog">
</modify_dialog>
<modify_dialog
description="%modify_dialog.description.linguistic.modifyauto"
domain="flintstones.domain.hesitant"
uid="flintstones.domain.linguistic.modifyauto"
implementation="flintstones.domain.fuzzyset.ui.dialog.ManualLinguisticDomainDialog">
</modify_dialog>
</extension>
</plugin>
@@ -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();
}
}
@@ -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;
}
}
@@ -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();
}
}
@@ -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();
}
}
@@ -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();
}
}
@@ -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;
}
@@ -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
@@ -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