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.aggregation.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.aggregation.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>1779484362635</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,45 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Ui
Bundle-SymbolicName: flintstones.method.common.phase.aggregation.ui;singleton:=true
Bundle-Version: 1.0.0.qualifier
Automatic-Module-Name: flintstones.method.common.phase.aggregation.ui
Bundle-RequiredExecutionEnvironment: JavaSE-11
Require-Bundle: flintstones.model.ui.service,
org.eclipse.e4.core.di,
flintstones.entity.domain,
flintstones.helper.ui,
javax.inject,
org.eclipse.e4.ui.di,
org.eclipse.e4.core.contexts,
flintstones.model.problemelement.service,
flintstones.application.constants,
flintstones.entity.problemelement,
flintstones.helper.data,
flintstones.method.common.phase.unification.ui,
flintstones.entity.valuation,
flintstones.model.valuation.service,
flintstones.valuation.linguistic,
flintstones.valuation.hesitant,
flintstones.valuation.elicit,
flintstones.valuation.twoTuple,
org.eclipse.e4.core.services,
flintstones.valuation.unifiedValuation,
flintstones.operator,
flintstones.domain.fuzzyset.ui.dialog,
flintstones.application.perspective.framework.ui,
org.jfree.chart.jfreechart,
flintstones.method.common.phase.aggregation,
flintstones.domain.fuzzyset.ui.chart,
javax.annotation,
flintstones.entity.operator,
flintstones.model.method.phase.service,
flintstones.entity.method.phase.ui,
flintstones.entity.method.phase,
org.eclipse.jface,
flintstones.method.common.phase.collectweightsaggregation.ui,
flintstones.entity.common,
flintstones.entity.aggregation,
flintstones.method.common.phase.collectweightsaggregation
Export-Package: flintstones.method.common.phase.aggregation.ui
Import-Package: org.osgi.service.event
@@ -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.aggregation.ui"
implementation="flintstones.method.common.phase.aggregation.ui.AggregationUI"
phasemethod="flintstones.method.common.phase.aggregation">
</phasemethod_ui>
</extension>
</plugin>
@@ -0,0 +1,116 @@
package flintstones.method.common.phase.aggregation.ui;
import java.util.Map;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.widgets.Composite;
import flintstones.domain.fuzzyset.FuzzySet;
import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction;
import flintstones.domain.fuzzyset.ui.chart.LinguisticDomainChart;
import flintstones.entity.domain.Domain;
import flintstones.entity.problemelement.entities.Alternative;
import flintstones.entity.problemelement.entities.ProblemElement;
import flintstones.entity.valuation.Valuation;
import flintstones.model.ui.service.UiService;
import flintstones.valuation.elicit.ELICIT;
import flintstones.valuation.twoTuple.TwoTupleValuation;
import flintstones.valuation.unifiedValuation.UnifiedValuation;
public class AggregationChartUi {
private Composite _chartView;
private ControlAdapter _controlListener;
private LinguisticDomainChart _chart;
public AggregationChartUi(Composite base) {
addRankingChart(base);
}
private void addRankingChart(Composite thirdRow) {
_chartView = new Composite(thirdRow, 0);
UiService.setGridData(_chartView, 9, 9, true, true);
// UiService.debugWithColors(_chartView.getParent().getParent(),
// _chartView.getParent(), _chartView);
setChart(null, null);
}
public void setChart(Domain domain, Map<Alternative, Valuation> aggregationResult) {
removeOldChart();
if (!(domain instanceof FuzzySet))
return;
_chart = new LinguisticDomainChart();
_chart.initialize(domain, _chartView, _chartView.getSize().x, _chartView.getSize().y, SWT.BORDER);
if (_controlListener == null) {
_controlListener = new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
setChart(domain, aggregationResult);
}
};
_chartView.addControlListener(_controlListener);
}
if (aggregationResult != null) {
int size = aggregationResult.size();
if (size > 0) {
String[] alternatives = new String[size];
int[] pos = new int[size];
int i = 0;
double[] alpha = new double[size];
Valuation valuation = null, aux;
TrapezoidalFunction[] fuzzyNumbers = new TrapezoidalFunction[size];
for (ProblemElement alternative : aggregationResult.keySet()) {
alternatives[i] = alternative.getName();
aux = aggregationResult.get(alternative);
if (aux instanceof UnifiedValuation) {
valuation = ((UnifiedValuation) aux).disunification((FuzzySet) aux.getDomain());
} else {
valuation = aux;
}
if (valuation instanceof TwoTupleValuation) {
pos[i] = ((FuzzySet) domain).getLabelSet().getPos(((TwoTupleValuation) valuation).getLabel());
alpha[i] = ((TwoTupleValuation) valuation).getAlpha();
i++;
} else if (valuation instanceof ELICIT) {
fuzzyNumbers[i] = ((ELICIT) valuation).getBeta();
i++;
} else {
alternatives[i] = null;
}
}
if (fuzzyNumbers[0] != null) {
_chart.displayAlternatives(alternatives, fuzzyNumbers);
} else {
_chart.displayAlternatives(alternatives, pos, alpha);
}
}
}
}
private void removeOldChart() {
if (_chart != null) {
_chart.getChartComposite().dispose();
_chartView.layout();
}
}
}
@@ -0,0 +1,271 @@
package flintstones.method.common.phase.aggregation.ui;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.Map;
import java.util.stream.Collectors;
import javax.inject.Inject;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.e4.core.services.nls.Translation;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.TreeViewerColumn;
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.layout.GridData;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import flintstones.application.constants.FrameworkConstants;
import flintstones.entity.aggregation.AggregationItem;
import flintstones.entity.common.interfaces.IRefreshEntity;
import flintstones.entity.domain.Domain;
import flintstones.entity.problemelement.entities.Alternative;
import flintstones.entity.problemelement.entities.Criterion;
import flintstones.entity.problemelement.entities.Expert;
import flintstones.entity.valuation.Valuation;
import flintstones.method.common.phase.aggregation.AggregationModel;
import flintstones.method.common.phase.aggregation.AggregationResultModel;
import flintstones.method.common.phase.aggregation.ui.messages.Messages;
import flintstones.method.common.phase.collectweightsaggregation.ui.provider.EnabledColumnEditingSupport;
import flintstones.method.common.phase.collectweightsaggregation.ui.provider.EnabledColumnLabelProvider;
import flintstones.method.common.phase.collectweightsaggregation.ui.provider.MainColumnLabelProvider;
import flintstones.model.ui.service.UiService;
public class AggregationResultUI implements IRefreshEntity {
@Inject
IEventBroker broker;
@Inject
@Translation
Messages messages;
// UI
private TreeViewer viewer;
private AggregationChartUi chartUi;
private Combo retranslationCombo;
// Data
private AggregationResultModel model;
private LinkedList<AggregationItem> alternatives;
// State
private boolean aggregationDone = false;
public AggregationResultUI() {}
public AggregationResultUI(Composite base, AggregationResultModel model, AggregationModel baseModel) {
initializeUI(base, model, baseModel);
}
public void initializeUI(Composite base, AggregationResultModel model, AggregationModel baseModel) {
this.model = model;
model.setAggregationModel(baseModel);
addAlternativesTree(base);
chartUi = new AggregationChartUi(base);
addConfigRow(base);
}
private void addAlternativesTree(Composite parent) {
Composite base = new Composite(parent, 0);
GridData gdata = UiService.setGridData(base, 9, 9, true, true);
gdata.heightHint = parent.getBounds().height/3;
base.setLayoutData(gdata);
UiService.setGridLayout(base, 1);
viewer = new TreeViewer(base, SWT.FULL_SELECTION);
viewer.setContentProvider(new ITreeContentProvider() {
@Override
public boolean hasChildren(Object element) {
return false;
}
@Override
public Object getParent(Object element) {
return null;
}
@Override
public Object[] getElements(Object inputElement) {
return ArrayContentProvider.getInstance().getElements(inputElement);
}
@Override
public Object[] getChildren(Object parentElement) {
return new Object[0];
}
});
viewer.getTree().setHeaderVisible(true);
viewer.getTree().setLinesVisible(true);
UiService.setGridData(viewer.getTree(), 9, 9, true, true);
TreeViewerColumn viewerColumn = new TreeViewerColumn(viewer, SWT.NONE);
viewerColumn.getColumn().setText(messages.AggregationResultUI_Element);
viewerColumn.setLabelProvider(new MainColumnLabelProvider());
TreeViewerColumn viewerColumn2 = new TreeViewerColumn(viewer, SWT.NONE);
viewerColumn2.getColumn().setText(messages.AggregationResultUI_Ranking);
viewerColumn2.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
boolean enabled = ((AggregationItem) element).isEnabled();
if(enabled)
return model.getRankingAlternative(((AggregationItem) element).getAlternative()) + ""; //$NON-NLS-1$
return ""; //$NON-NLS-1$
}
});
TreeViewerColumn viewerColumn3 = new TreeViewerColumn(viewer, SWT.NONE);
viewerColumn3.getColumn().setText(messages.AggregationResultUI_Enabled);
viewerColumn3.setLabelProvider(new EnabledColumnLabelProvider());
viewerColumn3.setEditingSupport(new EnabledColumnEditingSupport(this, viewer));
TreeViewerColumn viewerColumn4 = new TreeViewerColumn(viewer, SWT.NONE);
viewerColumn4.getColumn().setText(messages.AggregationResultUI_Result_valuation);
viewerColumn4.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
AggregationItem item = (AggregationItem) element;
Alternative alt = item.getAlternative();
Valuation valuation = model.getRetranslationResult().get(alt);
if(valuation != null)
return valuation.changeFormatValuationToString();
return ""; //$NON-NLS-1$
}
});
GridLayoutFactory.fillDefaults().generateLayout(parent);
// SIZE
base.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
Composite composite = (Composite) e.widget;
int width = composite.getBounds().width;
double total = 1.0d;
double c1 = 0.3;
double c2 = 0.1;
double c3 = 0.2;
double c4 = total -c2 -c3 -c1;
viewerColumn.getColumn().setWidth((int) (width*c1));
viewerColumn2.getColumn().setWidth((int) (width*c2));
viewerColumn3.getColumn().setWidth((int) (width*c3));
viewerColumn4.getColumn().setWidth((int) (width*c4));
}
});
Alternative[] alternativesPe = model.getAlternatives();
alternatives = Arrays.stream(alternativesPe).map(k -> new AggregationItem(k)).collect(Collectors.toCollection(LinkedList::new));;
viewer.setInput(alternatives.toArray(new AggregationItem[0]));
}
private void addConfigRow(Composite firstRow) {
Composite base = new Composite(firstRow, SWT.NONE);
UiService.setGridLayout(base, 4, false);
UiService.setGridData(base, 9, 1, true, false);
addRetranslationCombo(base);
}
private void addRetranslationCombo(Composite thirdRow) {
retranslationCombo = new Combo(thirdRow, SWT.READ_ONLY);
retranslationCombo.setItems(model.getRetranslationDomainsIds());
retranslationCombo.add(model.getUnifiedDomain().getName(), 0);
retranslationCombo.select(0);
retranslationCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
refreshEntity(null);
}
});
}
private void refreshUi(Domain domain, Map<Alternative, Valuation> aggregationResult) {
Collections.sort(alternatives, new Comparator<AggregationItem>() {
@Override
public int compare(AggregationItem a, AggregationItem b) {
Valuation va = aggregationResult.get(a.getAlternative());
Valuation vb = aggregationResult.get(b.getAlternative());
if(!a.isEnabled() && !b.isEnabled())
return 0;
if(!a.isEnabled())
return -1;
if(!b.isEnabled())
return 1;
return va.compareTo(vb);
}
});
Collections.reverse(alternatives);
model.computeRankingAlternatives(aggregationResult);
viewer.setInput(alternatives.toArray(new AggregationItem[0]));
chartUi.setChart(domain, aggregationResult);
}
@Override
public void refreshEntity(Object firstExpertsToAggregate) {
if(firstExpertsToAggregate != null) {
if((boolean) firstExpertsToAggregate)
model.setFirstToAggregate(Criterion.Type);
else
model.setFirstToAggregate(Expert.Type);
}
firstExpertsToAggregate = model.getFirstToAggregate();
if(firstExpertsToAggregate == null) {
return ;
}
Alternative[] enabledAlternatives = alternatives.stream().filter(k -> k.isEnabled()).map(k2 -> k2.getAlternative()).toArray(Alternative[]::new);
model.aggregate(enabledAlternatives);
aggregationDone = true;
model.computeRetranslationResults(retranslationCombo.getText());
refreshUi(model.getRetranslationDomain(retranslationCombo.getText()), model.getRetranslationResult());
sendRefresh();
}
private void sendRefresh() {
broker.post(FrameworkConstants.TOPIC_METHOD_PHASE_REFRESH,null);
}
public boolean isAggregationDone() {
return aggregationDone;
}
}
@@ -0,0 +1,119 @@
package flintstones.method.common.phase.aggregation.ui;
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.jface.viewers.CheckStateChangedEvent;
import org.eclipse.jface.viewers.ICheckStateListener;
import org.eclipse.swt.widgets.Composite;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventHandler;
import flintstones.application.constants.FrameworkConstants;
import flintstones.entity.common.interfaces.IChangedEntity;
import flintstones.entity.method.phase.ui.PhaseMethodUI;
import flintstones.entity.problemelement.entities.Alternative;
import flintstones.entity.problemelement.entities.Criterion;
import flintstones.entity.problemelement.entities.Expert;
import flintstones.entity.problemelement.entities.ProblemElementHelper;
import flintstones.method.common.phase.aggregation.AggregationModel;
import flintstones.method.common.phase.aggregation.AggregationResultModel;
import flintstones.method.common.phase.collectweightsaggregation.CollectAggregationDataModel;
import flintstones.method.common.phase.collectweightsaggregation.ui.CollectAggregationDataUI;
import flintstones.model.problemelement.service.IProblemElementService;
import flintstones.model.ui.service.UiService;
public class AggregationUI extends PhaseMethodUI implements ICheckStateListener, EventHandler {
@Inject
IEclipseContext context;
@Inject
IProblemElementService problemService;
@Inject
private IEventBroker broker;
private AggregationModel model;
// UIs
AggregationResultUI resultUi;
CollectAggregationDataUI collectUi;
// Models
CollectAggregationDataModel collectModel;
AggregationResultModel resultModel;
@Override
public void init() {
model = (AggregationModel) this.getModel();
Composite parent = baseComposite;
UiService.setGridDataAuto(parent);
UiService.setGridLayout(parent, 2, true);
// LEFT -> COLLECT DATA
Composite left = new Composite(parent, 0);
UiService.setGridDataAuto(left);
UiService.setGridLayout(left, 1);
Expert[] es = ProblemElementHelper.asExperts(problemService.getMainElements(Expert.Type));
Criterion[] cs = ProblemElementHelper.asCriterions(problemService.getMainElements(Criterion.Type));
Alternative[] as = ProblemElementHelper.asAlternatives(problemService.getMainElements(Alternative.Type));
collectModel = ContextInjectionFactory.make(CollectAggregationDataModel.class, context);
collectModel.setPreviousPhase(model.getPreviousPhase());
collectUi = ContextInjectionFactory.make(CollectAggregationDataUI.class, context);
collectUi.build(collectModel, left, es, cs, as);
collectUi.setChangeListener(new CollectorChangeEvent());
// RIGHT -> DRAW RESULTS
Composite right = new Composite(parent, 0);
UiService.setGridDataAuto(right);
UiService.setGridLayout(right, 1);
resultModel = ContextInjectionFactory.make(AggregationResultModel.class, context);
resultModel.setPreviousPhase(collectModel);
resultUi = new AggregationResultUI();
ContextInjectionFactory.inject(resultUi, context);
resultUi.initializeUI(right, resultModel, model);
broker.subscribe(FrameworkConstants.TOPIC_METHOD_PHASE_REFRESH, this);
}
private final class CollectorChangeEvent implements IChangedEntity {
@Override
public void onEntityChange(Object data) {
if (collectUi.getFirstError() == null)
resultUi.refreshEntity(data);
}
}
@Override
public void refresh() {
// resultUi.refreshEntity(null);
}
@Override
public boolean isForwardEnabled() {
return resultUi.isAggregationDone() && !collectUi.isExpertFirst();
}
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
refresh();
}
@Override
public void handleEvent(Event event) {
// if (resultUi != null)
// resultUi.refreshEntity(null);
}
}
@@ -0,0 +1,10 @@
package flintstones.method.common.phase.aggregation.ui.messages;
public class Messages {
public String AggregationResultUI_Element;
public String AggregationResultUI_Enabled;
public String AggregationResultUI_Ranking;
public String AggregationResultUI_Result_valuation;
}
@@ -0,0 +1,4 @@
AggregationResultUI_Element=Element
AggregationResultUI_Enabled=Enabled
AggregationResultUI_Ranking=Ranking
AggregationResultUI_Result_valuation=Result valuation
@@ -0,0 +1,4 @@
AggregationResultUI_Element=Elemento
AggregationResultUI_Enabled=Habilitado
AggregationResultUI_Ranking=Ranking
AggregationResultUI_Result_valuation=Resultado
@@ -0,0 +1,46 @@
package flintstones.method.common.phase.aggregation.ui.provider;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import flintstones.entity.valuation.Valuation;
import flintstones.valuation.twoTuple.TwoTupleValuation;
public class EvaluationColumnLabelProviderRepetido extends ColumnLabelProvider {
@Override
public String getText(Object element) {
if (((Object[]) element)[2] != null) {
if (((Object[]) element)[2] instanceof TwoTupleValuation) {
TwoTupleValuation valuation = (TwoTupleValuation) ((Object[]) element)[2];
String labelName = valuation.getLabel().getName();
String alpha = Double.toString(valuation.getAlpha());
if (alpha.equals("-0.0")) { //$NON-NLS-1$
alpha = "0"; //$NON-NLS-1$
}
if (alpha.equals("0.0")) { //$NON-NLS-1$
alpha = "0"; //$NON-NLS-1$
}
int size = 4;
if (alpha.startsWith("-")) { //$NON-NLS-1$
size = 5;
}
if (alpha.length() > size) {
alpha = alpha.substring(0, size);
}
if (alpha.length() > 1) {
if (alpha.endsWith("0")) { //$NON-NLS-1$
alpha = alpha.substring(0, size - 1);
}
}
return "(" + labelName + ", " + alpha + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
} else if(((Object[]) element)[2] instanceof Valuation) {
return ((Valuation) ((Object[]) element)[2]).changeFormatValuationToString();
} else {
return "";
}
} else {
return "Messages.EvaluationColumnLabelProvider_Not_evaluate";
}
}
}
@@ -0,0 +1,11 @@
package flintstones.method.common.phase.aggregation.ui.provider;
import org.eclipse.jface.viewers.ColumnLabelProvider;
public class RankingColumnLabelProvider extends ColumnLabelProvider {
@Override
public String getText(Object element) {
return ((Integer) ((Object[]) element)[0]).toString();
}
}
@@ -0,0 +1,105 @@
package flintstones.method.common.phase.aggregation.ui.provider;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.Viewer;
import flintstones.domain.fuzzyset.FuzzySet;
import flintstones.entity.problemelement.entities.ProblemElement;
import flintstones.entity.valuation.Valuation;
import flintstones.valuation.elicit.ELICIT;
import flintstones.valuation.hesitant.HesitantValuation;
import flintstones.valuation.twoTuple.TwoTupleValuation;
import flintstones.valuation.unifiedValuation.UnifiedValuation;
public class RankingViewerProvider implements IStructuredContentProvider {
private Map<ProblemElement, Valuation> _results;
private class MyComparator implements Comparator<Object[]> {
@Override
public int compare(Object[] o1, Object[] o2) {
if ((o1[0] instanceof HesitantValuation)) {
return ((HesitantValuation) o1[0]).compareTo((HesitantValuation) o2[0]);
} else if(o1[0] instanceof ELICIT) {
return ((ELICIT) o1[0]).compareTo((ELICIT) o2[0]);
} else {
return Double.compare((Double) o1[0], (Double) o2[0]);
}
}
}
@Override
public void dispose() {}
@SuppressWarnings("unchecked")
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
_results = (Map<ProblemElement, Valuation>) newInput;
}
@Override
public Object[] getElements(Object inputElement) {
int size = _results.size();
if(size != 0) {
Object[][] input = new Object[size][2];
int pos = 0;
for(ProblemElement alternative : _results.keySet()) {
input[pos][0] = alternative.getName();
input[pos][1] = _results.get(alternative);
pos++;
}
List<Object[]> result = new LinkedList<Object[]>();
if(input[0][1] != null) {
String alternativeName;
Valuation valuation;
TwoTupleValuation twoTuple = null;
Object[] listEntry = null;
for (int i = 0; i < size; i++) {
alternativeName = (String) input[i][0];
valuation = (Valuation) input[i][1];
if (valuation != null) {
if (valuation instanceof UnifiedValuation) {
twoTuple = ((UnifiedValuation) valuation).disunification((FuzzySet) valuation.getDomain());
} else if(valuation instanceof TwoTupleValuation) {
twoTuple = (TwoTupleValuation) valuation;
listEntry = new Object[] {twoTuple.calculateInverseDelta(), alternativeName, twoTuple };
} else {
listEntry = new Object[] {valuation, alternativeName, valuation };
}
} else {
listEntry = new Object[] { 0d, alternativeName, null };
}
result.add(listEntry);
}
Collections.sort(result, new MyComparator());
Collections.reverse(result);
int ranking = 0;
double previous = -1;
for (Object[] element : result) {
if ((element[0] instanceof HesitantValuation || element[0] instanceof ELICIT)) {
element[0] = Integer.valueOf(++ranking);
} else if ((Double) element[0] == previous) {
element[0] = ranking;
} else {
ranking++;
previous = (Double) element[0];
element[0] = ranking;
}
}
}
return result.toArray(new Object[0][0]);
} else {
return new Object[0];
}
}
}
@@ -0,0 +1,23 @@
package flintstones.method.common.phase.aggregation.ui.provider;
import java.util.List;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.Viewer;
import flintstones.entity.domain.Domain;
public class RetranslationViewerProvider implements 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();
}
}