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.collectweights.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.collectweights.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>1779484362648</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,26 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Ui
Bundle-SymbolicName: flintstones.method.common.phase.collectweights.ui;singleton:=true
Bundle-Version: 1.0.0.qualifier
Automatic-Module-Name: flintstones.method.common.phase.collectweights.ui
Bundle-RequiredExecutionEnvironment: JavaSE-11
Require-Bundle: org.eclipse.e4.core.contexts,
flintstones.entity.method.phase.ui,
org.eclipse.swt,
org.eclipse.e4.core.di,
flintstones.application,
javax.inject,
flintstones.application.constants,
org.eclipse.e4.core.services,
org.eclipse.osgi.services,
org.eclipse.e4.ui.workbench,
flintstones.method.common.phase.collectweights,
flintstones.model.ui.service,
org.eclipse.nebula.widgets.opal.checkboxgroup,
flintstones.entity.problemelement.ui,
flintstones.entity.problemelement,
flintstones.model.problemelement.service,
flintstones.helper.ui,
flintstones.helper.data,
flintstones.entity.method.phase
@@ -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.phase.collectweights.ui"
implementation="flintstones.method.common.phase.collectweights.ui.CollectWeightsUI"
phasemethod="flintstones.method.common.phase.collectweights">
</phasemethod_ui>
</extension>
</plugin>
@@ -0,0 +1,156 @@
package flintstones.method.common.phase.collectweights.ui;
import java.text.MessageFormat;
import javax.inject.Inject;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.nebula.widgets.opal.checkboxgroup.CheckBoxGroup;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import flintstones.application.constants.ApplicationContants;
import flintstones.application.constants.FrameworkConstants;
import flintstones.application.handlers.PerspectiveSwitcher;
import flintstones.entity.method.phase.ui.PhaseMethodUI;
import flintstones.entity.problemelement.entities.ProblemElement;
import flintstones.helper.data.HashMatrix;
import flintstones.method.common.phase.collectweights.CollectWeightsModel;
import flintstones.method.common.phase.collectweights.ui.interfaces.IToggled;
import flintstones.model.ui.service.UiService;
public class CollectAlternativeWeightColumn {
@Inject
IEventBroker broker;
@Inject
IEclipseContext context;
ProblemElement[] gathererElements;
ProblemElement fakeCached = null;
HashMatrix<ProblemElement, ProblemElement, Double> weights = new HashMatrix<>();
CollectWeightsModel model;
String key;
private IToggled toggleListener;
private CheckBoxGroup group;
public CollectAlternativeWeightColumn(Composite parent, CollectWeightsModel model, String id,
ProblemElement[] mainElements) {
this(parent, model, id, mainElements, null);
}
public CollectAlternativeWeightColumn(Composite parent, CollectWeightsModel model, String id,
ProblemElement[] mainElements, ProblemElement[] otherElements) {
this.model = model;
this.key = id;
Composite base = new Composite(parent, 0);
UiService.setGridLayout(base, 1, true);
UiService.setGridData(base, 9, 1, false, false);
// GROUP
String mainType = mainElements[0].getType();
String otherType = otherElements != null ? otherElements[0].getType() : "";
String template = otherElements != null ? "Introducir pesos para {0} -> {1}"
: "Introducir pesos globales para {0}";
String text = MessageFormat.format(template, mainType, otherType);
group = new CheckBoxGroup(base, 0);
UiService.setGridData(group, 9, 9, true, true);
UiService.setGridLayout(group, 1);
group.setText(text);
group.setBackground(UiService.COLOR_BG_DISABLED);
group.addSelectionListener(groupToggle());
// Content base
Composite groupBase = group.getContent();
UiService.setMargin(groupBase, 0);
Combo c = new Combo(groupBase, SWT.BORDER | SWT.READ_ONLY);
c.setItems(model.getCriterionWeightCollectorLabels());
c.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String phaseId = model.getPhaseIdBy(c.getText());
PhaseMethodUI ui = model.getCriterionPhase();
ContextInjectionFactory.make(PerspectiveSwitcher.class, context).changePerspective(ApplicationContants.MPerspective_Phase_Phantom);
// broker.subscribe(FrameworkConstants.TOPIC_METHOD_PHASE_PHANTOM_RESPONSE,phase);
// lastSelection = "combo";
if( ui != null && ui.getModel().getName().equals(c.getText()))
broker.send(FrameworkConstants.TOPIC_METHOD_PHASE_PHANTOM, ui);
else
broker.send(FrameworkConstants.TOPIC_METHOD_PHASE_PHANTOM, phaseId);
}
});
// Selectors
// Collector
gathererElements = otherElements != null ? otherElements : mainElements;
// Deactivate all - Always at the end
group.deactivate();
}
private SelectionAdapter groupToggle() {
return new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (group.isActivated()) {
group.setBackground(group.getParent().getBackground());
// Simulate a change to reexport if needed
} else {
model.deleteExport(key);
group.setBackground(UiService.COLOR_BG_DISABLED);
}
toggleListener.onToggle(group.isActivated());
}
};
}
public void setToggleListener(IToggled i) {
toggleListener = i;
}
public void toggle(boolean status) {
if(group.isActivated() == status)
return ;
if (status) {
group.activate();
group.setBackground(group.getParent().getBackground());
} else {
group.setBackground(UiService.COLOR_BG_DISABLED);
group.deactivate();
}
}
}
@@ -0,0 +1,280 @@
package flintstones.method.common.phase.collectweights.ui;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import org.eclipse.nebula.widgets.opal.checkboxgroup.CheckBoxGroup;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import flintstones.entity.problemelement.entities.FakeProblemElement;
import flintstones.entity.problemelement.entities.ProblemElement;
import flintstones.entity.problemelement.ui.widget.ProblemElementSelector;
import flintstones.entity.problemelement.ui.widget.listener.IProblemElementChangedListener;
import flintstones.helper.DoubleHelper;
import flintstones.helper.data.HashMatrix;
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.method.common.phase.collectweights.CollectWeightsModel;
import flintstones.method.common.phase.collectweights.ui.interfaces.IToggled;
import flintstones.model.ui.service.UiService;
public class CollectWeightColumn {
ProblemElementSelector mainSelector;
WCollector collector;
ProblemElement[] gathererElements;
ProblemElement fakeCached = null;
HashMatrix<ProblemElement, ProblemElement, Double> weights = new HashMatrix<>();
CollectWeightsModel model;
String key;
Label saveStatus;
private IToggled toggleListener;
private CheckBoxGroup group;
public CollectWeightColumn(Composite parent, CollectWeightsModel model, String id, ProblemElement[] mainElements) {
this(parent, model, id, mainElements, null);
}
public CollectWeightColumn(Composite parent, CollectWeightsModel model, String id, ProblemElement[] mainElements,
ProblemElement[] otherElements) {
this.model = model;
this.key = id;
Composite base = new Composite(parent, 0);
UiService.setGridLayout(base, 1, true);
UiService.setGridDataAuto(base);
// GROUP
String mainType = mainElements[0].getType();
String otherType = otherElements != null ? otherElements[0].getType() : "";
String template = otherElements != null ? "Introducir pesos para {0} -> {1}"
: "Introducir pesos globales para {0}";
String text = MessageFormat.format(template, mainType, otherType);
group = new CheckBoxGroup(base, 0);
UiService.setGridData(group, 9, 9, true, true);
UiService.setGridLayout(group, 1);
group.setText(text);
group.setBackground(UiService.COLOR_BG_DISABLED);
group.addSelectionListener(groupToggle());
// Content base
Composite groupBase = group.getContent();
UiService.setMargin(groupBase, 0);
// Selectors
mainSelector = null;
if (otherElements != null)
mainSelector = new ProblemElementSelector(groupBase, mainElements);
// Collector
gathererElements = otherElements != null ? otherElements : mainElements;
collector = new WCollector(groupBase);
collector.setHeaders(Arrays.stream(gathererElements).map(k -> k.getName()).toArray(String[]::new));
collector.setEnabled(false);
// Logic attached to variables
if (mainSelector != null)
mainSelector.setListener(onSelectorChange(collector));
collector.setChangeListener(new WItemChanged() {
@Override
public void onWidgetChange() {
onCollectorChange(collector);
}
});
collector.setBeforeOperationListener(beforeCollectorOperation(collector));
collector.setOperationListener(collectorOperation());
saveStatus = new Label(groupBase, SWT.WRAP);
UiService.setFont(saveStatus, UiService.FONT_TEXT_BOLD);
UiService.setFontSize(saveStatus, 10);
setSaveStatus(false);
// Deactivate all - Always at the end
group.deactivate();
}
private void setSaveStatus(boolean status) {
if (status) {
saveStatus.setText("Cambios guardados");
UiService.setFontColor(saveStatus, UiService.COLOR_FG_SUCCESS);
} else {
saveStatus.setText("Cambios sin guardar.\nTodos deben sumar 1");
UiService.setFontColor(saveStatus, UiService.COLOR_FG_ERROR);
}
}
private WItemOperation collectorOperation() {
return new WItemOperation() {
@Override
public String getModifiedValue(WEvent operationType, String before, String after) {
if (operationType.equals(WEvent.ADD)) {
if(before.equals("1") && gathererElements.length == 1)
return "1";
return DoubleHelper.NormalizeZeroToOne(before) + "";
}
return after;
}
};
}
private WItemBeforeOperation beforeCollectorOperation(WCollector collector) {
return new WItemBeforeOperation() {
@Override
public boolean shouldBeExecuted(WEvent operationType, String before, String after) {
if (operationType.equals(WEvent.ADD)) {
double newValue = before.equals("1") && gathererElements.length == 1 ? 1.0 : DoubleHelper.NormalizeZeroToOne(before);
if (DoubleHelper.Equals(0.0, newValue, 1))
return false;
String[] data = collector.getData();
// Same lenth, limit reached
if (data.length == gathererElements.length)
return false;
// Lets sum
double sum = 0.0;
for (String value : data) {
sum += Double.parseDouble(value);
}
sum += newValue;
// When the last element in introduced must sum 1
if (data.length == gathererElements.length - 1) {
return DoubleHelper.Equals(sum, 1.0, 5);
} else { // Must not sum over 1 in any case
return sum <= 1.0;
}
} else if (operationType.equals(WEvent.CLEAR)) {
return true;
}
return false;
}
};
}
private void onCollectorChange(WCollector collector) {
ProblemElement main = getCurrentMain();
// Update memory
String[] data = collector.getData();
for (int i = 0; i < gathererElements.length && i < data.length; i++)
weights.put(main, gathererElements[i], DoubleHelper.ParseDouble(data[i]));
// Update UI
boolean status = data.length == gathererElements.length;
if (mainSelector != null) {
mainSelector.setStatus(main, status);
status = mainSelector.getStatus();
}
if (status)
model.export(key, weights);
setSaveStatus(status);
}
private IProblemElementChangedListener onSelectorChange(WCollector collector) {
return new IProblemElementChangedListener() {
@Override
public void problemElementChanged(ProblemElement pe) {
ProblemElement main = getCurrentMain();
ArrayList<String> data = new ArrayList<>();
for (int i = 0; i < gathererElements.length; i++) {
Double value = weights.get(main, gathererElements[i]);
if (value != null)
data.add(value + "");
}
collector.setValues(data);
}
};
}
private ProblemElement getCurrentMain() {
if (mainSelector != null)
return mainSelector.getSelectedElement();
if (fakeCached == null)
fakeCached = new FakeProblemElement("");
return fakeCached;
}
private SelectionAdapter groupToggle() {
return new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (group.isActivated()) {
group.setBackground(group.getParent().getBackground());
// Simulate a change to reexport if needed
onCollectorChange(collector);
} else {
model.deleteExport(key);
group.setBackground(UiService.COLOR_BG_DISABLED);
}
collector.setEnabled(group.isActivated());
toggleListener.onToggle(group.isActivated());
}
};
}
public void setToggleListener(IToggled i) {
toggleListener = i;
}
public void toggle(boolean status) {
if(group.isActivated() == status)
return ;
if (status) {
group.activate();
group.setBackground(group.getParent().getBackground());
onCollectorChange(collector);
} else {
group.deactivate();
group.setBackground(UiService.COLOR_BG_DISABLED);
}
collector.setEnabled(group.isActivated());
}
}
@@ -0,0 +1,121 @@
package flintstones.method.common.phase.collectweights.ui;
import java.util.stream.IntStream;
import javax.inject.Inject;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventHandler;
import flintstones.entity.method.phase.ui.PhaseMethodUI;
import flintstones.entity.problemelement.entities.Criterion;
import flintstones.entity.problemelement.entities.Expert;
import flintstones.entity.problemelement.entities.ProblemElement;
import flintstones.method.common.phase.collectweights.CollectWeightsModel;
import flintstones.method.common.phase.collectweights.ui.interfaces.IToggled;
import flintstones.model.problemelement.service.IProblemElementService;
import flintstones.model.ui.service.UiService;
public class CollectWeightsUI extends PhaseMethodUI implements EventHandler {
@Inject
IEclipseContext context;
@Inject
IEventBroker broker;
@Inject
IProblemElementService problemService;
CollectWeightsModel model;
Button expertWeights;
String lastSelection = ""; // button / combo
CollectWeightColumn[] upCols;
CollectAlternativeWeightColumn[] downCols;
@Override
public void refresh() {
}
@Override
protected boolean isForwardEnabled() {
return true;
}
@Override
public void init() {
model = (CollectWeightsModel) this.getModel();
Composite base = this.getBaseComposite();
UiService.setGridDataAuto(base);
UiService.setGridLayout(base, 4);
ProblemElement[] experts = problemService.getAll(Expert.Type);
ProblemElement[] criterions = problemService.getAll(Criterion.Type);
upCols = new CollectWeightColumn[4];
upCols[0] = new CollectWeightColumn(base, model, "criterionWeight", experts);
upCols[1] = new CollectWeightColumn(base, model, "criterionExpertWeight", experts, criterions);
upCols[2] = new CollectWeightColumn(base, model, "expertWeight", criterions);
upCols[3] = new CollectWeightColumn(base, model, "expertCriterionWeight", criterions, experts);
IntStream.range(0, 4) //
.forEach(k -> upCols[k].setToggleListener(toggled(true, k)));
downCols = new CollectAlternativeWeightColumn[4];
downCols[0] = new CollectAlternativeWeightColumn(base, model, "criterionWeight", experts);
downCols[1] = new CollectAlternativeWeightColumn(base, model, "criterionExpertWeight", experts, criterions);
downCols[2] = new CollectAlternativeWeightColumn(base, model, "expertWeight", criterions);
downCols[3] = new CollectAlternativeWeightColumn(base, model, "expertCriterionWeight", criterions, experts);
IntStream.range(0, 4) //
.forEach( //
k -> {
downCols[k].setToggleListener(toggled(false, k));
ContextInjectionFactory.inject(upCols[k], context);
} //
);
}
private IToggled toggled(boolean up, int pos) {
return new IToggled() {
@Override
public void onToggle(boolean status) {
if (status) { // If we are enabling, disable the other one
if (up)
downCols[pos].toggle(false);
else
upCols[pos].toggle(false);
}
}
};
}
@Override
public void handleEvent(Event event) {
String propertyName = event.getPropertyNames()[0];
PhaseMethodUI ui = (PhaseMethodUI) event.getProperty(propertyName);
if (lastSelection.equals("button")) {
model.setExpertPhase(ui);
} else if (lastSelection.equals("combo")) {
model.setCriterionPhase(ui);
}
broker.unsubscribe(this);
}
}
@@ -0,0 +1,5 @@
package flintstones.method.common.phase.collectweights.ui.interfaces;
public interface IToggled {
void onToggle(boolean status);
}