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-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.valuation.ahp.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.valuation.ahp.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>1779484362744</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,20 @@
|
||||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: Ui
|
||||
Bundle-SymbolicName: flintstones.valuation.ahp.ui
|
||||
Bundle-Version: 1.0.0.qualifier
|
||||
Automatic-Module-Name: flintstones.valuation.ahp.ui
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-11
|
||||
Require-Bundle: org.eclipse.swt,
|
||||
flintstones.helper.ui,
|
||||
javax.inject,
|
||||
flintstones.entity.problemelement,
|
||||
org.apache.commons.lang,
|
||||
flintstones.entity.ahp,
|
||||
flintstones.entity.ahppreferences,
|
||||
flintstones.model.ui.service,
|
||||
flintstones.model.problemelement.service,
|
||||
flintstones.helper.data,
|
||||
flintstones.valuation.ahp,
|
||||
flintstones.helper.ahp
|
||||
Export-Package: flintstones.valuation.ahp.ui
|
||||
@@ -0,0 +1,4 @@
|
||||
source.. = src/
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.
|
||||
+374
@@ -0,0 +1,374 @@
|
||||
package flintstones.valuation.ahp.ui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.Listener;
|
||||
|
||||
//import flintstones.entity.ahp.AHPMatrix;
|
||||
import flintstones.entity.problemelement.entities.ProblemElement;
|
||||
import flintstones.entity.problemelement.entities.ProblemElementHelper;
|
||||
import flintstones.helper.StringHelper;
|
||||
import flintstones.helper.ahp.AHPHelper;
|
||||
import flintstones.model.problemelement.service.IProblemElementService;
|
||||
import flintstones.model.ui.service.UiService;
|
||||
|
||||
/**
|
||||
* The Class AHPValuationPanel.
|
||||
*/
|
||||
public class AHPValuationPanel {
|
||||
|
||||
@Inject
|
||||
IProblemElementService problemService;
|
||||
|
||||
/** The buttons. */
|
||||
HashMap<ProblemElement, HashMap<ProblemElement, ArrayList<Button>>> buttons = new HashMap<>();
|
||||
|
||||
/** The button click listener. */
|
||||
IAHPValuationPanelClickListener buttonClickListener;
|
||||
|
||||
/** The parent. */
|
||||
Composite parent;
|
||||
|
||||
/** The show all. */
|
||||
boolean showAll = true;
|
||||
|
||||
/** The left items indexes. */
|
||||
HashMap<ProblemElement, Integer> leftItemsIndexes = new HashMap<>();
|
||||
|
||||
/** The right items indexes. */
|
||||
HashMap<ProblemElement, Integer> rightItemsIndexes = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Instantiates a new AHP valuation panel.
|
||||
*
|
||||
* @param base the base
|
||||
*/
|
||||
public AHPValuationPanel(Composite base) {
|
||||
parent = base;
|
||||
}
|
||||
|
||||
public void show(boolean all) {
|
||||
showAll = all;
|
||||
}
|
||||
|
||||
/**
|
||||
* Base 1.
|
||||
*
|
||||
* @param domain the domain
|
||||
* @param leftArr the left arr
|
||||
* @param rightArr the right arr
|
||||
* @param mat the mat
|
||||
*/
|
||||
public void base1(ProblemElement[] leftArr, ProblemElement[] rightArr, int[][] mat) {
|
||||
|
||||
clear();
|
||||
|
||||
// IMPORTANTE: PRIMERO SE CACHEAN LOS ARRAYS CON LA MATRIX
|
||||
// Y DESPUES SE ORDENAN LOS ELEMENTOS EN LA UI.
|
||||
// NO PONER ESTAS 4 LINEAS TRAS LA ORDENACION!!!!
|
||||
|
||||
// Cache the positions of items in the matrix
|
||||
for (int i = 0; i < leftArr.length; i++)
|
||||
leftItemsIndexes.put(leftArr[i], i);
|
||||
|
||||
for (int i = 0; i < rightArr.length; i++)
|
||||
rightItemsIndexes.put(rightArr[i], i);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
leftArr = ProblemElementHelper.getAsUserOrdered(leftArr);
|
||||
rightArr = ProblemElementHelper.getAsUserOrdered(rightArr);
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
if (mat != null) {
|
||||
drawMatrixRowsBase2(leftArr, rightArr);
|
||||
fillMatrixBase3(leftArr, rightArr, mat);
|
||||
parent.layout();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw matrix rows base 2.
|
||||
*
|
||||
* @param leftArr the left arr
|
||||
* @param rightArr the right arr
|
||||
* @param mat the mat
|
||||
*/
|
||||
private void drawMatrixRowsBase2(ProblemElement[] leftArr, ProblemElement[] rightArr) {
|
||||
|
||||
// Cache sizes
|
||||
int largestLeft = Stream.of(leftArr).map(k -> StringHelper.Draw(k.getShortName()))
|
||||
.max(Comparator.comparingInt(String::length)).get().length();
|
||||
int largestRight = Stream.of(rightArr).map(k -> StringHelper.Draw(k.getShortName()))
|
||||
.max(Comparator.comparingInt(String::length)).get().length();
|
||||
|
||||
if (showAll) {
|
||||
for (ProblemElement left : leftArr)
|
||||
for (ProblemElement right : rightArr)
|
||||
if (!left.equals(right))
|
||||
drawRow(parent, left, right, largestLeft, largestRight);
|
||||
|
||||
} else {
|
||||
for (int i = 0; i < leftArr.length; i++) {
|
||||
ProblemElement pe1 = leftArr[i];
|
||||
for (int j = i; j < rightArr.length; j++) {
|
||||
ProblemElement pe2 = rightArr[j];
|
||||
if (!pe1.equals(pe2))
|
||||
drawRow(parent, pe1, pe2, largestLeft, largestRight);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill matrix base 3.
|
||||
*
|
||||
* @param leftArr the left arr
|
||||
* @param rightArr the right arr
|
||||
* @param mat the mat
|
||||
*/
|
||||
private void fillMatrixBase3(ProblemElement[] leftArr, ProblemElement[] rightArr, int[][] mat) {
|
||||
for (ProblemElement left : leftArr) {
|
||||
for (ProblemElement right : rightArr) {
|
||||
if (!left.equals(right)) {
|
||||
int leftIndex = leftItemsIndexes.get(left);
|
||||
int rightIndex = rightItemsIndexes.get(right);
|
||||
int index = mat[leftIndex][rightIndex];
|
||||
|
||||
if (buttonClickListener != null)
|
||||
buttonClickListener.onClick(left, right, index);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw matrix.
|
||||
*
|
||||
* @param domain the domain
|
||||
* @param arr the arr
|
||||
* @param mat the mat
|
||||
*/
|
||||
public void drawMatrix(ProblemElement[] arr, int[][] mat) {
|
||||
this.base1(arr, arr, mat);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw matrix.
|
||||
*
|
||||
* @param domain the domain
|
||||
* @param arr the arr
|
||||
*/
|
||||
public void drawMatrix(ProblemElement[] arr) {
|
||||
this.base1(arr, arr, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw row.
|
||||
*
|
||||
* @param base the base
|
||||
* @param main the main
|
||||
* @param other the other
|
||||
*/
|
||||
private void drawRow(Composite base, ProblemElement main, ProblemElement other, int largestElementNameLeft,
|
||||
int largestElementNameRight) {
|
||||
|
||||
HashMap<ProblemElement, ArrayList<Button>> map1 = buttons.get(main);
|
||||
if (map1 == null)
|
||||
map1 = new HashMap<>();
|
||||
|
||||
ArrayList<Button> buttonList = map1.get(other);
|
||||
if (buttonList == null)
|
||||
buttonList = new ArrayList<>();
|
||||
|
||||
Composite mainC = new Composite(base, SWT.NONE);
|
||||
|
||||
Label leftLabel = new Label(mainC, 0);
|
||||
UiService.setFont(leftLabel, UiService.FONT_CODE);
|
||||
|
||||
String leftName = StringHelper.Draw(main.getShortName());
|
||||
String leftAlternative = StringUtils.leftPad(leftName, largestElementNameLeft, " ");
|
||||
leftLabel.setText(leftAlternative);
|
||||
|
||||
GridLayout mainGrid = new GridLayout(3, false);
|
||||
mainGrid.horizontalSpacing = 0;
|
||||
mainGrid.verticalSpacing = 0;
|
||||
mainGrid.marginHeight = 0;
|
||||
mainC.setLayout(mainGrid);
|
||||
|
||||
UiService.setGridData(mainC, 9, -1, true, false);
|
||||
|
||||
Composite interior = new Composite(mainC, 0);
|
||||
GridLayout grid = new GridLayout(17, true);
|
||||
grid.horizontalSpacing = 0;
|
||||
grid.marginHeight = 0;
|
||||
interior.setLayout(grid);
|
||||
UiService.setGridData(interior, 9, 0, true, false);
|
||||
|
||||
for (int i = 0; i < AHPHelper.getLabels().length; i++) {
|
||||
Button b = new Button(interior, SWT.TOGGLE);
|
||||
UiService.setGridData(b, 9, 9, true, true);
|
||||
b.setText(AHPHelper.getLabels()[i]);
|
||||
|
||||
final int fi = i;
|
||||
|
||||
b.addListener(SWT.MouseEnter, highlight(main, other, fi));
|
||||
b.addListener(SWT.MouseExit, unhighlight(main, other));
|
||||
if (buttonClickListener != null)
|
||||
b.addListener(SWT.Selection, click(main, other, fi));
|
||||
|
||||
buttonList.add(b);
|
||||
}
|
||||
|
||||
map1.put(other, buttonList);
|
||||
buttons.put(main, map1);
|
||||
|
||||
Label rightLabel = new Label(mainC, 0);
|
||||
UiService.setFont(rightLabel, UiService.FONT_CODE);
|
||||
|
||||
String rightName = StringHelper.Draw(other.getShortName());
|
||||
String rightAlternative = StringUtils.rightPad(rightName, largestElementNameRight, " ");
|
||||
rightLabel.setText(rightAlternative);
|
||||
|
||||
// Select the middle one
|
||||
int midpoint = (int) AHPHelper.getMidPoint();
|
||||
if (buttonClickListener != null)
|
||||
buttonClickListener.onClick(main, other, midpoint);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Click.
|
||||
*
|
||||
* @param main the main
|
||||
* @param other the other
|
||||
* @param fi the fi
|
||||
* @return the listener
|
||||
*/
|
||||
private Listener click(ProblemElement main, ProblemElement other, final int fi) {
|
||||
return new Listener() {
|
||||
|
||||
@Override
|
||||
public void handleEvent(Event event) {
|
||||
|
||||
if (buttonClickListener != null)
|
||||
buttonClickListener.onClick(main, other, fi);
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Unhighlight.
|
||||
*
|
||||
* @param main the main
|
||||
* @param other the other
|
||||
* @return the listener
|
||||
*/
|
||||
private Listener unhighlight(ProblemElement main, ProblemElement other) {
|
||||
return new Listener() {
|
||||
|
||||
@Override
|
||||
public void handleEvent(Event event) {
|
||||
HashMap<ProblemElement, ArrayList<Button>> map1 = buttons.get(main);
|
||||
ArrayList<Button> buttonList = map1.get(other);
|
||||
|
||||
buttonList.forEach(k -> UiService.setBackgroundColor(k, UiService.COLOR_BG_BUTTON_NORMAL));
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Highlight.
|
||||
*
|
||||
* @param main the main
|
||||
* @param other the other
|
||||
* @param position the position
|
||||
* @return the listener
|
||||
*/
|
||||
private Listener highlight(ProblemElement main, ProblemElement other, int position) {
|
||||
return new Listener() {
|
||||
|
||||
@Override
|
||||
public void handleEvent(Event event) {
|
||||
HashMap<ProblemElement, ArrayList<Button>> map1 = buttons.get(main);
|
||||
ArrayList<Button> buttonList = map1.get(other);
|
||||
|
||||
buttonList.forEach(k -> UiService.setBackgroundColor(k, UiService.COLOR_BG_BUTTON_HIGHLIGHT2));
|
||||
UiService.setBackgroundColor(buttonList.get(position), UiService.COLOR_BG_BUTTON_HIGHLIGHT);
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Select.
|
||||
*
|
||||
* @param a the a
|
||||
* @param b the b
|
||||
* @param pos the pos
|
||||
*/
|
||||
public void select(ProblemElement a, ProblemElement b, int pos) {
|
||||
|
||||
// Select a,b
|
||||
HashMap<ProblemElement, ArrayList<Button>> map1A = buttons.get(a);
|
||||
if (map1A != null) {
|
||||
|
||||
ArrayList<Button> buttonListA = map1A.get(b);
|
||||
if (buttonListA != null) {
|
||||
buttonListA.forEach(k -> k.setSelection(false));
|
||||
|
||||
Button buttonA = buttonListA.get(pos);
|
||||
buttonA.setSelection(true);
|
||||
}
|
||||
}
|
||||
|
||||
// Select b,a
|
||||
HashMap<ProblemElement, ArrayList<Button>> map1B = buttons.get(b);
|
||||
if (map1B != null) {
|
||||
ArrayList<Button> buttonListB = map1B.get(a);
|
||||
if (buttonListB != null) {
|
||||
buttonListB.forEach(k -> k.setSelection(false));
|
||||
|
||||
pos = AHPHelper.getInverseIndex(pos);
|
||||
Button buttonB = buttonListB.get(pos);
|
||||
buttonB.setSelection(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the button on click listener.
|
||||
*
|
||||
* @param l the new button on click listener
|
||||
*/
|
||||
public void setButtonOnClickListener(IAHPValuationPanelClickListener l) {
|
||||
this.buttonClickListener = l;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear.
|
||||
*/
|
||||
public void clear() {
|
||||
this.buttons = new HashMap<>();
|
||||
Stream.of(this.parent.getChildren()).forEach(k -> k.dispose());
|
||||
}
|
||||
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package flintstones.valuation.ahp.ui;
|
||||
|
||||
import flintstones.entity.problemelement.entities.ProblemElement;
|
||||
|
||||
public interface IAHPValuationPanelClickListener {
|
||||
|
||||
public void onClick(ProblemElement a, ProblemElement b, int position);
|
||||
}
|
||||
Reference in New Issue
Block a user