public code v1
This commit is contained in:
@@ -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-11"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
+14
@@ -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.fuzzy.common.phase.collectweights.criterion.ui</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<packaging>eclipse-plugin</packaging>
|
||||
<name>[bundle] Bundle-Name</name>
|
||||
</project>
|
||||
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>flintstones.method.fuzzy.common.phase.collectweights.criterion.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>1779484362674</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>
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
|
||||
org.eclipse.jdt.core.compiler.compliance=11
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||
org.eclipse.jdt.core.compiler.release=enabled
|
||||
org.eclipse.jdt.core.compiler.source=11
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: %Bundle-Name
|
||||
Bundle-SymbolicName: flintstones.method.fuzzy.common.phase.collectweights.criterion.ui;singleton:=true
|
||||
Bundle-Version: 1.0.0.qualifier
|
||||
Automatic-Module-Name: flintstones.method.fuzzy.common.phase.collectweights.criterion.ui
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-11
|
||||
Require-Bundle: org.eclipse.e4.core.services,
|
||||
flintstones.entity.method.phase.ui,
|
||||
javax.inject,
|
||||
flintstones.helper.ui,
|
||||
flintstones.entity.problemelement.ui,
|
||||
flintstones.model.valuation.service,
|
||||
flintstones.method.fuzzy.common.phase.collectweights.criterion,
|
||||
flintstones.entity.problemelement,
|
||||
flintstones.model.ui.service,
|
||||
flintstones.entity.method.phase,
|
||||
flintstones.domain.fuzzyset,
|
||||
flintstones.helper.data,
|
||||
flintstones.valuation.linguistic,
|
||||
flintstones.model.domain.service
|
||||
+5
@@ -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
|
||||
implementation="flintstones.method.fuzzy.common.phase.collectweights.criterion.ui.FuzzyCollectWeightsCriterionUI"
|
||||
phasemethod="flintstones.method.fuzzy.common.phase.collectweights.criterion"
|
||||
uid="flintstones.method.fuzzy.common.phase.collectweights.criterion.ui">
|
||||
</phasemethod_ui>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
+300
@@ -0,0 +1,300 @@
|
||||
package flintstones.method.fuzzy.common.phase.collectweights.criterion.ui;
|
||||
|
||||
import org.eclipse.e4.core.services.nls.Translation;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Combo;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
|
||||
import flintstones.domain.fuzzyset.FuzzySet;
|
||||
import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction;
|
||||
import flintstones.domain.fuzzyset.label.LabelLinguisticDomain;
|
||||
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.entity.problemelement.ui.widget.ProblemElementSelector;
|
||||
import flintstones.entity.problemelement.ui.widget.listener.IProblemElementChangedListener;
|
||||
import flintstones.helper.DoubleHelper;
|
||||
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.fuzzy.common.phase.collectweights.criterion.FuzzyCollectWeightsCriterion;
|
||||
import flintstones.method.fuzzy.common.phase.collectweights.criterion.ui.messages.Messages;
|
||||
import flintstones.model.ui.service.UiService;
|
||||
import flintstones.model.valuation.service.IValuationService;
|
||||
import flintstones.valuation.linguistic.LinguisticValuation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class FuzzyCollectWeightsCriterionUI extends PhaseMethodUI
|
||||
implements WItemBeforeOperation, WItemChanged, IProblemElementChangedListener {
|
||||
|
||||
@Inject
|
||||
IValuationService valuationService;
|
||||
|
||||
/**
|
||||
* Phase model implementation
|
||||
*/
|
||||
FuzzyCollectWeightsCriterion model;
|
||||
|
||||
/**
|
||||
* Expert selector
|
||||
*/
|
||||
ProblemElementSelector selectorExpert;
|
||||
|
||||
/**
|
||||
* Criterion selector
|
||||
*/
|
||||
ProblemElementSelector selectorCriterion;
|
||||
|
||||
/**
|
||||
* Data collector
|
||||
*/
|
||||
WCollector collector;
|
||||
|
||||
@Inject
|
||||
@Translation
|
||||
Messages msg;
|
||||
|
||||
/**
|
||||
* Init interface
|
||||
*/
|
||||
@Override
|
||||
public void init() {
|
||||
model = (FuzzyCollectWeightsCriterion) this.getModel();
|
||||
|
||||
// Experts and criteria
|
||||
ProblemElement[] items = model.getExperts();
|
||||
ProblemElement[] subitems = model.getCriteria();
|
||||
|
||||
Composite base = this.getBaseComposite();
|
||||
UiService.setGridDataAuto(base);
|
||||
UiService.setGridLayout(base, 1);
|
||||
|
||||
Composite topRow = new Composite(base, SWT.BORDER);
|
||||
UiService.setGridData(topRow, 0, 0, true, false);
|
||||
UiService.setGridLayout(topRow, 1, false);
|
||||
|
||||
// <-- Expert & criteria selection -->
|
||||
Composite rowSelectors = new Composite(topRow, SWT.NONE);
|
||||
UiService.setGridData(rowSelectors, 0, 9, true, true);
|
||||
UiService.setGridLayout(rowSelectors, 4, false);
|
||||
|
||||
// Expert selector
|
||||
selectorExpert = new ProblemElementSelector(rowSelectors, items);
|
||||
selectorExpert.setText(Expert.Type);
|
||||
selectorExpert.setListener(this);
|
||||
|
||||
// Criterion selector
|
||||
selectorCriterion = new ProblemElementSelector(rowSelectors, subitems);
|
||||
selectorCriterion.setText(Criterion.Type);
|
||||
selectorCriterion.setListener(this);
|
||||
|
||||
// <-- Fuzzy tag selector -->
|
||||
Composite rowFuzzyTag = new Composite(topRow, SWT.BORDER);
|
||||
UiService.setGridLayout(rowFuzzyTag, 3, true);
|
||||
UiService.setGridData(rowFuzzyTag, 9, 0, true, true);
|
||||
|
||||
Label label = new Label(rowFuzzyTag, SWT.NONE);
|
||||
label.setText(msg.selectTag);
|
||||
Combo tagSelector = new Combo(rowFuzzyTag, SWT.NONE);
|
||||
List<LabelLinguisticDomain> tags = ((FuzzySet) ((LinguisticValuation) valuationService.getAll()[0]).getDomain())
|
||||
.getLabelSet().getLabels();
|
||||
for (LabelLinguisticDomain lb : tags) {
|
||||
tagSelector.add(lb.getName());
|
||||
}
|
||||
tagSelector.select(0);
|
||||
|
||||
// Add button
|
||||
Button tagAdd = new Button(rowFuzzyTag, SWT.NONE);
|
||||
tagAdd.setText(msg.buttonTag);
|
||||
tagAdd.addSelectionListener(new SelectionAdapter() {
|
||||
/**
|
||||
* Assigns the selected label value to next weight
|
||||
*/
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
String[] newData = new String[3];
|
||||
TrapezoidalFunction selected = (TrapezoidalFunction) tags.get(tagSelector.getSelectionIndex())
|
||||
.getSemantic();
|
||||
newData[0] = Double.toString(selected.getA());
|
||||
newData[1] = Double.toString(selected.getB());
|
||||
newData[2] = Double.toString(selected.getD());
|
||||
collector.setValues(new ArrayList<String>(Arrays.asList(newData)));
|
||||
selectorCriterion.setStatus(selectorCriterion.getSelectedElement(), true);
|
||||
saveWeights(newData);
|
||||
updateSelectors();
|
||||
}
|
||||
});
|
||||
|
||||
// <-- Weights collector -->
|
||||
Composite rowCollector = new Composite(base, SWT.NONE);
|
||||
UiService.setGridLayout(rowCollector, 1, true);
|
||||
UiService.setGridDataAuto(rowCollector);
|
||||
|
||||
// Data collector
|
||||
String[] fuzzy = new String[] { "l", "m", "r" };
|
||||
collector = new WCollector(rowCollector);
|
||||
collector.setHeaders(fuzzy);
|
||||
collector.setBeforeOperationListener(this);// shouldBeExecuted
|
||||
collector.setChangeListener(this);// onWidgetChange
|
||||
collector.setOperationListener(new WItemOperation() {
|
||||
/**
|
||||
* Allows input of integer numbers as decimals.
|
||||
*/
|
||||
@Override
|
||||
public String getModifiedValue(WEvent operationType, String before, String after) {
|
||||
return Double.toString(DoubleHelper.NormalizeZeroToOne(before));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refresh() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if next phase is available, otherwise false
|
||||
*/
|
||||
@Override
|
||||
protected boolean isForwardEnabled() {
|
||||
return model.isFilled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Listener to check the new weight
|
||||
*
|
||||
* @return true to add, otherwise false
|
||||
*/
|
||||
@Override
|
||||
public boolean shouldBeExecuted(WEvent operationType, String before, String after) {
|
||||
|
||||
if (operationType.equals(WEvent.ADD)) {
|
||||
String[] data = collector.getData();
|
||||
if (data.length < 3) {// at most three values
|
||||
if (data.length >= 1) {// check order when more than 1 value
|
||||
for (String d : data) {
|
||||
if(DoubleHelper.NormalizeZeroToOne(d) > DoubleHelper.NormalizeZeroToOne(before)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
|
||||
} else if (operationType.equals(WEvent.CLEAR)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Listener to add a new weight
|
||||
*/
|
||||
@Override
|
||||
public void onWidgetChange() {
|
||||
updateStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates expert & criteria completion status
|
||||
*/
|
||||
private void updateStatus() {
|
||||
String[] data = collector.getData();
|
||||
Float sum = 0.0f;
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
sum += Float.valueOf(data[i]);
|
||||
}
|
||||
// <--- WEIGHT SUM T --->
|
||||
// ArrayList<String> newData = new ArrayList<>(Arrays.asList(data));
|
||||
// // If sum exceeds 1, don't add the new weight
|
||||
// if (sum > 1.0f) {
|
||||
// newData.remove(newData.size() - 1);
|
||||
// collector.setValues(newData);
|
||||
// data = collector.getData();
|
||||
// } else if (data.length == 2) { // Else, if only 1 remains, adds it directly
|
||||
// newData.add(Float.toString(1.0f - sum));
|
||||
// collector.setValues(newData);
|
||||
// data = collector.getData();
|
||||
// }
|
||||
|
||||
if (data.length == 3) {
|
||||
saveWeights(data);
|
||||
|
||||
selectorCriterion.setStatus(selectorCriterion.getSelectedElement(), true);
|
||||
} else {
|
||||
selectorCriterion.setStatus(selectorCriterion.getSelectedElement(), false);
|
||||
}
|
||||
updateSelectors();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates expert & criteria selectors status
|
||||
*/
|
||||
private void updateSelectors() {
|
||||
ProblemElement[] c = model.getCriteria();
|
||||
selectorExpert.setStatus(selectorExpert.getSelectedElement(), true);
|
||||
for (ProblemElement cr : c) {
|
||||
if (model.getWeight(selectorExpert.getSelectedElement(), cr) == null) {
|
||||
selectorExpert.setStatus(selectorExpert.getSelectedElement(), false);
|
||||
selectorCriterion.setStatus(cr, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves weigths for the next phase
|
||||
*
|
||||
* @param data Weigths to save
|
||||
*/
|
||||
private void saveWeights(String[] data) {
|
||||
double[] fuzzyNumber = new double[data.length];
|
||||
for (int i = 0; i < data.length; i++)
|
||||
fuzzyNumber[i] = DoubleHelper.ParseDouble(data[i]);
|
||||
|
||||
model.addWeight(selectorExpert.getSelectedElement(), selectorCriterion.getSelectedElement(),
|
||||
new TrapezoidalFunction(fuzzyNumber));
|
||||
|
||||
sendRefresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when changing selected expert or criterion
|
||||
*/
|
||||
@Override
|
||||
public void problemElementChanged(ProblemElement pe) {
|
||||
ArrayList<String> dt = new ArrayList<>();
|
||||
|
||||
ProblemElement criterion = selectorCriterion.getSelectedElement();
|
||||
ProblemElement expert = selectorExpert.getSelectedElement();
|
||||
|
||||
TrapezoidalFunction weight = model.getWeight(expert, criterion);
|
||||
// If there is weight, add to the list
|
||||
if (weight != null) {
|
||||
for (Double v : weight.getLimits())
|
||||
dt.add(v + "");
|
||||
|
||||
dt.remove(1);// Remove the second value since it is the same of the third value
|
||||
}
|
||||
|
||||
collector.setValues(dt);
|
||||
if (pe.getType() == Expert.Type) {
|
||||
updateStatus();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package flintstones.method.fuzzy.common.phase.collectweights.criterion.ui.messages;
|
||||
|
||||
import org.eclipse.e4.core.services.nls.Message;
|
||||
|
||||
@Message
|
||||
public class Messages {
|
||||
public String selectTag;
|
||||
public String buttonTag;
|
||||
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
selectTag=Select valuation for next weight
|
||||
buttonTag=Add
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
selectTag=Seleccionar valoración para el siguiente peso
|
||||
buttonTag=Añadir
|
||||
Reference in New Issue
Block a user