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 @@
<?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.method.common.phase.selectBLTS.ui</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.method.common.phase.selectBLTS.ui</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>1779484362651</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,27 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Ui
Bundle-SymbolicName: flintstones.method.common.phase.selectBLTS.ui;singleton:=true
Bundle-Version: 1.0.0.qualifier
Automatic-Module-Name: flintstones.method.common.phase.selectBLTS.ui
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: flintstones.method.common.phase.unification.ui.dialog
Require-Bundle: flintstones.method.common.phase.selectBLTS,
flintstones.domain.fuzzyset.ui.dialog,
flintstones.helper.ui,
org.eclipse.wb.swt,
org.eclipse.e4.core.contexts,
flintstones.entity.domain,
javax.inject,
flintstones.model.domain.service,
org.eclipse.e4.core.di,
flintstones.domain.fuzzyset.ui.chart,
javax.annotation,
flintstones.model.ui.service,
flintstones.model.method.service,
flintstones.entity.method.phase,
flintstones.model.method.phase.service,
flintstones.entity.method.phase.ui,
org.eclipse.e4.core.services,
org.jfree.chart.jfreechart
Import-Package: org.eclipse.swt.widgets
@@ -0,0 +1,5 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.xml
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="flintstones.phasemethod.ui">
<phasemethod_ui
uid="flintstones.method.common.unification.ui.selectBLTS"
implementation="flintstones.method.common.phase.selectBLTS.ui.SelectBLTSUi"
phasemethod="flintstones.method.common.phase.selectBLTS">
</phasemethod_ui>
</extension>
</plugin>
@@ -0,0 +1,302 @@
package flintstones.method.common.phase.selectBLTS.ui;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import javax.inject.Inject;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.services.nls.Translation;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
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.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import flintstones.domain.fuzzyset.FuzzySet;
import flintstones.domain.fuzzyset.ui.chart.LinguisticDomainChart;
import flintstones.entity.domain.Domain;
import flintstones.entity.method.phase.ui.PhaseMethodUI;
import flintstones.method.common.phase.selectBLTS.SelectBLTSPhase;
import flintstones.method.common.phase.selectBLTS.ui.messages.Messages;
import flintstones.method.common.phase.unification.ui.dialog.NewBLTSDomainDialog;
import flintstones.model.domain.service.IDomainService;
import flintstones.model.method.service.IMethodService;
import flintstones.model.ui.service.UiService;
public class SelectBLTSUi extends PhaseMethodUI {
// LEFT
private Composite selectedDomainPanel;
// RIGHT
private TableViewer validDomainsViewer;
private LinguisticDomainChart chart = null;
private ControlAdapter controlListener = null;
private List<Domain> domains;
private Domain selectedDomain;
private boolean shouldCreateNewButton = false; // Diferenciar entre la SELECTBLTS con y sin botón
private Button _createNewButton;
private SelectBLTSPhase phaseModel;
@Inject
IDomainService domainService;
@Inject
IMethodService methodService;
@Inject
IEclipseContext context;
@Inject
@Translation
Messages messages;
@Override
public void init() {
createPartControl(this.baseComposite);
}
@Override
public void refresh() {
SelectBLTSUi.this.sendRefresh();
if(chart != null)
refreshChart();
}
@Override
public boolean isForwardEnabled() {
Domain d = phaseModel.getUnifiedDomain();
return d != null;
}
@Override
public boolean isSkippable() {
if (domains.size() == 1)
return true;
return false;
}
@Override
public void beforeSkip() {
List<Domain> domains = getBLTSDomains();
FuzzySet selected = (FuzzySet) domains.get(0);
phaseModel.setUnifiedDomain(selected);
}
public void createPartControl(Composite parent) {
phaseModel = (SelectBLTSPhase) this.getModel();
domains = new LinkedList<Domain>();
selectedDomain = null;
UiService.setGridData(parent, 9, 9, true, true);
UiService.setGridLayout(parent, 14, true);
createValidDomainsPanel();
createSelectedDomainPanel();
}
private void createValidDomainsPanel() {
Composite validDomainsPanel = new Composite(this.baseComposite, SWT.NONE);
validDomainsPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 6, 1));
GridLayout layout = new GridLayout(1, false);
layout.marginTop = 0;
layout.marginBottom = 0;
layout.marginLeft = 0;
layout.marginRight = 0;
layout.verticalSpacing = 20;
layout.marginWidth = 0;
layout.marginHeight = 0;
layout.horizontalSpacing = 0;
validDomainsPanel.setLayout(layout);
validDomainsViewer = new TableViewer(validDomainsPanel, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.FULL_SELECTION);
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
validDomainsViewer.getTable().setLayoutData(gridData);
validDomainsViewer.getTable().setHeaderVisible(true);
validDomainsViewer.setContentProvider(new IStructuredContentProvider() {
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
@Override
public void dispose() {
}
@SuppressWarnings("unchecked")
@Override
public Object[] getElements(Object inputElement) {
return ((List<Domain>) inputElement).toArray();
}
});
validDomainsViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
ISelection selection = validDomainsViewer.getSelection();
selectedDomain = (FuzzySet) ((IStructuredSelection) selection).getFirstElement();
phaseModel.setUnifiedDomain((FuzzySet) selectedDomain);
SelectBLTSUi.this.refresh();
}
});
TableViewerColumn col = new TableViewerColumn(validDomainsViewer, SWT.NONE);
col.getColumn().setWidth(100);
col.getColumn().setText("Name");
col.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return ((FuzzySet) element).getName();
}
});
final TableViewerColumn descriptionColumn = new TableViewerColumn(validDomainsViewer, SWT.NONE);
descriptionColumn.getColumn().setWidth(100);
descriptionColumn.getColumn().setText("Description");
descriptionColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return ((FuzzySet) element).formatDescriptionDomain();
}
});
if (shouldCreateNewButton) {
_createNewButton = new Button(validDomainsPanel, SWT.PUSH);
_createNewButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1));
_createNewButton.setText("Create new");
_createNewButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
NewBLTSDomainDialog dialog = ContextInjectionFactory.make(NewBLTSDomainDialog.class, context);
if (dialog.open() == IDialogConstants.OK_ID) {
FuzzySet fuzzySet = dialog.getDomain();
int count = 1;
for (Domain domain : domains) {
if (domain.getName()
.contains("Generate ")) {
count++;
}
}
fuzzySet.setName("Generate " + count);
domains.add(fuzzySet);
validDomainsViewer.refresh();
descriptionColumn.getColumn()
.pack();
}
}
});
}
loadDomains();
descriptionColumn.getColumn().pack();
}
private void loadDomains() {
domains = getBLTSDomains();
validDomainsViewer.setInput(domains);
if(domains.size() > 0)
validDomainsViewer.setSelection(new StructuredSelection(getBLTSWithMaximumGranularity(domains)), true);
}
private List<Domain> getBLTSDomains() {
List<Domain> domains = Arrays.asList(domainService.getAll());
List<Domain> bltsDomains = new LinkedList<Domain>();
for (Domain domain : domains) {
if (domain instanceof FuzzySet) {
FuzzySet fDomain = (FuzzySet) domain;
if (fDomain.isBLTS()) {
bltsDomains.add(domain);
}
}
}
return bltsDomains;
}
private FuzzySet getBLTSWithMaximumGranularity(List<Domain> domains) {
int granularity = 0, domainGranularity;
FuzzySet selected = null;
for(Domain domain: domains) {
domainGranularity = ((FuzzySet) domain).getLabelSet().getCardinality();
if(domainGranularity > granularity) {
selected = (FuzzySet) domain;
granularity = domainGranularity;
}
}
return selected;
}
private void createSelectedDomainPanel() {
selectedDomainPanel = new Composite(this.baseComposite, SWT.NONE);
selectedDomainPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 8, 1));
refreshChart();
}
private void refreshChart() {
removeChart();
chart = ContextInjectionFactory.make(LinguisticDomainChart.class, context);
Point size = selectedDomainPanel.getSize();
chart.initialize(selectedDomain, selectedDomainPanel, size.x, size.y, SWT.BORDER);
if (controlListener == null) {
controlListener = new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
refreshChart();
}
};
selectedDomainPanel.addControlListener(controlListener);
}
}
private void removeChart() {
if (chart != null) {
chart.getChartComposite()
.dispose();
}
}
}
@@ -0,0 +1,24 @@
//This file has been auto-generated
package flintstones.method.common.phase.selectBLTS.ui.messages;
import org.eclipse.e4.core.services.nls.Message;
@Message
@SuppressWarnings("javadoc")
public class Messages {
public String SelectBLTS_Name;
public String SelectBLTS_Description;
public String SelectBLTS_Create_new;
public String SelectBLTS_Generate;
public String NewBLTSDomainDialog_New_BLTS_domain;
public String NewBLTSDomainDialog_Preview;
public String NewBLTSDomainDialog_Set_semantic;
public String NewBLTSDomainDialog_If_you_make_changes_to_the_data_the_semantic_will_be_lost;
public String NewBLTSDomainDialog_Numer_of_labels;
public String NewBLTSDomainDialog_Semantic;
public String SemanticDialog_Semantic_for_domain;
}
@@ -0,0 +1,15 @@
SelectBLTS_Name=Name
SelectBLTS_Description=Description
SelectBLTS_Create_new=Create new
SelectBLTS_Generate=Generate
NewBLTSDomainDialog_Cancel=Cancel
NewBLTSDomainDialog_If_you_make_changes_to_the_data_the_semantic_will_be_lost=If you make changes to the data the semantic will be lost
NewBLTSDomainDialog_New_BLTS_domain=New BLTS domain
NewBLTSDomainDialog_Numer_of_labels=Number of labels
NewBLTSDomainDialog_Preview=Preview
NewBLTSDomainDialog_Save=Save
NewBLTSDomainDialog_Set_semantic=Set semantic
NewBLTSDomainDialog_Semantic=Semantic
SemanticDialog_Semantic_for_domain=Semantic for domain
@@ -0,0 +1,15 @@
SelectBLTS_Name=Nombre
SelectBLTS_Description=Descripcion
SelectBLTS_Create_new=Nuevo
SelectBLTS_Generate=Generar
NewBLTSDomainDialog_Cancel=Cancelar
NewBLTSDomainDialog_If_you_make_changes_to_the_data_the_semantic_will_be_lost=Si realiza cambios la informacin sobre la gramtica se perder
NewBLTSDomainDialog_Numer_of_labels=Numero de etiquetas
NewBLTSDomainDialog_New_BLTS_domain=Nuevo dominio BTLS
NewBLTSDomainDialog_Preview=Previsualizacion
NewBLTSDomainDialog_Save=Guardar
NewBLTSDomainDialog_Set_semantic=Asignar semantica
NewBLTSDomainDialog_Semantic=Semantica
SemanticDialog_Semantic_for_domain=Semantica para el dominio
@@ -0,0 +1,220 @@
package flintstones.method.common.phase.unification.ui.dialog;
import java.util.List;
import javax.inject.Inject;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.services.nls.Translation;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.fieldassist.ControlDecoration;
import org.eclipse.jface.fieldassist.FieldDecoration;
import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
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.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Spinner;
import flintstones.domain.fuzzyset.FuzzySet;
import flintstones.domain.fuzzyset.ui.chart.LinguisticDomainChart;
import flintstones.method.common.phase.selectBLTS.ui.messages.Messages;
import flintstones.model.domain.service.IDomainService;
import flintstones.model.ui.service.UiService;
public class NewBLTSDomainDialog extends Dialog {
@Inject
IEclipseContext context;
@Inject
IDomainService domainService;
@Inject
@Translation
Messages messages;
private Spinner _spinner;
private Label _previewLabel;
private String[] _labels;
private Button _setSemanticButton;
private LinguisticDomainChart _fuzzySetChart;
private FuzzySet _domainBLTS;
private Button okButton;
private Composite baseComposite;
public NewBLTSDomainDialog() {
super(Display.getCurrent()
.getActiveShell());
}
/* (non-Javadoc)
*
* @see
* org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.
* Composite) */
@Override
protected Control createDialogArea(Composite base) {
super.createDialogArea(base);
this.baseComposite = base;
UiService.setGridLayout(base, 1);
UiService.setGridData(base, 9, 9, true, true);
_domainBLTS = (FuzzySet) domainService.create(FuzzySet.ID);
this.getShell().setText(messages.NewBLTSDomainDialog_New_BLTS_domain);
drawRow1(base);
drawRow2(base);
return base;
}
private void drawRow2(Composite base) {
Composite row2 = new Composite(base,SWT.NONE);
UiService.setGridData(row2, 9, 1, true, true);
_previewLabel = new Label(row2, SWT.NONE);
UiService.setFont(_previewLabel,UiService.FONT_SECTION_TITLE);
_previewLabel.setText(messages.NewBLTSDomainDialog_Preview);
_labels = new String[] { "s0", "s1", "s2" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
_domainBLTS.createTrapezoidalFunction(_labels);
Composite chartComposite = new Composite(base, SWT.NONE);
chartComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
_fuzzySetChart = new LinguisticDomainChart();
_fuzzySetChart.initialize(_domainBLTS, chartComposite, 550, 200, SWT.BORDER);
}
private void drawRow1(Composite base) {
Composite row1 = new Composite(base,SWT.NONE);
UiService.setGridLayout(row1, 2);
UiService.setGridData(row1, 9, 1, true, true);
drawRow1Left(row1);
drawRow1Right(row1);
}
private void drawRow1Right(Composite row1) {
Composite row1Right = new Composite(row1,SWT.NONE);
UiService.setGridLayout(row1Right,1);
UiService.setGridData(row1Right, 9, 1, true, true);
Label row1RightLabel = new Label(row1Right, SWT.NULL);
UiService.setFont(row1RightLabel,UiService.FONT_SECTION_TITLE);
row1RightLabel.setText(messages.NewBLTSDomainDialog_Semantic);
_setSemanticButton = new Button(row1Right, SWT.NONE);
_setSemanticButton.setText(messages.NewBLTSDomainDialog_Set_semantic);
ControlDecoration controlDecoration = new ControlDecoration(_setSemanticButton, SWT.LEFT | SWT.TOP);
FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_WARNING);
controlDecoration.setImage(fieldDecoration.getImage());
controlDecoration.setDescriptionText(messages.NewBLTSDomainDialog_If_you_make_changes_to_the_data_the_semantic_will_be_lost);
_setSemanticButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
SemanticDialog dialog = new SemanticDialog(baseComposite.getShell(), _labels);
ContextInjectionFactory.inject(dialog, context);
if (dialog.open() == IDialogConstants.OK_ID) {
List<String> auxLabels = dialog.getValues();
for (int i = 0; i < auxLabels.size(); i++) {
_labels[i] = auxLabels.get(i);
}
modifyDomainSemantic();
}
}
});
}
private void drawRow1Left(Composite row1) {
Composite row1Left = new Composite(row1,SWT.NONE);
UiService.setGridLayout(row1Left, 1);
UiService.setGridData(row1Left, 9, 9, true, true);
Label row1LeftLabel = new Label(row1Left, SWT.NULL);
row1LeftLabel.setText(messages.NewBLTSDomainDialog_Numer_of_labels);
UiService.setFont(row1LeftLabel,UiService.FONT_SECTION_TITLE);
UiService.setGridData(row1LeftLabel, -1, 0, true, false);
_spinner = new Spinner(row1Left, SWT.SINGLE | SWT.BORDER);
UiService.setGridData(_spinner, 0, 0, false, false);
_spinner.setSelection(3);
_spinner.setMinimum(3);
_spinner.setIncrement(2);
_spinner.setMaximum(Integer.MAX_VALUE);
_spinner.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
int selection = _spinner.getSelection();
boolean valid = (selection >= 3);
if (valid) {
valid = ((selection % 2) == 1);
}
okButton.setEnabled(valid);
modifyDomain();
}
});
}
@Override
protected void createButtonsForButtonBar(Composite parent) {
okButton = this.createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
this.createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
UiService.reLayoutShell(this.getShell());
}
private void modifyDomain() {
int cardinality = _spinner.getSelection();
_labels = new String[cardinality];
for (int i = 0; i < cardinality; i++) {
_labels[i] = "s" + i; //$NON-NLS-1$
}
modifyDomainSemantic();
}
private void modifyDomainSemantic() {
_domainBLTS.createTrapezoidalFunction(_labels);
_fuzzySetChart.setDomain(_domainBLTS);
}
public FuzzySet getDomain() {
return _domainBLTS;
}
}
@@ -0,0 +1,306 @@
package flintstones.method.common.phase.unification.ui.dialog;
import java.util.LinkedList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.eclipse.e4.core.services.nls.Translation;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.fieldassist.ControlDecoration;
import org.eclipse.jface.fieldassist.FieldDecoration;
import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
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.Text;
import org.eclipse.wb.swt.SWTResourceManager;
import flintstones.method.common.phase.selectBLTS.ui.messages.Messages;
import flintstones.model.ui.service.UiService;
class SemanticDialog extends Dialog {
public static final int SAVE = 100;
public static final int CANCEL = 101;
private String _title;
private boolean _validFields = false;
private int _num;
private List<Text> _textValues;
private List<ControlDecoration> _controlDecorations;
private List<String> _values = new LinkedList<String>();;
@Inject
@Translation
Messages messages;
/**
* Crea el dilogo.
*
* @param parentShell
* Contenedor del dilogo.
* @param values
* Nombres de las etiquetas
*/
SemanticDialog(Shell parentShell, String[] values) {
super(parentShell);
for (String value : values) {
_values.add(value);
}
}
@PostConstruct
private void init() {
_num = _values.size();
_title = messages.SemanticDialog_Semantic_for_domain;
}
@Override
protected Control createDialogArea(Composite parent) {
super.createDialogArea(parent);
Composite container = (Composite) super.createDialogArea(parent);
GridLayout gridLayout = (GridLayout) container.getLayout();
gridLayout.verticalSpacing = 15;
gridLayout.numColumns = 1;
Label titleLabel = new Label(container, SWT.NONE);
titleLabel.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false, 1, 1));
titleLabel.setFont(SWTResourceManager.getFont("Cantarell", 10, SWT.BOLD)); //$NON-NLS-1$
titleLabel.setText(_title);
ScrolledComposite scrolledComposite = new ScrolledComposite(container, SWT.H_SCROLL | SWT.V_SCROLL);
scrolledComposite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true, 1, 1));
gridLayout = new GridLayout(2, false);
gridLayout.verticalSpacing = 15;
gridLayout.numColumns = 2;
Composite labelsComposite = new Composite(scrolledComposite, SWT.NONE);
labelsComposite.setLayout(gridLayout);
Label fieldLabel;
GridData gridData;
_textValues = new LinkedList<Text>();
_controlDecorations = new LinkedList<ControlDecoration>();
Text value;
ControlDecoration controlDecoration;
for (int i = 0; i < _num; i++) {
fieldLabel = new Label(labelsComposite, SWT.NONE);
fieldLabel.setFont(SWTResourceManager.getFont("Cantarell", 9, SWT.BOLD)); //$NON-NLS-1$
fieldLabel.setText("Label" + " " + (i + 1)); //$NON-NLS-1$ //$NON-NLS-2$
value = new Text(labelsComposite, SWT.BORDER);
gridData = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
gridData.widthHint = 75;
value.setLayoutData(gridData);
value.setText(_values.get(i));
_textValues.add(value);
controlDecoration = createExceptionDecorator(value);
_controlDecorations.add(controlDecoration);
}
scrolledComposite.setContent(labelsComposite);
scrolledComposite.setExpandVertical(true);
scrolledComposite.setExpandHorizontal(true);
scrolledComposite.setMinSize(labelsComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
scrolledComposite.setSize(200, 300);
hookValuesModifyListener();
validateFields();
return container;
}
@Override
protected void createButtonsForButtonBar(Composite parent) {
this.createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
this.createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
UiService.reLayoutShell(this.getShell());
}
/**
* Crea un decorador de excepcin en un campo.
*
* @param control
* Control a decorar.
* @return Decorador creado.
*/
private ControlDecoration createExceptionDecorator(Control control) {
ControlDecoration controlDecoration = new ControlDecoration(control, SWT.LEFT | SWT.TOP);
FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault()
.getFieldDecoration(FieldDecorationRegistry.DEC_ERROR);
controlDecoration.setImage(fieldDecoration.getImage());
validate(controlDecoration, ""); //$NON-NLS-1$
return controlDecoration;
}
/**
* Valida un campo.
*
* @param controlDecoration
* Decorador del campo.
* @param text
* Texto del decorador.
* @return True si el campo es vlido, False en caso contrario.
*/
private boolean validate(ControlDecoration controlDecoration, String text) {
controlDecoration.setDescriptionText(text);
if (text.isEmpty()) {
controlDecoration.hide();
return true;
}
controlDecoration.show();
return false;
}
/**
* Engancha los listeners de modificacin de valores.
*/
private void hookValuesModifyListener() {
ModifyListener modifyListener = new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
Text auxText = (Text) e.getSource();
String auxValue = auxText.getText();
Text text;
for (int i = 0; i < _textValues.size(); i++) {
text = _textValues.get(i);
if (auxText == text) {
_values.set(i, auxValue);
}
}
validateFields();
}
};
for (Text text : _textValues) {
text.addModifyListener(modifyListener);
}
}
/**
* Comprueba que un texto no est en blanco.
*
* @param text
* Texto a comprobar.
* @param controlDecoration
* Decorador del campo.
* @return True si el campo no est en blanco, false en caso contrario.
*/
private boolean validateEmptyText(Text text, ControlDecoration controlDecoration) {
if (text.getText()
.isEmpty()) {
return validate(controlDecoration, "Messages.SemanticDialog_Empty_value");
}
return validate(controlDecoration, ""); //$NON-NLS-1$
}
/**
* Comprueba que un texto no contenga valores invlidos.
*
* @param text
* Texto a comprobar.
* @param controlDecoration
* Decorador del campo.
* @return True si el campo no contiene valores invlidos, false en caso
* contrario.
*/
private boolean validateInvalidText(Text text, ControlDecoration controlDecoration) {
String textValue = text.getText();
if (textValue.contains(":")) { //$NON-NLS-1$
return validate(controlDecoration, "Messages.SemanticDialog_Illegal_value");
}
return validate(controlDecoration, ""); //$NON-NLS-1$
}
/**
* Comprueba que un texto no est duplicado.
*
* @param text
* Texto a comprobar.
* @param controlDecoration
* Decorador del campo.
* @return True si el campo no est duplicado, false en caso contrario.
*/
private boolean validateDuplicateText(Text text, int index, ControlDecoration controlDecoration) {
String textValue = text.getText();
for (int i = 0; i < _textValues.size(); i++) {
if (i != index) {
if (textValue.equals(_textValues.get(i)
.getText())) {
return validate(controlDecoration, "Messages.SemanticDialog_Duplicated_value");
}
}
}
return validate(controlDecoration, ""); //$NON-NLS-1$
}
/**
* Realiza todas las validaciones.
*/
private void validateFields() {
Boolean[] values = new Boolean[_num];
// Validar campos no nulos
Text text;
ControlDecoration controlDecoration;
for (int index = 0; index < _textValues.size(); index++) {
text = _textValues.get(index);
controlDecoration = _controlDecorations.get(index);
values[index] = validateEmptyText(text, controlDecoration);
if (values[index]) {
values[index] = validateInvalidText(text, controlDecoration);
if (values[index]) {
values[index] = validateDuplicateText(text, index, controlDecoration);
}
}
}
_validFields = true;
int i = 0;
do {
_validFields = values[i++];
} while ((_validFields) && (i < values.length));
Button SaveButton = getButton(SAVE);
if (SaveButton != null) {
SaveButton.setEnabled(_validFields);
}
}
/**
* Devuelve los valores.
*
* @return Valores de las etiquetas.
*/
public List<String> getValues() {
return _values;
}
@Override
protected void buttonPressed(int buttonId) {
setReturnCode(buttonId);
close();
}
}