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,347 @@
package flintstones.domain.numeric.ui.dialog;
import java.util.ArrayList;
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.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Point;
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.Spinner;
import flintstones.domain.numeric.NumericDomain;
import flintstones.domain.numeric.ui.dialog.messages.Messages;
import flintstones.entity.domain.ui.chart.DomainChart;
import flintstones.entity.domain.ui.dialog.DomainDialog;
import flintstones.helper.ui.components.WLabel;
import flintstones.model.domain.ui.service.IDomainUIService;
import flintstones.model.ui.service.UiService;
public class UpsertNumericDomainDialog extends DomainDialog {
@Inject
IDomainUIService uiDomainService;
@Inject
@Translation
private Messages messages;
// UI STATE
private Composite spinnersRow;
private Button hasLimitsCB;
private Composite chartRow;
private DomainChart domainChart;
private Spinner lower;
private Spinner upper;
// ERROR
private final HashMap<String, WLabel> errorLabels = new HashMap<>();
private final HashMap<String, Control> errorControls = new HashMap<>();
// Variants
private boolean isInteger; // If it is not integer, is real
private boolean isCreating; // If not creating then modify.
private boolean isIntervalar;
/**
* Necesary builder?
*/
public UpsertNumericDomainDialog() {
}
/**
* @param isInteger if true is integer, if not, is real
*/
public UpsertNumericDomainDialog(boolean isInteger) {
this.isInteger = isInteger;
}
public NumericDomain getMyDomain() {
return (NumericDomain) this.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.drawBlock2Limits(base);
this.drawBlock3Chart(base);
return base;
}
private void drawBlock1DomainName(Composite base) {
this.addNameField(base);
}
private void drawBlock2Limits(Composite base) {
Composite row1 = new Composite(base, SWT.NONE);
UiService.setGridLayout(row1, 3);
UiService.setGridData(row1, 9, 1, true, false);
// LABEL
WLabel nameLabel = new WLabel(row1, SWT.NULL);
nameLabel.setText(this.messages.limits);
UiService.setGridData(nameLabel, -1, 0, false, false);
UiService.setFont(nameLabel, UiService.FONT_SECTION_TITLE);
// CHECKBOX
this.hasLimitsCB = new Button(row1, SWT.CHECK);
UiService.setGridData(this.hasLimitsCB, -1, 0, false, false);
this.hasLimitsCB.setText(this.messages.rangeless);
this.hasLimitsCB.addSelectionListener(this.hasLimitsOnClick());
// ERROR: Limits
this.addErrorLabel(row1, this.messages.error_limits);
// SPINNER - LABEL - SPINNER
this.spinnersRow = new Composite(base, SWT.NONE);
UiService.setGridData(this.spinnersRow, 9, 9, true, false);
UiService.setGridLayout(this.spinnersRow, 3);
this.lower = new Spinner(this.spinnersRow, SWT.BORDER);
UiService.setGridData(this.lower, 9, 0, true, false);
this.errorControls.put(this.messages.error_limits1, this.lower);
Label toLabel = new Label(this.spinnersRow, SWT.NONE);
toLabel.setText(this.messages.to);
this.upper = new Spinner(this.spinnersRow, SWT.BORDER);
UiService.setGridData(this.upper, 9, 0, true, false);
this.errorControls.put(this.messages.error_limits2, this.upper);
if (this.isInteger) {
// Nothing? Default set up seems to work just fine with integers
} else {
this.lower.setDigits(2);
this.lower.setIncrement(10);
this.lower.setSelection((int) (0 * 100d));
this.upper.setDigits(2);
this.upper.setIncrement(10);
this.upper.setSelection((int) (0 * 100d));
}
// Same for integer and real
this.lower.setMinimum(Integer.MIN_VALUE);
this.lower.setMaximum(Integer.MAX_VALUE);
this.upper.setMinimum(Integer.MIN_VALUE);
this.upper.setMaximum(Integer.MAX_VALUE);
this.lower.addModifyListener(this.lowerLimitModifyListener());
this.upper.addModifyListener(this.upperLimitModifyListener());
}
private ModifyListener lowerLimitModifyListener() {
return e -> {
Spinner c = (Spinner) e.widget;
if (UpsertNumericDomainDialog.this.isInteger)
getMyDomain().setMin(c.getSelection());
else
getMyDomain().setMin(c.getSelection() / 100d);
UpsertNumericDomainDialog.this.upper.setMinimum(UpsertNumericDomainDialog.this.lower.getSelection());
UpsertNumericDomainDialog.this.redraw();
};
}
private ModifyListener upperLimitModifyListener() {
return e -> {
Spinner c = (Spinner) e.widget;
if (UpsertNumericDomainDialog.this.isInteger)
getMyDomain().setMax(c.getSelection());
else
getMyDomain().setMax(c.getSelection() / 100d);
UpsertNumericDomainDialog.this.lower.setMaximum(UpsertNumericDomainDialog.this.upper.getSelection());
UpsertNumericDomainDialog.this.redraw();
};
}
private void updateRow2(boolean status) {
this.spinnersRow.setEnabled(!status);
this.recolorSpinners(status);
}
private void recolorSpinners(boolean status) {
Color c = (!status) ? UiService.COLOR_BG_DISABLED : UiService.COLOR_BG_NORMAL;
for (Control spinner : this.spinnersRow.getChildren())
if (spinner instanceof Spinner)
spinner.setBackground(c);
}
private SelectionAdapter hasLimitsOnClick() {
return new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
boolean status = ((Button) e.getSource()).getSelection();
getMyDomain().setInRange(!status);
UpsertNumericDomainDialog.this.updateRow2(!status);
UpsertNumericDomainDialog.this.redraw();
}
};
}
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);
}
@Override
protected Point getInitialSize() {
return new Point(510, 600);
}
@Override
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
String title = String.format(this.messages.dialogTitleTemplate,
this.isCreating ? this.messages.crating : this.messages.modifying,
this.isInteger ? this.messages.integer : this.messages.real,
this.isIntervalar ? this.messages.intervalar : "" //$NON-NLS-1$
);
newShell.setText(title);
}
protected void beforeUI() {
NumericDomain domain = getMyDomain();
// SHELL
this.isIntervalar = domain.getType().contains(this.messages.intervalar);
// LOCAL
domain.setName(domain.getName() == null ? "" : domain.getName()); //$NON-NLS-1$
if (!domain.isInRange()) {
domain.setMin(0.0d);
domain.setMax(0.0d);
}
// CHART
this.domainChart = this.uiDomainService.createChart(domain.getType());
this.domainChart.initialize(domain, this.chartRow, 470, 300, SWT.BORDER);
this.redraw();
}
private void redraw() {
// ROW 2
boolean hasLimitsStatus = getMyDomain().getInRange();
this.hasLimitsCB.setSelection(!hasLimitsStatus);
this.updateRow2(!hasLimitsStatus);
// ROW 2 SPINNERS
NumericDomain cDomain = getMyDomain();
double maxD = cDomain.getMax();
double minD = cDomain.getMin();
int max = (int) maxD;
int min = (int) minD;
if (!this.isInteger) {
max = (int) (maxD * 100d);
min = (int) (minD * 100d);
}
if (this.upper.getSelection() != max)
this.upper.setSelection(max);
if (this.lower.getSelection() != min)
this.lower.setSelection(min);
// ROW 3
this.domainChart.setDomain(getMyDomain());
// BUTTON BAR
ArrayList<String> errors = this.checkAndDrawErrors();
boolean ok = errors.size() == 0;
setSaveEnabled(ok);
}
private ArrayList<String> checkAndDrawErrors() {
ArrayList<String> errors = new ArrayList<>();
// 4. Check limits
NumericDomain cDomain = (NumericDomain) getMyDomain();
double max = cDomain.getMax();
double min = cDomain.getMin();
boolean inRange = cDomain.getInRange();
if (inRange && max <= min) {
String msg = this.messages.error_out_of_limits;
errors.add(msg);
this.errorLabels.get(this.messages.error_limits).setText(msg);
this.errorControls.get(this.messages.error_limits1).setBackground(UiService.COLOR_BG_WRONG);
this.errorControls.get(this.messages.error_limits2).setBackground(UiService.COLOR_BG_WRONG);
} else {
this.errorLabels.get(this.messages.error_limits).setText(""); //$NON-NLS-1$
if (inRange) {
this.errorControls.get(this.messages.error_limits1).setBackground(UiService.COLOR_BG_NORMAL);
this.errorControls.get(this.messages.error_limits2).setBackground(UiService.COLOR_BG_NORMAL);
} else {
this.errorControls.get(this.messages.error_limits1).setBackground(UiService.COLOR_BG_DISABLED);
this.errorControls.get(this.messages.error_limits2).setBackground(UiService.COLOR_BG_DISABLED);
}
}
return errors;
}
}
@@ -0,0 +1,38 @@
// This file has been auto-generated
package flintstones.domain.numeric.ui.dialog.messages;
import org.eclipse.e4.core.services.nls.Message;
@Message
@SuppressWarnings("javadoc")
public class Messages {
public String NumericDomain_formatTemplate;
public String NumericDomain_toStringTemplate;
public String NumericDomainChart_range;
public String plusInfinity;
public String noInfinity;
public String Without_range;
public String lessInfinity;
public String label_domain_name;
public String error_domain_name;
public String limits;
public String rangeless;
public String limitless;
public String error_limits;
public String error_limits1;
public String to;
public String error_limits2;
public String preview;
public String dialogTitleTemplate;
public String crating;
public String integer;
public String intervalar;
public String error_empty_domain;
public String error_alredy_used_name;
public String error_out_of_limits;
public String modifying;
public String real;
public String blank;
}
@@ -0,0 +1,28 @@
Without_range=Without range
error_limits1=limits1
error_limits2=limits2
error_domain_name=name
error_limits=limits
chart=chart
crating=Creating
dialogTitleTemplate=%s domain of type %s %s
label_domain_name=Domain name
error_alredy_used_name=The chosen name is alredy used by another domain
error_empty_domain=Domain name can not be empty
error_out_of_limits=The first limit must be smaller than the second one
integer=Integer
intervalar=intervalar
lessInfinity=-Infinity
limitless=(-\u221E to \u221E)
limits=Limits
modifying=Editing
noInfinity=\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
NumericDomainChart_range=Range
plusInfinity=+Infinity
preview=Preview
rangeless=No range
real=Real
to=to
NumericDomain_formatTemplate={0} {1}
NumericDomain_toStringTemplate=[ {0} - {1} ]
blank=\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
@@ -0,0 +1,28 @@
Without_range=Sin rango
error_limits1=limits1
error_limits2=limits2
error_domain_name=name
error_limits=limits
chart=chart
crating=Creando
dialogTitleTemplate=%s dominio de tipo %s %s
label_domain_name=Nombre del dominio
error_alredy_used_name=El nombre ya esta siendo usado por otro dominio
error_empty_domain=El nombre de dominio no puede estar vacio
error_out_of_limits=El limite inferior debe ser menor que el limite superior
integer=Entero
intervalar=intervalar
limitless=(-\u221E to \u221E)
limits=Limites
modifying=Modificando
preview=Previsualización
rangeless=Sin rango
real=Real
to=a
NumericDomainChart_range=Rango
plusInfinity=+Infinito
lessInfinity=-Infinito
noInfinity=\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
NumericDomain_formatTemplate={0} {1}
NumericDomain_toStringTemplate=[ {0} - {1} ]
blank=\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \